summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/undo_redo.cpp16
-rw-r--r--core/undo_redo.h4
-rw-r--r--editor/editor_node.cpp152
-rw-r--r--editor/editor_node.h1
4 files changed, 64 insertions, 109 deletions
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index b3f9dd818d..b9a2fdd0ac 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -299,26 +299,30 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
}
}
-void UndoRedo::redo() {
+bool UndoRedo::redo() {
- ERR_FAIL_COND(action_level > 0);
+ ERR_FAIL_COND_V(action_level > 0, false);
if ((current_action + 1) >= actions.size())
- return; //nothing to redo
+ return false; //nothing to redo
current_action++;
_process_operation_list(actions[current_action].do_ops.front());
version++;
+
+ return true;
}
-void UndoRedo::undo() {
+bool UndoRedo::undo() {
- ERR_FAIL_COND(action_level > 0);
+ ERR_FAIL_COND_V(action_level > 0, false);
if (current_action < 0)
- return; //nothing to redo
+ return false; //nothing to redo
_process_operation_list(actions[current_action].undo_ops.front());
current_action--;
version--;
+
+ return true;
}
void UndoRedo::clear_history() {
diff --git a/core/undo_redo.h b/core/undo_redo.h
index a373296b73..3a17c78851 100644
--- a/core/undo_redo.h
+++ b/core/undo_redo.h
@@ -109,8 +109,8 @@ public:
void commit_action();
- void redo();
- void undo();
+ bool redo();
+ bool undo();
String get_current_action_name() const;
void clear_history();
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 6256856b40..6084332dfb 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -595,9 +595,7 @@ void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const St
Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS);
if (err != OK) {
- current_option = -1;
- accept->set_text(TTR("Error saving resource!"));
- accept->popup_centered_minsize();
+ show_accept(TTR("Error saving resource!"), TTR("I see..."));
return;
}
@@ -683,26 +681,21 @@ void EditorNode::_dialog_display_save_error(String p_file, Error p_error) {
if (p_error) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
-
switch (p_error) {
case ERR_FILE_CANT_WRITE: {
- accept->set_text(TTR("Can't open file for writing:") + " " + p_file.get_extension());
+ show_accept(TTR("Can't open file for writing:") + " " + p_file.get_extension(), TTR("I see..."));
} break;
case ERR_FILE_UNRECOGNIZED: {
- accept->set_text(TTR("Requested file format unknown:") + " " + p_file.get_extension());
+ show_accept(TTR("Requested file format unknown:") + " " + p_file.get_extension(), TTR("I see..."));
} break;
default: {
- accept->set_text(TTR("Error while saving."));
+ show_accept(TTR("Error while saving."), TTR("I see..."));
} break;
}
-
- accept->popup_centered_minsize();
}
}
@@ -710,34 +703,29 @@ void EditorNode::_dialog_display_load_error(String p_file, Error p_error) {
if (p_error) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
-
switch (p_error) {
case ERR_CANT_OPEN: {
- accept->set_text(vformat(TTR("Can't open '%s'. The file could have been moved or deleted."), p_file.get_file()));
+ show_accept(vformat(TTR("Can't open '%s'. The file could have been moved or deleted."), p_file.get_file()), TTR("I see..."));
} break;
case ERR_PARSE_ERROR: {
- accept->set_text(vformat(TTR("Error while parsing '%s'."), p_file.get_file()));
+ show_accept(vformat(TTR("Error while parsing '%s'."), p_file.get_file()), TTR("I see..."));
} break;
case ERR_FILE_CORRUPT: {
- accept->set_text(vformat(TTR("Unexpected end of file '%s'."), p_file.get_file()));
+ show_accept(vformat(TTR("Unexpected end of file '%s'."), p_file.get_file()), TTR("I see..."));
} break;
case ERR_FILE_NOT_FOUND: {
- accept->set_text(vformat(TTR("Missing '%s' or its dependencies."), p_file.get_file()));
+ show_accept(vformat(TTR("Missing '%s' or its dependencies."), p_file.get_file()), TTR("I see..."));
} break;
default: {
- accept->set_text(vformat(TTR("Error while loading '%s'."), p_file.get_file()));
+ show_accept(vformat(TTR("Error while loading '%s'."), p_file.get_file()), TTR("I see..."));
} break;
}
-
- accept->popup_centered_minsize();
}
}
@@ -998,10 +986,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
if (!scene) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("This operation can't be done without a tree root."));
- accept->popup_centered_minsize();
+ show_accept(TTR("This operation can't be done without a tree root."), TTR("I see..."));
return;
}
@@ -1029,10 +1014,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
if (err != OK) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."));
- accept->popup_centered_minsize();
+ show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("I see..."));
return;
}
@@ -1040,10 +1022,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
// (hacky but needed for the tree to update properly)
Node *dummy_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE);
if (!dummy_scene) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."));
- accept->popup_centered_minsize();
+ show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("I see..."));
return;
}
memdelete(dummy_scene);
@@ -1179,10 +1158,7 @@ void EditorNode::_dialog_action(String p_file) {
ml = ResourceLoader::load(p_file, "MeshLibrary");
if (ml.is_null()) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("Can't load MeshLibrary for merging!"));
- accept->popup_centered_minsize();
+ show_accept(TTR("Can't load MeshLibrary for merging!"), TTR("I see..."));
return;
}
}
@@ -1195,11 +1171,7 @@ void EditorNode::_dialog_action(String p_file) {
Error err = ResourceSaver::save(p_file, ml);
if (err) {
-
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("Error saving MeshLibrary!"));
- accept->popup_centered_minsize();
+ show_accept(TTR("Error saving MeshLibrary!"), TTR("I see..."));
return;
}
@@ -1211,10 +1183,7 @@ void EditorNode::_dialog_action(String p_file) {
tileset = ResourceLoader::load(p_file, "TileSet");
if (tileset.is_null()) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("Can't load TileSet for merging!"));
- accept->popup_centered_minsize();
+ show_accept(TTR("Can't load TileSet for merging!"), TTR("I see..."));
return;
}
@@ -1227,10 +1196,7 @@ void EditorNode::_dialog_action(String p_file) {
Error err = ResourceSaver::save(p_file, tileset);
if (err) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("Error saving TileSet!"));
- accept->popup_centered_minsize();
+ show_accept("Error saving TileSet!", "I see...");
return;
}
} break;
@@ -1584,10 +1550,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
Node *scene = editor_data.get_edited_scene_root();
if (!scene) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("There is no defined scene to run."));
- accept->popup_centered_minsize();
+ show_accept(TTR("There is no defined scene to run."), TTR("I see..."));
return;
}
@@ -1641,10 +1604,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
if (scene->get_filename() == "") {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("Current scene was never saved, please save it prior to running."));
- accept->popup_centered_minsize();
+ show_accept(TTR("Current scene was never saved, please save it prior to running."), TTR("I see..."));
return;
}
@@ -1675,10 +1635,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
if (error != OK) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("Could not start subprocess!"));
- accept->popup_centered_minsize();
+ show_accept(TTR("Could not start subprocess!"), TTR("I see..."));
return;
}
@@ -1796,10 +1753,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
if (!scene) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("This operation can't be done without a tree root."));
- accept->popup_centered_minsize();
+ show_accept(TTR("This operation can't be done without a tree root."), TTR("I see..."));
break;
}
@@ -1862,10 +1816,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
if (!editor_data.get_edited_scene_root()) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("This operation can't be done without a scene."));
- accept->popup_centered_minsize();
+ show_accept(TTR("This operation can't be done without a scene."), TTR("I see..."));
break;
}
@@ -1885,10 +1836,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
//Make sure that the scene has a root before trying to convert to tileset
if (!editor_data.get_edited_scene_root()) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("This operation can't be done without a root node."));
- accept->popup_centered_minsize();
+ show_accept(TTR("This operation can't be done without a root node."), TTR("I see..."));
break;
}
@@ -1913,10 +1861,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
if (!editor_data.get_edited_scene_root()) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("This operation can't be done without a selected node."));
- accept->popup_centered_minsize();
+ show_accept(TTR("This operation can't be done without a selected node."), TTR("I see..."));
break;
}
@@ -1946,25 +1891,29 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
case EDIT_UNDO: {
if (Input::get_singleton()->get_mouse_button_mask() & 0x7) {
- break; // can't undo while mouse buttons are pressed
- }
-
- String action = editor_data.get_undo_redo().get_current_action_name();
- if (action != "")
- log->add_message("UNDO: " + action);
+ log->add_message("Can't UNDO while mouse buttons are pressed.");
+ } else {
+ String action = editor_data.get_undo_redo().get_current_action_name();
- editor_data.get_undo_redo().undo();
+ if (!editor_data.get_undo_redo().undo()) {
+ log->add_message("There is nothing to UNDO.");
+ } else if (action != "") {
+ log->add_message("UNDO: " + action);
+ }
+ }
} break;
case EDIT_REDO: {
- if (Input::get_singleton()->get_mouse_button_mask() & 0x7)
- break; // can't redo while mouse buttons are pressed
-
- editor_data.get_undo_redo().redo();
- String action = editor_data.get_undo_redo().get_current_action_name();
- if (action != "")
- log->add_message("REDO: " + action);
-
+ if (Input::get_singleton()->get_mouse_button_mask() & 0x7) {
+ log->add_message("Can't REDO while mouse buttons are pressed.");
+ } else {
+ if (!editor_data.get_undo_redo().redo()) {
+ log->add_message("There is nothing to REDO.");
+ } else {
+ String action = editor_data.get_undo_redo().get_current_action_name();
+ log->add_message("REDO: " + action);
+ }
+ }
} break;
case EDIT_REVERT: {
@@ -2185,10 +2134,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
OS::get_singleton()->set_low_processor_usage_mode(false);
EditorSettings::get_singleton()->set_project_metadata("editor_options", "update_always", true);
- current_option = -1;
- accept->get_ok()->set_text(TTR("I see..."));
- accept->set_text(TTR("This option is deprecated. Situations where refresh must be forced are now considered a bug. Please report."));
- accept->popup_centered_minsize();
+ show_accept(TTR("This option is deprecated. Situations where refresh must be forced are now considered a bug. Please report."), TTR("I see..."));
} break;
case SETTINGS_UPDATE_CHANGES: {
@@ -2787,10 +2733,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
if (!lpath.begins_with("res://")) {
- current_option = -1;
- accept->get_ok()->set_text(TTR("Ugh"));
- accept->set_text(TTR("Error loading scene, it must be inside the project path. Use 'Import' to open the scene, then save it inside the project path."));
- accept->popup_centered_minsize();
+ show_accept(TTR("Error loading scene, it must be inside the project path. Use 'Import' to open the scene, then save it inside the project path."), TTR("Ugh"));
opening_prev = false;
return ERR_FILE_NOT_FOUND;
}
@@ -3204,6 +3147,13 @@ Error EditorNode::export_preset(const String &p_preset, const String &p_path, bo
return OK;
}
+void EditorNode::show_accept(const String &p_text, const String &p_title) {
+ current_option = -1;
+ accept->get_ok()->set_text(p_title);
+ accept->set_text(p_text);
+ accept->popup_centered_minsize();
+}
+
void EditorNode::show_warning(const String &p_text, const String &p_title) {
warning->set_text(p_text);
diff --git a/editor/editor_node.h b/editor/editor_node.h
index dedd947633..4241520b30 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -685,6 +685,7 @@ public:
Ref<Theme> get_editor_theme() const { return theme; }
+ void show_accept(const String &p_text, const String &p_title);
void show_warning(const String &p_text, const String &p_title = "Warning!");
Error export_preset(const String &p_preset, const String &p_path, bool p_debug, const String &p_password, bool p_quit_after = false);