From 3be8a94868110f107454f4e9ae12c0db5c04c858 Mon Sep 17 00:00:00 2001 From: Andreas Haas Date: Tue, 16 May 2017 21:26:32 +0200 Subject: [PATCH] Editor: Make "open 2d/3d/script editor" shortcuts configurable. Also adds shortcuts for opening the AssetLib and for switching to the next/prev editor. --- editor/editor_node.cpp | 69 +++++++++++++++++-------- editor/editor_node.h | 5 +- editor/plugins/script_editor_plugin.cpp | 1 + 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 698066f1884..bc370a44da8 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -194,28 +194,20 @@ void EditorNode::_unhandled_input(const InputEvent &p_event) { filesystem_dock->focus_on_filter(); } - switch (p_event.key.scancode) { - - /*case KEY_F1: - if (!p_event.key.mod.shift && !p_event.key.mod.command) - _editor_select(EDITOR_SCRIPT); - break;*/ - case KEY_F1: - if (!p_event.key.mod.shift && !p_event.key.mod.command) - _editor_select(EDITOR_2D); - break; - case KEY_F2: - if (!p_event.key.mod.shift && !p_event.key.mod.command) - _editor_select(EDITOR_3D); - break; - case KEY_F3: - if (!p_event.key.mod.shift && !p_event.key.mod.command) - _editor_select(EDITOR_SCRIPT); - break; - /* case KEY_F5: _menu_option_confirm((p_event.key.mod.control&&p_event.key.mod.shift)?RUN_PLAY_CUSTOM_SCENE:RUN_PLAY,true); break; - case KEY_F6: _menu_option_confirm(RUN_PLAY_SCENE,true); break; - //case KEY_F7: _menu_option_confirm(RUN_PAUSE,true); break; - case KEY_F8: _menu_option_confirm(RUN_STOP,true); break;*/ + if (ED_IS_SHORTCUT("editor/editor_2d", p_event)) { + _editor_select(EDITOR_2D); + } else if (ED_IS_SHORTCUT("editor/editor_3d", p_event)) { + _editor_select(EDITOR_3D); + } else if (ED_IS_SHORTCUT("editor/editor_script", p_event)) { + _editor_select(EDITOR_SCRIPT); + } else if (ED_IS_SHORTCUT("editor/editor_help", p_event)) { + emit_signal("request_help_search", ""); + } else if (ED_IS_SHORTCUT("editor/editor_assetlib", p_event)) { + _editor_select(EDITOR_ASSETLIB); + } else if (ED_IS_SHORTCUT("editor/editor_next", p_event)) { + _editor_select_next(); + } else if (ED_IS_SHORTCUT("editor/editor_prev", p_event)) { + _editor_select_prev(); } } } @@ -454,6 +446,30 @@ void EditorNode::_node_renamed() { property_editor->update_tree(); } +void EditorNode::_editor_select_next() { + + int editor = _get_current_main_editor(); + + if (editor == editor_table.size() - 1) { + editor = 0; + } else { + editor++; + } + _editor_select(editor); +} + +void EditorNode::_editor_select_prev() { + + int editor = _get_current_main_editor(); + + if (editor == 0) { + editor = editor_table.size() - 1; + } else { + editor--; + } + _editor_select(editor); +} + Error EditorNode::load_resource(const String &p_scene) { RES res = ResourceLoader::load(p_scene); @@ -4795,6 +4811,7 @@ void EditorNode::_bind_methods() { ADD_SIGNAL(MethodInfo("pause_pressed")); ADD_SIGNAL(MethodInfo("stop_pressed")); ADD_SIGNAL(MethodInfo("request_help")); + ADD_SIGNAL(MethodInfo("request_help_search")); ADD_SIGNAL(MethodInfo("script_add_function_request", PropertyInfo(Variant::OBJECT, "obj"), PropertyInfo(Variant::STRING, "function"), PropertyInfo(Variant::POOL_STRING_ARRAY, "args"))); ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "obj"))); } @@ -6111,6 +6128,14 @@ EditorNode::EditorNode() { _dim_timer->set_wait_time(0.01666f); _dim_timer->connect("timeout", this, "_dim_timeout"); add_child(_dim_timer); + + ED_SHORTCUT("editor/editor_2d", TTR("Open 2D Editor"), KEY_F2); + ED_SHORTCUT("editor/editor_3d", TTR("Open 3D Editor"), KEY_F3); + ED_SHORTCUT("editor/editor_script", TTR("Open Script Editor"), KEY_F4); + ED_SHORTCUT("editor/editor_help", TTR("Search Help"), KEY_F1); + ED_SHORTCUT("editor/editor_assetlib", TTR("Open Asset Library")); + ED_SHORTCUT("editor/editor_next", TTR("Open the next Editor")); + ED_SHORTCUT("editor/editor_prev", TTR("Open the previous Editor")); } EditorNode::~EditorNode() { diff --git a/editor/editor_node.h b/editor/editor_node.h index fc107bb5053..92df04f4235 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -440,6 +440,8 @@ private: void _imported(Node *p_node); void _node_renamed(); + void _editor_select_next(); + void _editor_select_prev(); void _editor_select(int p_which); void _set_scene_metadata(const String &p_file, int p_idx = -1); void _get_scene_metadata(const String &p_file); @@ -618,7 +620,8 @@ public: enum EditorTable { EDITOR_2D = 0, EDITOR_3D, - EDITOR_SCRIPT + EDITOR_SCRIPT, + EDITOR_ASSETLIB }; void set_visible_editor(EditorTable p_table) { _editor_select(p_table); } diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index a5414325d07..18397264ef1 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1048,6 +1048,7 @@ void ScriptEditor::_notification(int p_what) { get_tree()->connect("tree_changed", this, "_tree_changed"); editor->connect("request_help", this, "_request_help"); + editor->connect("request_help_search", this, "_help_search"); } if (p_what == NOTIFICATION_EXIT_TREE) {