/*************************************************************************/ /* script_editor_plugin.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2021 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_plugin.h" #include "core/config/project_settings.h" #include "core/input/input.h" #include "core/io/file_access.h" #include "core/io/resource_loader.h" #include "core/os/keyboard.h" #include "core/os/os.h" #include "editor/debugger/editor_debugger_node.h" #include "editor/debugger/script_editor_debugger.h" #include "editor/editor_node.h" #include "editor/editor_run_script.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/filesystem_dock.h" #include "editor/find_in_files.h" #include "editor/node_dock.h" #include "editor/plugins/shader_editor_plugin.h" #include "modules/visual_script/visual_script_editor.h" #include "scene/main/window.h" #include "scene/scene_string_names.h" #include "script_text_editor.h" #include "servers/display_server.h" #include "text_editor.h" /*** SYNTAX HIGHLIGHTER ****/ String EditorSyntaxHighlighter::_get_name() const { String ret; if (GDVIRTUAL_CALL(_get_name, ret)) { return ret; } return "Unnamed"; } Array EditorSyntaxHighlighter::_get_supported_languages() const { Array ret; if (GDVIRTUAL_CALL(_get_supported_languages, ret)) { return ret; } return Array(); } Ref EditorSyntaxHighlighter::_create() const { Ref syntax_highlighter; syntax_highlighter.instantiate(); if (get_script_instance()) { syntax_highlighter->set_script(get_script_instance()->get_script()); } return syntax_highlighter; } void EditorSyntaxHighlighter::_bind_methods() { ClassDB::bind_method(D_METHOD("_get_edited_resource"), &EditorSyntaxHighlighter::_get_edited_resource); GDVIRTUAL_BIND(_get_name) GDVIRTUAL_BIND(_get_supported_languages) } //// void EditorStandardSyntaxHighlighter::_update_cache() { highlighter->set_text_edit(text_edit); highlighter->clear_keyword_colors(); highlighter->clear_member_keyword_colors(); highlighter->clear_color_regions(); highlighter->set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/symbol_color")); highlighter->set_function_color(EDITOR_GET("text_editor/theme/highlighting/function_color")); highlighter->set_number_color(EDITOR_GET("text_editor/theme/highlighting/number_color")); highlighter->set_member_variable_color(EDITOR_GET("text_editor/theme/highlighting/member_variable_color")); /* Engine types. */ const Color type_color = EDITOR_GET("text_editor/theme/highlighting/engine_type_color"); List types; ClassDB::get_class_list(&types); for (const StringName &E : types) { highlighter->add_keyword_color(E, type_color); } /* User types. */ const Color usertype_color = EDITOR_GET("text_editor/theme/highlighting/user_type_color"); List global_classes; ScriptServer::get_global_class_list(&global_classes); for (const StringName &E : global_classes) { highlighter->add_keyword_color(E, usertype_color); } /* Autoloads. */ OrderedHashMap autoloads = ProjectSettings::get_singleton()->get_autoload_list(); for (OrderedHashMap::Element E = autoloads.front(); E; E = E.next()) { const ProjectSettings::AutoloadInfo &info = E.value(); if (info.is_singleton) { highlighter->add_keyword_color(info.name, usertype_color); } } const Ref