1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

EditorNode: add Save/Discard/Cancel dialog

This commit is contained in:
Poommetee Ketson
2017-06-21 11:15:39 +07:00
parent a2e4b80ff5
commit 14fa4190b3
2 changed files with 55 additions and 26 deletions

View File

@@ -1117,14 +1117,24 @@ void EditorNode::_dialog_action(String p_file) {
get_undo_redo()->clear_history(); get_undo_redo()->clear_history();
} break; } break;
case FILE_CLOSE:
case SCENE_TAB_CLOSE:
case FILE_SAVE_SCENE: case FILE_SAVE_SCENE:
case FILE_SAVE_AS_SCENE: { case FILE_SAVE_AS_SCENE: {
int scene_idx = (current_option == FILE_CLOSE || current_option == SCENE_TAB_CLOSE) ? tab_closing : -1;
if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) { if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) {
//_save_scene(p_file); //_save_scene(p_file);
_save_default_environment(); _save_default_environment();
if (scene_idx != editor_data.get_edited_scene() || _get_current_main_editor() == EDITOR_SCRIPT)
_save_scene(p_file, scene_idx);
else
_save_scene_with_preview(p_file); _save_scene_with_preview(p_file);
if (scene_idx != -1)
_discard_changes();
} }
} break; } break;
@@ -1889,39 +1899,36 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
case FILE_CLOSE: { case FILE_CLOSE: {
if (!p_confirmed && unsaved_cache) { if (!p_confirmed && unsaved_cache) {
confirmation->get_ok()->set_text(TTR("Yes")); tab_closing = editor_data.get_edited_scene();
//confirmation->get_cancel()->show(); save_confirmation->popup_centered_minsize();
confirmation->set_text(TTR("Close scene? (Unsaved changes will be lost)"));
confirmation->popup_centered_minsize();
break; break;
} }
} // fallthrough
_remove_edited_scene(); case SCENE_TAB_CLOSE:
} break;
case SCENE_TAB_CLOSE: {
_remove_scene(tab_closing);
_update_scene_tabs();
current_option = -1;
} break;
case FILE_SAVE_SCENE: { case FILE_SAVE_SCENE: {
Node *scene = editor_data.get_edited_scene_root(); int scene_idx = (p_option == FILE_CLOSE || p_option == SCENE_TAB_CLOSE) ? tab_closing : -1;
Node *scene = editor_data.get_edited_scene_root(scene_idx);
if (scene && scene->get_filename() != "") { if (scene && scene->get_filename() != "") {
// save in background if in the script editor // save in background if in the script editor
if (_get_current_main_editor() == EDITOR_SCRIPT) { if (scene_idx != editor_data.get_edited_scene() || _get_current_main_editor() == EDITOR_SCRIPT) {
_save_scene(scene->get_filename()); _save_scene(scene->get_filename(), scene_idx);
} else { } else {
_save_scene_with_preview(scene->get_filename()); _save_scene_with_preview(scene->get_filename());
} }
if (scene_idx != -1)
_discard_changes();
return; return;
}; };
// fallthrough to save_as // fallthrough to save_as
}; };
case FILE_SAVE_AS_SCENE: { case FILE_SAVE_AS_SCENE: {
Node *scene = editor_data.get_edited_scene_root(); Node *scene = editor_data.get_edited_scene_root((p_option == FILE_CLOSE || p_option == SCENE_TAB_CLOSE) ? tab_closing : -1);
if (!scene) { if (!scene) {
@@ -1957,7 +1964,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
String existing; String existing;
if (extensions.size()) { if (extensions.size()) {
String root_name(get_edited_scene()->get_name()); String root_name(scene->get_name());
existing = root_name + "." + extensions.front()->get().to_lower(); existing = root_name + "." + extensions.front()->get().to_lower();
} }
file->set_current_path(existing); file->set_current_path(existing);
@@ -2690,6 +2697,22 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} }
} }
void EditorNode::_discard_changes(const String &p_str) {
save_confirmation->hide();
switch (current_option) {
case FILE_CLOSE:
case SCENE_TAB_CLOSE: {
_remove_scene(tab_closing);
_update_scene_tabs();
current_option = -1;
} break;
}
}
void EditorNode::_update_debug_options() { void EditorNode::_update_debug_options() {
bool check_deploy_remote = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_deploy_remote_debug", false); bool check_deploy_remote = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_deploy_remote_debug", false);
@@ -4266,14 +4289,9 @@ void EditorNode::_scene_tab_closed(int p_tab) {
saved_version != editor_data.get_undo_redo().get_version() : saved_version != editor_data.get_undo_redo().get_version() :
editor_data.get_scene_version(p_tab) != 0; editor_data.get_scene_version(p_tab) != 0;
if (unsaved) { if (unsaved) {
confirmation->get_ok()->set_text(TTR("Yes")); save_confirmation->popup_centered_minsize();
//confirmation->get_cancel()->show();
confirmation->set_text(TTR("Close scene? (Unsaved changes will be lost)"));
confirmation->popup_centered_minsize();
} else { } else {
_remove_scene(p_tab); _discard_changes();
_update_scene_tabs();
} }
} }
@@ -4891,6 +4909,7 @@ void EditorNode::_bind_methods() {
ClassDB::bind_method("_scene_tab_script_edited", &EditorNode::_scene_tab_script_edited); ClassDB::bind_method("_scene_tab_script_edited", &EditorNode::_scene_tab_script_edited);
ClassDB::bind_method("_set_main_scene_state", &EditorNode::_set_main_scene_state); ClassDB::bind_method("_set_main_scene_state", &EditorNode::_set_main_scene_state);
ClassDB::bind_method("_update_scene_tabs", &EditorNode::_update_scene_tabs); ClassDB::bind_method("_update_scene_tabs", &EditorNode::_update_scene_tabs);
ClassDB::bind_method("_discard_changes", &EditorNode::_discard_changes);
ClassDB::bind_method("_prepare_history", &EditorNode::_prepare_history); ClassDB::bind_method("_prepare_history", &EditorNode::_prepare_history);
ClassDB::bind_method("_select_history", &EditorNode::_select_history); ClassDB::bind_method("_select_history", &EditorNode::_select_history);
@@ -5889,6 +5908,14 @@ EditorNode::EditorNode() {
gui_base->add_child(confirmation); gui_base->add_child(confirmation);
confirmation->connect("confirmed", this, "_menu_confirm_current"); confirmation->connect("confirmed", this, "_menu_confirm_current");
save_confirmation = memnew(ConfirmationDialog);
save_confirmation->get_ok()->set_text(TTR("Save & Close"));
save_confirmation->add_button(TTR("Don't Save"), OS::get_singleton()->get_swap_ok_cancel(), "discard");
save_confirmation->set_text(TTR("Save changes to the scene before closing?"));
gui_base->add_child(save_confirmation);
save_confirmation->connect("confirmed", this, "_menu_confirm_current");
save_confirmation->connect("custom_action", this, "_discard_changes");
accept = memnew(AcceptDialog); accept = memnew(AcceptDialog);
gui_base->add_child(accept); gui_base->add_child(accept);
accept->connect("confirmed", this, "_menu_confirm_current"); accept->connect("confirmed", this, "_menu_confirm_current");

View File

@@ -296,6 +296,7 @@ private:
//CallDialog *call_dialog; //CallDialog *call_dialog;
ConfirmationDialog *confirmation; ConfirmationDialog *confirmation;
ConfirmationDialog *save_confirmation;
ConfirmationDialog *import_confirmation; ConfirmationDialog *import_confirmation;
ConfirmationDialog *open_recent_confirmation; ConfirmationDialog *open_recent_confirmation;
ConfirmationDialog *pick_main_scene; ConfirmationDialog *pick_main_scene;
@@ -465,6 +466,7 @@ private:
void _vp_resized(); void _vp_resized();
void _save_scene(String p_file, int idx = -1); void _save_scene(String p_file, int idx = -1);
void _discard_changes(const String &p_str = String());
void _instance_request(const Vector<String> &p_files); void _instance_request(const Vector<String> &p_files);