diff --git a/modules/code_editor/SCsub b/modules/code_editor/SCsub index 112e01e12..4f3abc2a2 100644 --- a/modules/code_editor/SCsub +++ b/modules/code_editor/SCsub @@ -10,6 +10,7 @@ sources = [ "script_editor_plugin.cpp", "script_text_editor.cpp", "text_editor.cpp", + "script_editor_quick_open.cpp", ] env_mlp.add_source_files(env.modules_sources, sources) diff --git a/modules/code_editor/script_editor_plugin.cpp b/modules/code_editor/script_editor_plugin.cpp index 0c4b52a8f..19ff623a6 100644 --- a/modules/code_editor/script_editor_plugin.cpp +++ b/modules/code_editor/script_editor_plugin.cpp @@ -91,6 +91,7 @@ #include "scene/scene_string_names.h" #include "script_text_editor.h" #include "text_editor.h" +#include "script_editor_quick_open.h" #include "modules/modules_enabled.gen.h" @@ -190,104 +191,6 @@ public: virtual ~EditorScriptCodeCompletionCache() {} }; -void ScriptEditorQuickOpen::popup_dialog(const Vector &p_functions, bool p_dontclear) { - popup_centered_ratio(0.6); - if (p_dontclear) { - search_box->select_all(); - } else { - search_box->clear(); - } - search_box->grab_focus(); - functions = p_functions; - _update_search(); -} - -void ScriptEditorQuickOpen::_text_changed(const String &p_newtext) { - _update_search(); -} - -void ScriptEditorQuickOpen::_sbox_input(const Ref &p_ie) { - Ref k = p_ie; - - if (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_PAGEUP || k->get_scancode() == KEY_PAGEDOWN)) { - search_options->call("_gui_input", k); - search_box->accept_event(); - } -} - -void ScriptEditorQuickOpen::_update_search() { - search_options->clear(); - TreeItem *root = search_options->create_item(); - - for (int i = 0; i < functions.size(); i++) { - String file = functions[i]; - if ((search_box->get_text() == "" || file.findn(search_box->get_text()) != -1)) { - TreeItem *ti = search_options->create_item(root); - ti->set_text(0, file); - if (root->get_children() == ti) { - ti->select(0); - } - } - } - - get_ok()->set_disabled(root->get_children() == nullptr); -} - -void ScriptEditorQuickOpen::_confirmed() { - TreeItem *ti = search_options->get_selected(); - if (!ti) { - return; - } - int line = ti->get_text(0).get_slice(":", 1).to_int(); - - emit_signal("goto_line", line - 1); - hide(); -} - -void ScriptEditorQuickOpen::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - connect("confirmed", this, "_confirmed"); - - search_box->set_clear_button_enabled(true); - FALLTHROUGH; - } - case NOTIFICATION_THEME_CHANGED: { - search_box->set_right_icon(get_theme_icon("Search", "EditorIcons")); - } break; - case NOTIFICATION_EXIT_TREE: { - disconnect("confirmed", this, "_confirmed"); - } break; - } -} - -void ScriptEditorQuickOpen::_bind_methods() { - ClassDB::bind_method(D_METHOD("_text_changed"), &ScriptEditorQuickOpen::_text_changed); - ClassDB::bind_method(D_METHOD("_confirmed"), &ScriptEditorQuickOpen::_confirmed); - ClassDB::bind_method(D_METHOD("_sbox_input"), &ScriptEditorQuickOpen::_sbox_input); - - ADD_SIGNAL(MethodInfo("goto_line", PropertyInfo(Variant::INT, "line"))); -} - -ScriptEditorQuickOpen::ScriptEditorQuickOpen() { - VBoxContainer *vbc = memnew(VBoxContainer); - add_child(vbc); - search_box = memnew(LineEdit); - vbc->add_margin_child(TTR("Search:"), search_box); - search_box->connect("text_changed", this, "_text_changed"); - search_box->connect("gui_input", this, "_sbox_input"); - search_options = memnew(Tree); - vbc->add_margin_child(TTR("Matches:"), search_options, true); - get_ok()->set_text(TTR("Open")); - get_ok()->set_disabled(true); - register_text_enter(search_box); - set_hide_on_ok(false); - search_options->connect("item_activated", this, "_confirmed"); - search_options->set_hide_root(true); - search_options->set_hide_folding(true); - search_options->add_theme_constant_override("draw_guides", 1); -} - ///////////////////////////////// ScriptEditor *ScriptEditor::script_editor = nullptr; diff --git a/modules/code_editor/script_editor_plugin.h b/modules/code_editor/script_editor_plugin.h index 496c8309e..d58d40cf5 100644 --- a/modules/code_editor/script_editor_plugin.h +++ b/modules/code_editor/script_editor_plugin.h @@ -75,31 +75,7 @@ class Timer; class ToolButton; class Tree; class VSplitContainer; - -class ScriptEditorQuickOpen : public ConfirmationDialog { - GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog); - - LineEdit *search_box; - Tree *search_options; - String function; - - void _update_search(); - - void _sbox_input(const Ref &p_ie); - Vector functions; - - void _confirmed(); - void _text_changed(const String &p_newtext); - -protected: - void _notification(int p_what); - static void _bind_methods(); - -public: - void popup_dialog(const Vector &p_functions, bool p_dontclear = false); - ScriptEditorQuickOpen(); -}; - +class ScriptEditorQuickOpen; class ScriptEditorDebugger; class ScriptEditorBase : public VBoxContainer { diff --git a/modules/code_editor/script_editor_quick_open.cpp b/modules/code_editor/script_editor_quick_open.cpp new file mode 100644 index 000000000..f69f7c72a --- /dev/null +++ b/modules/code_editor/script_editor_quick_open.cpp @@ -0,0 +1,136 @@ +/*************************************************************************/ +/* script_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "script_editor_quick_open.h" + +#include "core/os/keyboard.h" + +#include "scene/gui/button.h" +#include "scene/gui/line_edit.h" +#include "scene/gui/tree.h" +#include "scene/gui/box_container.h" + +void ScriptEditorQuickOpen::popup_dialog(const Vector &p_functions, bool p_dontclear) { + popup_centered_ratio(0.6); + if (p_dontclear) { + search_box->select_all(); + } else { + search_box->clear(); + } + search_box->grab_focus(); + functions = p_functions; + _update_search(); +} + +void ScriptEditorQuickOpen::_text_changed(const String &p_newtext) { + _update_search(); +} + +void ScriptEditorQuickOpen::_sbox_input(const Ref &p_ie) { + Ref k = p_ie; + + if (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_PAGEUP || k->get_scancode() == KEY_PAGEDOWN)) { + search_options->call("_gui_input", k); + search_box->accept_event(); + } +} + +void ScriptEditorQuickOpen::_update_search() { + search_options->clear(); + TreeItem *root = search_options->create_item(); + + for (int i = 0; i < functions.size(); i++) { + String file = functions[i]; + if ((search_box->get_text() == "" || file.findn(search_box->get_text()) != -1)) { + TreeItem *ti = search_options->create_item(root); + ti->set_text(0, file); + if (root->get_children() == ti) { + ti->select(0); + } + } + } + + get_ok()->set_disabled(root->get_children() == nullptr); +} + +void ScriptEditorQuickOpen::_confirmed() { + TreeItem *ti = search_options->get_selected(); + if (!ti) { + return; + } + int line = ti->get_text(0).get_slice(":", 1).to_int(); + + emit_signal("goto_line", line - 1); + hide(); +} + +void ScriptEditorQuickOpen::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + connect("confirmed", this, "_confirmed"); + + search_box->set_clear_button_enabled(true); + FALLTHROUGH; + } + case NOTIFICATION_THEME_CHANGED: { + search_box->set_right_icon(get_theme_icon("Search", "EditorIcons")); + } break; + case NOTIFICATION_EXIT_TREE: { + disconnect("confirmed", this, "_confirmed"); + } break; + } +} + +void ScriptEditorQuickOpen::_bind_methods() { + ClassDB::bind_method(D_METHOD("_text_changed"), &ScriptEditorQuickOpen::_text_changed); + ClassDB::bind_method(D_METHOD("_confirmed"), &ScriptEditorQuickOpen::_confirmed); + ClassDB::bind_method(D_METHOD("_sbox_input"), &ScriptEditorQuickOpen::_sbox_input); + + ADD_SIGNAL(MethodInfo("goto_line", PropertyInfo(Variant::INT, "line"))); +} + +ScriptEditorQuickOpen::ScriptEditorQuickOpen() { + VBoxContainer *vbc = memnew(VBoxContainer); + add_child(vbc); + search_box = memnew(LineEdit); + vbc->add_margin_child(TTR("Search:"), search_box); + search_box->connect("text_changed", this, "_text_changed"); + search_box->connect("gui_input", this, "_sbox_input"); + search_options = memnew(Tree); + vbc->add_margin_child(TTR("Matches:"), search_options, true); + get_ok()->set_text(TTR("Open")); + get_ok()->set_disabled(true); + register_text_enter(search_box); + set_hide_on_ok(false); + search_options->connect("item_activated", this, "_confirmed"); + search_options->set_hide_root(true); + search_options->set_hide_folding(true); + search_options->add_theme_constant_override("draw_guides", 1); +} diff --git a/modules/code_editor/script_editor_quick_open.h b/modules/code_editor/script_editor_quick_open.h new file mode 100644 index 000000000..451193cf9 --- /dev/null +++ b/modules/code_editor/script_editor_quick_open.h @@ -0,0 +1,66 @@ +#ifndef SCRIPT_EDITOR_QUICK_OPEN_H +#define SCRIPT_EDITOR_QUICK_OPEN_H + +/*************************************************************************/ +/* script_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "scene/gui/dialogs.h" + +#include "core/containers/vector.h" +#include "core/string/ustring.h" + +class LineEdit; +class Tree; + +class ScriptEditorQuickOpen : public ConfirmationDialog { + GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog); + + LineEdit *search_box; + Tree *search_options; + String function; + + void _update_search(); + + void _sbox_input(const Ref &p_ie); + Vector functions; + + void _confirmed(); + void _text_changed(const String &p_newtext); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + void popup_dialog(const Vector &p_functions, bool p_dontclear = false); + ScriptEditorQuickOpen(); +}; + +#endif // SCRIPT_EDITOR_PLUGIN_H diff --git a/modules/code_editor/script_text_editor.cpp b/modules/code_editor/script_text_editor.cpp index d604341d0..17ef55012 100644 --- a/modules/code_editor/script_text_editor.cpp +++ b/modules/code_editor/script_text_editor.cpp @@ -30,30 +30,29 @@ #include "script_text_editor.h" -#include "core/variant/array.h" -#include "core/object/class_db.h" -#include "core/variant/dictionary.h" +#include "core/config/project_settings.h" +#include "core/containers/rb_set.h" #include "core/error/error_list.h" #include "core/error/error_macros.h" +#include "core/input/input.h" +#include "core/input/input_event.h" #include "core/io/resource_loader.h" #include "core/math/expression.h" #include "core/math/math_defs.h" #include "core/math/transform_2d.h" -#include "core/string/node_path.h" +#include "core/object/class_db.h" +#include "core/object/script_language.h" #include "core/os/file_access.h" -#include "core/input/input.h" -#include "core/input/input_event.h" #include "core/os/keyboard.h" #include "core/os/memory.h" -#include "core/config/project_settings.h" -#include "core/object/script_language.h" -#include "core/containers/rb_set.h" +#include "core/string/node_path.h" #include "core/string/string_name.h" #include "core/typedefs.h" +#include "core/variant/array.h" +#include "core/variant/dictionary.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" -#include "script_editor_plugin.h" #include "editor/script_editor_debugger.h" #include "scene/gui/box_container.h" #include "scene/gui/color_picker.h" @@ -69,6 +68,8 @@ #include "scene/main/node.h" #include "scene/main/scene_tree.h" #include "scene/resources/texture.h" +#include "script_editor_plugin.h" +#include "script_editor_quick_open.h" void ConnectionInfoDialog::ok_pressed() { }