/**************************************************************************/ /* script_editor_plugin.h */ /**************************************************************************/ /* 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. */ /**************************************************************************/ #ifndef SCRIPT_EDITOR_PLUGIN_H #define SCRIPT_EDITOR_PLUGIN_H #include "core/object/script_language.h" #include "editor/editor_plugin.h" #include "scene/gui/dialogs.h" #include "scene/gui/panel_container.h" #include "scene/resources/syntax_highlighter.h" #include "scene/resources/text_file.h" class EditorFileDialog; class EditorHelpSearch; class FindReplaceBar; class HSplitContainer; class ItemList; class MenuButton; class TabContainer; class TextureRect; class Tree; class VSplitContainer; class WindowWrapper; class EditorSyntaxHighlighter : public SyntaxHighlighter { GDCLASS(EditorSyntaxHighlighter, SyntaxHighlighter) private: Ref edited_resourse; protected: static void _bind_methods(); GDVIRTUAL0RC(String, _get_name) GDVIRTUAL0RC(PackedStringArray, _get_supported_languages) public: virtual String _get_name() const; virtual PackedStringArray _get_supported_languages() const; void _set_edited_resource(const Ref &p_res) { edited_resourse = p_res; } Ref _get_edited_resource() { return edited_resourse; } virtual Ref _create() const; }; class EditorStandardSyntaxHighlighter : public EditorSyntaxHighlighter { GDCLASS(EditorStandardSyntaxHighlighter, EditorSyntaxHighlighter) private: Ref highlighter; public: virtual void _update_cache() override; virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); } virtual String _get_name() const override { return TTR("Standard"); } virtual Ref _create() const override; EditorStandardSyntaxHighlighter() { highlighter.instantiate(); } }; class EditorPlainTextSyntaxHighlighter : public EditorSyntaxHighlighter { GDCLASS(EditorPlainTextSyntaxHighlighter, EditorSyntaxHighlighter) public: virtual String _get_name() const override { return TTR("Plain Text"); } virtual Ref _create() const override; }; class EditorJSONSyntaxHighlighter : public EditorSyntaxHighlighter { GDCLASS(EditorJSONSyntaxHighlighter, EditorSyntaxHighlighter) private: Ref highlighter; public: virtual void _update_cache() override; virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); } virtual PackedStringArray _get_supported_languages() const override { return PackedStringArray{ "json" }; } virtual String _get_name() const override { return TTR("JSON"); } virtual Ref _create() const override; EditorJSONSyntaxHighlighter() { highlighter.instantiate(); } }; /////////////////////////////////////////////////////////////////////////////// class ScriptEditorQuickOpen : public ConfirmationDialog { GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog); LineEdit *search_box = nullptr; Tree *search_options = nullptr; 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 EditorDebuggerNode; class ScriptEditorBase : public VBoxContainer { GDCLASS(ScriptEditorBase, VBoxContainer); protected: static void _bind_methods(); public: virtual void add_syntax_highlighter(Ref p_highlighter) = 0; virtual void set_syntax_highlighter(Ref p_highlighter) = 0; virtual void apply_code() = 0; virtual Ref get_edited_resource() const = 0; virtual Vector get_functions() = 0; virtual void set_edited_resource(const Ref &p_res) = 0; virtual void enable_editor(Control *p_shortcut_context = nullptr) = 0; virtual void reload_text() = 0; virtual String get_name() = 0; virtual Ref get_theme_icon() = 0; virtual bool is_unsaved() = 0; virtual Variant get_edit_state() = 0; virtual void set_edit_state(const Variant &p_state) = 0; virtual Variant get_navigation_state() = 0; virtual void goto_line(int p_line, bool p_with_error = false) = 0; virtual void set_executing_line(int p_line) = 0; virtual void clear_executing_line() = 0; virtual void trim_trailing_whitespace() = 0; virtual void insert_final_newline() = 0; virtual void convert_indent() = 0; virtual void ensure_focus() = 0; virtual void tag_saved_version() = 0; virtual void reload(bool p_soft) {} virtual PackedInt32Array get_breakpoints() = 0; virtual void set_breakpoint(int p_line, bool p_enabled) = 0; virtual void clear_breakpoints() = 0; virtual void add_callback(const String &p_function, PackedStringArray p_args) = 0; virtual void update_settings() = 0; virtual void set_debugger_active(bool p_active) = 0; virtual bool can_lose_focus_on_node_selection() { return true; } virtual void update_toggle_scripts_button() {} virtual bool show_members_overview() = 0; virtual void set_tooltip_request_func(const Callable &p_toolip_callback) = 0; virtual Control *get_edit_menu() = 0; virtual void clear_edit_menu() = 0; virtual void set_find_replace_bar(FindReplaceBar *p_bar) = 0; virtual Control *get_base_editor() const = 0; virtual void validate() = 0; ScriptEditorBase() {} }; typedef ScriptEditorBase *(*CreateScriptEditorFunc)(const Ref &p_resource); class EditorScriptCodeCompletionCache; class FindInFilesDialog; class FindInFilesPanel; class ScriptEditor : public PanelContainer { GDCLASS(ScriptEditor, PanelContainer); enum { FILE_NEW, FILE_NEW_TEXTFILE, FILE_OPEN, FILE_REOPEN_CLOSED, FILE_OPEN_RECENT, FILE_SAVE, FILE_SAVE_AS, FILE_SAVE_ALL, FILE_THEME, FILE_RUN, FILE_CLOSE, CLOSE_DOCS, CLOSE_ALL, CLOSE_OTHER_TABS, TOGGLE_SCRIPTS_PANEL, SHOW_IN_FILE_SYSTEM, FILE_COPY_PATH, FILE_TOOL_RELOAD_SOFT, SEARCH_IN_FILES, REPLACE_IN_FILES, SEARCH_HELP, SEARCH_WEBSITE, HELP_SEARCH_FIND, HELP_SEARCH_FIND_NEXT, HELP_SEARCH_FIND_PREVIOUS, WINDOW_MOVE_UP, WINDOW_MOVE_DOWN, WINDOW_NEXT, WINDOW_PREV, WINDOW_SORT, WINDOW_SELECT_BASE = 100, }; enum { THEME_IMPORT, THEME_RELOAD, THEME_SAVE, THEME_SAVE_AS }; enum ScriptSortBy { SORT_BY_NAME, SORT_BY_PATH, SORT_BY_NONE }; enum ScriptListName { DISPLAY_NAME, DISPLAY_DIR_AND_NAME, DISPLAY_FULL_PATH, }; HBoxContainer *menu_hb = nullptr; MenuButton *file_menu = nullptr; MenuButton *edit_menu = nullptr; MenuButton *script_search_menu = nullptr; MenuButton *debug_menu = nullptr; PopupMenu *context_menu = nullptr; Timer *autosave_timer = nullptr; uint64_t idle = 0; PopupMenu *recent_scripts = nullptr; PopupMenu *theme_submenu = nullptr; Button *help_search = nullptr; Button *site_search = nullptr; Button *make_floating = nullptr; bool is_floating = false; EditorHelpSearch *help_search_dialog = nullptr; ItemList *script_list = nullptr; HSplitContainer *script_split = nullptr; ItemList *members_overview = nullptr; LineEdit *filter_scripts = nullptr; LineEdit *filter_methods = nullptr; VBoxContainer *scripts_vbox = nullptr; VBoxContainer *overview_vbox = nullptr; HBoxContainer *buttons_hbox = nullptr; Label *filename = nullptr; Button *members_overview_alphabeta_sort_button = nullptr; bool members_overview_enabled; ItemList *help_overview = nullptr; bool help_overview_enabled; VSplitContainer *list_split = nullptr; TabContainer *tab_container = nullptr; EditorFileDialog *file_dialog = nullptr; AcceptDialog *error_dialog = nullptr; ConfirmationDialog *erase_tab_confirm = nullptr; ScriptCreateDialog *script_create_dialog = nullptr; Button *scripts_visible = nullptr; FindReplaceBar *find_replace_bar = nullptr; String current_theme; TextureRect *script_icon = nullptr; Label *script_name_label = nullptr; Button *script_back = nullptr; Button *script_forward = nullptr; FindInFilesDialog *find_in_files_dialog = nullptr; FindInFilesPanel *find_in_files = nullptr; Button *find_in_files_button = nullptr; WindowWrapper *window_wrapper = nullptr; enum { SCRIPT_EDITOR_FUNC_MAX = 32, }; static int script_editor_func_count; static CreateScriptEditorFunc script_editor_funcs[SCRIPT_EDITOR_FUNC_MAX]; Vector> syntax_highlighters; struct ScriptHistory { Control *control = nullptr; Variant state; }; Vector history; int history_pos; List previous_scripts; List script_close_queue; void _tab_changed(int p_which); void _menu_option(int p_option); void _theme_option(int p_option); void _show_save_theme_as_dialog(); bool _has_docs_tab() const; bool _has_script_tab() const; void _prepare_file_menu(); void _file_menu_closed(); Tree *disk_changed_list = nullptr; ConfirmationDialog *disk_changed = nullptr; bool restoring_layout; String _get_debug_tooltip(const String &p_text, Node *_se); void _resave_scripts(const String &p_str); bool _test_script_times_on_disk(Ref p_for_script = Ref()); void _add_recent_script(String p_path); void _update_recent_scripts(); void _open_recent_script(int p_idx); void _show_error_dialog(String p_path); void _close_tab(int p_idx, bool p_save = true, bool p_history_back = true); void _update_find_replace_bar(); void _close_current_tab(bool p_save = true); void _close_discard_current_tab(const String &p_str); void _close_docs_tab(); void _close_other_tabs(); void _close_all_tabs(); void _queue_close_tabs(); void _copy_script_path(); void _ask_close_current_unsaved_tab(ScriptEditorBase *current); bool grab_focus_block; bool pending_auto_reload; bool auto_reload_running_scripts; void _live_auto_reload_running_scripts(); void _update_selected_editor_menu(); EditorScriptCodeCompletionCache *completion_cache = nullptr; void _editor_stop(); int edit_pass; void _add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args); void _res_saved_callback(const Ref &p_res); void _scene_saved_callback(const String &p_path); bool open_textfile_after_create = true; bool trim_trailing_whitespace_on_save; bool convert_indent_on_save; void _goto_script_line2(int p_line); void _goto_script_line(Ref p_script, int p_line); void _set_execution(Ref p_script, int p_line); void _clear_execution(Ref p_script); void _breaked(bool p_breaked, bool p_can_debug); void _script_created(Ref