From 681769e2c91124057d0421c44ff1e6582d926483 Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 3 Jul 2024 15:14:51 +0200 Subject: [PATCH] Fix undoredo handling in some dialogs --- editor/editor_node.cpp | 8 ++++++ editor/editor_node.h | 3 +++ editor/editor_settings_dialog.cpp | 15 ++--------- editor/plugins/animation_library_editor.cpp | 22 +++++++++++++++ editor/plugins/animation_library_editor.h | 1 + editor/plugins/polygon_2d_editor_plugin.cpp | 30 +++++++++++++++++++-- editor/project_settings_editor.cpp | 15 ++--------- 7 files changed, 66 insertions(+), 28 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 71603e6190b8..632b36c70590 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5261,6 +5261,14 @@ bool EditorNode::has_scenes_in_session() { return !scenes.is_empty(); } +void EditorNode::undo() { + trigger_menu_option(EDIT_UNDO, true); +} + +void EditorNode::redo() { + trigger_menu_option(EDIT_REDO, true); +} + bool EditorNode::ensure_main_scene(bool p_from_native) { pick_main_scene->set_meta("from_native", p_from_native); // Whether from play button or native run. String main_scene = GLOBAL_GET("application/run/main_scene"); diff --git a/editor/editor_node.h b/editor/editor_node.h index 28bd692ddfdc..7a26156ab8dd 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -916,6 +916,9 @@ class EditorNode : public Node { bool has_scenes_in_session(); + void undo(); + void redo(); + int execute_and_show_output(const String &p_title, const String &p_path, const List &p_arguments, bool p_close_on_ok = true, bool p_close_on_errors = false, String *r_output = nullptr); EditorNode(); diff --git a/editor/editor_settings_dialog.cpp b/editor/editor_settings_dialog.cpp index 6fd6a7103f3d..a71d43ad51a6 100644 --- a/editor/editor_settings_dialog.cpp +++ b/editor/editor_settings_dialog.cpp @@ -168,28 +168,17 @@ void EditorSettingsDialog::_notification(int p_what) { } void EditorSettingsDialog::shortcut_input(const Ref &p_event) { - ERR_FAIL_COND(p_event.is_null()); - EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); - const Ref k = p_event; if (k.is_valid() && k->is_pressed()) { bool handled = false; if (ED_IS_SHORTCUT("ui_undo", p_event)) { - String action = undo_redo->get_current_action_name(); - if (!action.is_empty()) { - EditorNode::get_log()->add_message(vformat(TTR("Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR); - } - undo_redo->undo(); + EditorNode::get_singleton()->undo(); handled = true; } if (ED_IS_SHORTCUT("ui_redo", p_event)) { - undo_redo->redo(); - String action = undo_redo->get_current_action_name(); - if (!action.is_empty()) { - EditorNode::get_log()->add_message(vformat(TTR("Redo: %s"), action), EditorLog::MSG_TYPE_EDITOR); - } + EditorNode::get_singleton()->redo(); handled = true; } diff --git a/editor/plugins/animation_library_editor.cpp b/editor/plugins/animation_library_editor.cpp index afe7ea83d8cf..b07db993ba93 100644 --- a/editor/plugins/animation_library_editor.cpp +++ b/editor/plugins/animation_library_editor.cpp @@ -781,6 +781,27 @@ void AnimationLibraryEditor::_update_editor(Object *p_mixer) { emit_signal("update_editor", p_mixer); } +void AnimationLibraryEditor::shortcut_input(const Ref &p_event) { + const Ref k = p_event; + if (k.is_valid() && k->is_pressed()) { + bool handled = false; + + if (ED_IS_SHORTCUT("ui_undo", p_event)) { + EditorNode::get_singleton()->undo(); + handled = true; + } + + if (ED_IS_SHORTCUT("ui_redo", p_event)) { + EditorNode::get_singleton()->redo(); + handled = true; + } + + if (handled) { + set_input_as_handled(); + } + } +} + void AnimationLibraryEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_editor", "mixer"), &AnimationLibraryEditor::_update_editor); ADD_SIGNAL(MethodInfo("update_editor")); @@ -788,6 +809,7 @@ void AnimationLibraryEditor::_bind_methods() { AnimationLibraryEditor::AnimationLibraryEditor() { set_title(TTR("Edit Animation Libraries")); + set_process_shortcut_input(true); file_dialog = memnew(EditorFileDialog); add_child(file_dialog); diff --git a/editor/plugins/animation_library_editor.h b/editor/plugins/animation_library_editor.h index c8d9274f4f20..beb34c6343a8 100644 --- a/editor/plugins/animation_library_editor.h +++ b/editor/plugins/animation_library_editor.h @@ -113,6 +113,7 @@ class AnimationLibraryEditor : public AcceptDialog { protected: void _notification(int p_what); void _update_editor(Object *p_mixer); + virtual void shortcut_input(const Ref &p_event) override; static void _bind_methods(); public: diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index b5db7bef7051..e442c37edd51 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -52,6 +52,31 @@ #include "scene/gui/texture_rect.h" #include "scene/gui/view_panner.h" +class UVEditDialog : public AcceptDialog { + GDCLASS(UVEditDialog, AcceptDialog); + + void shortcut_input(const Ref &p_event) override { + const Ref k = p_event; + if (k.is_valid() && k->is_pressed()) { + bool handled = false; + + if (ED_IS_SHORTCUT("ui_undo", p_event)) { + EditorNode::get_singleton()->undo(); + handled = true; + } + + if (ED_IS_SHORTCUT("ui_redo", p_event)) { + EditorNode::get_singleton()->redo(); + handled = true; + } + + if (handled) { + set_input_as_handled(); + } + } + } +}; + Node2D *Polygon2DEditor::_get_node() const { return node; } @@ -1305,9 +1330,10 @@ Polygon2DEditor::Polygon2DEditor() { button_uv->connect(SceneStringName(pressed), callable_mp(this, &Polygon2DEditor::_menu_option).bind(MODE_EDIT_UV)); uv_mode = UV_MODE_EDIT_POINT; - uv_edit = memnew(AcceptDialog); - add_child(uv_edit); + uv_edit = memnew(UVEditDialog); uv_edit->set_title(TTR("Polygon 2D UV Editor")); + uv_edit->set_process_shortcut_input(true); + add_child(uv_edit); uv_edit->connect(SceneStringName(confirmed), callable_mp(this, &Polygon2DEditor::_uv_edit_popup_hide)); uv_edit->connect("canceled", callable_mp(this, &Polygon2DEditor::_uv_edit_popup_hide)); diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 943e345e9748..bdf4e41c5f8c 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -235,28 +235,17 @@ void ProjectSettingsEditor::_select_type(Variant::Type p_type) { } void ProjectSettingsEditor::shortcut_input(const Ref &p_event) { - ERR_FAIL_COND(p_event.is_null()); - EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); - const Ref k = p_event; if (k.is_valid() && k->is_pressed()) { bool handled = false; if (ED_IS_SHORTCUT("ui_undo", p_event)) { - String action = undo_redo->get_current_action_name(); - if (!action.is_empty()) { - EditorNode::get_log()->add_message(vformat(TTR("Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR); - } - undo_redo->undo(); + EditorNode::get_singleton()->undo(); handled = true; } if (ED_IS_SHORTCUT("ui_redo", p_event)) { - undo_redo->redo(); - String action = undo_redo->get_current_action_name(); - if (!action.is_empty()) { - EditorNode::get_log()->add_message(vformat(TTR("Redo: %s"), action), EditorLog::MSG_TYPE_EDITOR); - } + EditorNode::get_singleton()->redo(); handled = true; }