Fix undoredo handling in some dialogs

This commit is contained in:
kobewi 2024-07-03 15:14:51 +02:00
parent 6a13fdcae3
commit 681769e2c9
7 changed files with 66 additions and 28 deletions

View File

@ -5261,6 +5261,14 @@ bool EditorNode::has_scenes_in_session() {
return !scenes.is_empty(); 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) { 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. 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"); String main_scene = GLOBAL_GET("application/run/main_scene");

View File

@ -916,6 +916,9 @@ public:
bool has_scenes_in_session(); bool has_scenes_in_session();
void undo();
void redo();
int execute_and_show_output(const String &p_title, const String &p_path, const List<String> &p_arguments, bool p_close_on_ok = true, bool p_close_on_errors = false, String *r_output = nullptr); int execute_and_show_output(const String &p_title, const String &p_path, const List<String> &p_arguments, bool p_close_on_ok = true, bool p_close_on_errors = false, String *r_output = nullptr);
EditorNode(); EditorNode();

View File

@ -168,28 +168,17 @@ void EditorSettingsDialog::_notification(int p_what) {
} }
void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) { void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
const Ref<InputEventKey> k = p_event; const Ref<InputEventKey> k = p_event;
if (k.is_valid() && k->is_pressed()) { if (k.is_valid() && k->is_pressed()) {
bool handled = false; bool handled = false;
if (ED_IS_SHORTCUT("ui_undo", p_event)) { if (ED_IS_SHORTCUT("ui_undo", p_event)) {
String action = undo_redo->get_current_action_name(); EditorNode::get_singleton()->undo();
if (!action.is_empty()) {
EditorNode::get_log()->add_message(vformat(TTR("Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
}
undo_redo->undo();
handled = true; handled = true;
} }
if (ED_IS_SHORTCUT("ui_redo", p_event)) { if (ED_IS_SHORTCUT("ui_redo", p_event)) {
undo_redo->redo(); EditorNode::get_singleton()->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);
}
handled = true; handled = true;
} }

View File

@ -781,6 +781,27 @@ void AnimationLibraryEditor::_update_editor(Object *p_mixer) {
emit_signal("update_editor", p_mixer); emit_signal("update_editor", p_mixer);
} }
void AnimationLibraryEditor::shortcut_input(const Ref<InputEvent> &p_event) {
const Ref<InputEventKey> 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() { void AnimationLibraryEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_update_editor", "mixer"), &AnimationLibraryEditor::_update_editor); ClassDB::bind_method(D_METHOD("_update_editor", "mixer"), &AnimationLibraryEditor::_update_editor);
ADD_SIGNAL(MethodInfo("update_editor")); ADD_SIGNAL(MethodInfo("update_editor"));
@ -788,6 +809,7 @@ void AnimationLibraryEditor::_bind_methods() {
AnimationLibraryEditor::AnimationLibraryEditor() { AnimationLibraryEditor::AnimationLibraryEditor() {
set_title(TTR("Edit Animation Libraries")); set_title(TTR("Edit Animation Libraries"));
set_process_shortcut_input(true);
file_dialog = memnew(EditorFileDialog); file_dialog = memnew(EditorFileDialog);
add_child(file_dialog); add_child(file_dialog);

View File

@ -113,6 +113,7 @@ class AnimationLibraryEditor : public AcceptDialog {
protected: protected:
void _notification(int p_what); void _notification(int p_what);
void _update_editor(Object *p_mixer); void _update_editor(Object *p_mixer);
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
static void _bind_methods(); static void _bind_methods();
public: public:

View File

@ -52,6 +52,31 @@
#include "scene/gui/texture_rect.h" #include "scene/gui/texture_rect.h"
#include "scene/gui/view_panner.h" #include "scene/gui/view_panner.h"
class UVEditDialog : public AcceptDialog {
GDCLASS(UVEditDialog, AcceptDialog);
void shortcut_input(const Ref<InputEvent> &p_event) override {
const Ref<InputEventKey> 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 { Node2D *Polygon2DEditor::_get_node() const {
return node; return node;
} }
@ -1305,9 +1330,10 @@ Polygon2DEditor::Polygon2DEditor() {
button_uv->connect(SceneStringName(pressed), callable_mp(this, &Polygon2DEditor::_menu_option).bind(MODE_EDIT_UV)); button_uv->connect(SceneStringName(pressed), callable_mp(this, &Polygon2DEditor::_menu_option).bind(MODE_EDIT_UV));
uv_mode = UV_MODE_EDIT_POINT; uv_mode = UV_MODE_EDIT_POINT;
uv_edit = memnew(AcceptDialog); uv_edit = memnew(UVEditDialog);
add_child(uv_edit);
uv_edit->set_title(TTR("Polygon 2D UV Editor")); 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(SceneStringName(confirmed), callable_mp(this, &Polygon2DEditor::_uv_edit_popup_hide));
uv_edit->connect("canceled", callable_mp(this, &Polygon2DEditor::_uv_edit_popup_hide)); uv_edit->connect("canceled", callable_mp(this, &Polygon2DEditor::_uv_edit_popup_hide));

View File

@ -235,28 +235,17 @@ void ProjectSettingsEditor::_select_type(Variant::Type p_type) {
} }
void ProjectSettingsEditor::shortcut_input(const Ref<InputEvent> &p_event) { void ProjectSettingsEditor::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
const Ref<InputEventKey> k = p_event; const Ref<InputEventKey> k = p_event;
if (k.is_valid() && k->is_pressed()) { if (k.is_valid() && k->is_pressed()) {
bool handled = false; bool handled = false;
if (ED_IS_SHORTCUT("ui_undo", p_event)) { if (ED_IS_SHORTCUT("ui_undo", p_event)) {
String action = undo_redo->get_current_action_name(); EditorNode::get_singleton()->undo();
if (!action.is_empty()) {
EditorNode::get_log()->add_message(vformat(TTR("Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
}
undo_redo->undo();
handled = true; handled = true;
} }
if (ED_IS_SHORTCUT("ui_redo", p_event)) { if (ED_IS_SHORTCUT("ui_redo", p_event)) {
undo_redo->redo(); EditorNode::get_singleton()->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);
}
handled = true; handled = true;
} }