Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undoredo handling in some dialogs #93898

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> &p_arguments, bool p_close_on_ok = true, bool p_close_on_errors = false, String *r_output = nullptr);

EditorNode();
Expand Down
15 changes: 2 additions & 13 deletions editor/editor_settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,28 +168,17 @@ void EditorSettingsDialog::_notification(int p_what) {
}

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;
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;
}

Expand Down
22 changes: 22 additions & 0 deletions editor/plugins/animation_library_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,13 +781,35 @@ void AnimationLibraryEditor::_update_editor(Object *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() {
ClassDB::bind_method(D_METHOD("_update_editor", "mixer"), &AnimationLibraryEditor::_update_editor);
ADD_SIGNAL(MethodInfo("update_editor"));
}

AnimationLibraryEditor::AnimationLibraryEditor() {
set_title(TTR("Edit Animation Libraries"));
set_process_shortcut_input(true);

file_dialog = memnew(EditorFileDialog);
add_child(file_dialog);
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/animation_library_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputEvent> &p_event) override;
static void _bind_methods();

public:
Expand Down
30 changes: 28 additions & 2 deletions editor/plugins/polygon_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 {
return node;
}
Expand Down Expand Up @@ -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));

Expand Down
15 changes: 2 additions & 13 deletions editor/project_settings_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,28 +235,17 @@ void ProjectSettingsEditor::_select_type(Variant::Type p_type) {
}

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;
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;
}

Expand Down
Loading