From 1ff98bfa1b4302871c3c5dfcbb8f80264b92cbef Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sat, 25 Sep 2021 20:33:57 +0200 Subject: [PATCH] Add history navigation in the script editor using extra mouse buttons This feature is enabled by default, but it can be disabled in the editor settings in case it interferes with other uses of the extra buttons (such as push-to-talk in a VoIP program). --- editor/editor_settings.cpp | 1 + editor/plugins/script_editor_plugin.cpp | 28 +++++++++++++++++++++++-- editor/plugins/script_editor_plugin.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 207acb42b5a7..fc2b36d2e329 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -444,6 +444,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { _initial_set("text_editor/navigation/show_minimap", true); _initial_set("text_editor/navigation/minimap_width", 80); hints["text_editor/navigation/minimap_width"] = PropertyInfo(Variant::INT, "text_editor/navigation/minimap_width", PROPERTY_HINT_RANGE, "50,250,1"); + _initial_set("text_editor/navigation/mouse_extra_buttons_navigate_history", true); // Appearance _initial_set("text_editor/appearance/show_line_numbers", true); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 8841fc1d8ab3..9a62d8863579 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -2543,6 +2543,27 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co } } +void ScriptEditor::_input(const Ref &p_event) { + // This feature can be disabled to avoid interfering with other uses of the additional + // mouse buttons, such as push-to-talk in a VoIP program. + if (EDITOR_GET("text_editor/navigation/mouse_extra_buttons_navigate_history")) { + const Ref mb = p_event; + + // Navigate the script history using additional mouse buttons present on some mice. + // This must be hardcoded as the editor shortcuts dialog doesn't allow assigning + // more than one shortcut per action. + if (mb.is_valid() && mb->is_pressed() && is_visible_in_tree() && !get_viewport()->gui_has_modal_stack()) { + if (mb->get_button_index() == BUTTON_XBUTTON1) { + _history_back(); + } + + if (mb->get_button_index() == BUTTON_XBUTTON2) { + _history_forward(); + } + } + } +} + void ScriptEditor::_unhandled_input(const Ref &p_event) { ERR_FAIL_COND(p_event.is_null()); @@ -3082,6 +3103,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_history_forward", &ScriptEditor::_history_forward); ClassDB::bind_method("_history_back", &ScriptEditor::_history_back); ClassDB::bind_method("_live_auto_reload_running_scripts", &ScriptEditor::_live_auto_reload_running_scripts); + ClassDB::bind_method("_input", &ScriptEditor::_input); ClassDB::bind_method("_unhandled_input", &ScriptEditor::_unhandled_input); ClassDB::bind_method("_script_list_gui_input", &ScriptEditor::_script_list_gui_input); ClassDB::bind_method("_toggle_members_overview_alpha_sort", &ScriptEditor::_toggle_members_overview_alpha_sort); @@ -3211,8 +3233,10 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { ED_SHORTCUT("script_editor/window_sort", TTR("Sort")); ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP); ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN); - ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work - ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA); + // FIXME: These should be `KEY_GREATER` and `KEY_LESS` but those don't work. + ED_SHORTCUT("script_editor/next_script", TTR("Next Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); + ED_SHORTCUT("script_editor/prev_script", TTR("Previous Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA); + set_process_input(true); set_process_unhandled_input(true); file_menu = memnew(MenuButton); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 27843baa29e6..440d49b22133 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -369,6 +369,7 @@ class ScriptEditor : public PanelContainer { bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); + void _input(const Ref &p_event); void _unhandled_input(const Ref &p_event); void _script_list_gui_input(const Ref &ev);