/**************************************************************************/ /* script_editor_plugin.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* 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_plugin.h" #include "core/config/project_settings.h" #include "core/input/input.h" #include "core/io/config_file.h" #include "core/io/file_access.h" #include "core/io/json.h" #include "core/io/resource_loader.h" #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/string/fuzzy_search.h" #include "core/version.h" #include "editor/debugger/editor_debugger_node.h" #include "editor/debugger/script_editor_debugger.h" #include "editor/doc/editor_help_search.h" #include "editor/docks/editor_dock_manager.h" #include "editor/docks/filesystem_dock.h" #include "editor/docks/inspector_dock.h" #include "editor/docks/signals_dock.h" #include "editor/editor_interface.h" #include "editor/editor_main_screen.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" #include "editor/file_system/editor_paths.h" #include "editor/gui/code_editor.h" #include "editor/gui/editor_file_dialog.h" #include "editor/gui/editor_toaster.h" #include "editor/gui/window_wrapper.h" #include "editor/inspector/editor_context_menu_plugin.h" #include "editor/run/editor_run_bar.h" #include "editor/scene/editor_scene_tabs.h" #include "editor/script/editor_script.h" #include "editor/script/find_in_files.h" #include "editor/script/script_text_editor.h" #include "editor/script/syntax_highlighters.h" #include "editor/script/text_editor.h" #include "editor/settings/editor_command_palette.h" #include "editor/settings/editor_settings.h" #include "editor/shader/shader_editor_plugin.h" #include "editor/shader/text_shader_editor.h" #include "editor/themes/editor_scale.h" #include "editor/themes/editor_theme_manager.h" #include "scene/gui/separator.h" #include "scene/gui/tab_container.h" #include "scene/gui/texture_rect.h" #include "scene/main/node.h" #include "scene/main/window.h" #include "servers/display/display_server.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_event) { // Redirect navigational key events to the tree. Ref key = p_event; if (key.is_valid()) { if (key->is_action("ui_up", true) || key->is_action("ui_down", true) || key->is_action("ui_page_up") || key->is_action("ui_page_down")) { search_options->gui_input(key); 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().is_empty() || file.containsn(search_box->get_text()))) { TreeItem *ti = search_options->create_item(root); ti->set_text(0, file); if (root->get_first_child() == ti) { ti->select(0); } } } get_ok_button()->set_disabled(root->get_first_child() == nullptr); } void ScriptEditorQuickOpen::_confirmed() { TreeItem *ti = search_options->get_selected(); if (!ti) { return; } int line = ti->get_text(0).get_slicec(':', 1).to_int(); emit_signal(SNAME("goto_line"), line - 1); hide(); } void ScriptEditorQuickOpen::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { connect(SceneStringName(confirmed), callable_mp(this, &ScriptEditorQuickOpen::_confirmed)); search_box->set_clear_button_enabled(true); [[fallthrough]]; } case NOTIFICATION_VISIBILITY_CHANGED: { search_box->set_right_icon(search_options->get_editor_theme_icon(SNAME("Search"))); } break; case NOTIFICATION_EXIT_TREE: { disconnect(SceneStringName(confirmed), callable_mp(this, &ScriptEditorQuickOpen::_confirmed)); } break; } } void ScriptEditorQuickOpen::_bind_methods() { 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(TTRC("Search:"), search_box); search_box->connect(SceneStringName(text_changed), callable_mp(this, &ScriptEditorQuickOpen::_text_changed)); search_box->connect(SceneStringName(gui_input), callable_mp(this, &ScriptEditorQuickOpen::_sbox_input)); search_options = memnew(Tree); vbc->add_margin_child(TTRC("Matches:"), search_options, true); set_ok_button_text(TTRC("Open")); get_ok_button()->set_disabled(true); register_text_enter(search_box); set_hide_on_ok(false); search_options->connect("item_activated", callable_mp(this, &ScriptEditorQuickOpen::_confirmed)); search_options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); 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; /*** SCRIPT EDITOR ******/ String ScriptEditor::_get_debug_tooltip(const String &p_text, Node *p_se) { if (EDITOR_GET("text_editor/behavior/documentation/enable_tooltips")) { return String(); } // NOTE: See also `ScriptTextEditor::_show_symbol_tooltip()` for documentation tooltips enabled. String debug_value = EditorDebuggerNode::get_singleton()->get_var_value(p_text); if (!debug_value.is_empty()) { constexpr int DISPLAY_LIMIT = 1024; if (debug_value.size() > DISPLAY_LIMIT) { debug_value = debug_value.left(DISPLAY_LIMIT) + "... " + TTR("(truncated)"); } debug_value = TTR("Current value: ") + debug_value; } return debug_value; } void ScriptEditor::_script_created(Ref