Path: blob/master/editor/script/script_text_editor.h
10277 views
/**************************************************************************/1/* script_text_editor.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "script_editor_plugin.h"3334#include "editor/gui/code_editor.h"35#include "scene/gui/color_picker.h"36#include "scene/gui/dialogs.h"37#include "scene/gui/option_button.h"38#include "scene/gui/tree.h"3940class RichTextLabel;4142class ConnectionInfoDialog : public AcceptDialog {43GDCLASS(ConnectionInfoDialog, AcceptDialog);4445Label *method = nullptr;46Tree *tree = nullptr;4748virtual void ok_pressed() override;4950public:51void popup_connections(const String &p_method, const Vector<Node *> &p_nodes);5253ConnectionInfoDialog();54};5556class ScriptTextEditor : public ScriptEditorBase {57GDCLASS(ScriptTextEditor, ScriptEditorBase);5859CodeTextEditor *code_editor = nullptr;60RichTextLabel *warnings_panel = nullptr;61RichTextLabel *errors_panel = nullptr;6263Ref<Script> script;64bool script_is_valid = false;65bool editor_enabled = false;6667Vector<String> functions;68List<ScriptLanguage::Warning> warnings;69List<ScriptLanguage::ScriptError> errors;70HashMap<String, List<ScriptLanguage::ScriptError>> depended_errors;71HashSet<int> safe_lines;7273List<Connection> missing_connections;7475Vector<String> member_keywords;7677HBoxContainer *edit_hb = nullptr;7879MenuButton *edit_menu = nullptr;80MenuButton *search_menu = nullptr;81MenuButton *goto_menu = nullptr;82PopupMenu *bookmarks_menu = nullptr;83PopupMenu *breakpoints_menu = nullptr;84PopupMenu *highlighter_menu = nullptr;85PopupMenu *context_menu = nullptr;8687int inline_color_line = -1;88int inline_color_start = -1;89int inline_color_end = -1;90PopupPanel *inline_color_popup = nullptr;91ColorPicker *inline_color_picker = nullptr;92OptionButton *inline_color_options = nullptr;93Ref<Texture2D> color_alpha_texture;9495GotoLinePopup *goto_line_popup = nullptr;96ScriptEditorQuickOpen *quick_open = nullptr;97ConnectionInfoDialog *connection_info_dialog = nullptr;9899int connection_gutter = -1;100void _gutter_clicked(int p_line, int p_gutter);101void _update_gutter_indexes();102103int line_number_gutter = -1;104Color default_line_number_color = Color(1, 1, 1);105Color safe_line_number_color = Color(1, 1, 1);106107Color marked_line_color = Color(1, 1, 1);108Color warning_line_color = Color(1, 1, 1);109Color folded_code_region_color = Color(1, 1, 1);110int previous_line = 0;111112PopupPanel *color_panel = nullptr;113ColorPicker *color_picker = nullptr;114Vector3i color_position;115String color_args;116117bool theme_loaded = false;118119enum {120EDIT_UNDO,121EDIT_REDO,122EDIT_CUT,123EDIT_COPY,124EDIT_PASTE,125EDIT_SELECT_ALL,126EDIT_COMPLETE,127EDIT_AUTO_INDENT,128EDIT_TRIM_TRAILING_WHITESAPCE,129EDIT_TRIM_FINAL_NEWLINES,130EDIT_CONVERT_INDENT_TO_SPACES,131EDIT_CONVERT_INDENT_TO_TABS,132EDIT_TOGGLE_COMMENT,133EDIT_MOVE_LINE_UP,134EDIT_MOVE_LINE_DOWN,135EDIT_INDENT,136EDIT_UNINDENT,137EDIT_DELETE_LINE,138EDIT_DUPLICATE_SELECTION,139EDIT_DUPLICATE_LINES,140EDIT_PICK_COLOR,141EDIT_TO_UPPERCASE,142EDIT_TO_LOWERCASE,143EDIT_CAPITALIZE,144EDIT_EVALUATE,145EDIT_TOGGLE_WORD_WRAP,146EDIT_TOGGLE_FOLD_LINE,147EDIT_FOLD_ALL_LINES,148EDIT_CREATE_CODE_REGION,149EDIT_UNFOLD_ALL_LINES,150SEARCH_FIND,151SEARCH_FIND_NEXT,152SEARCH_FIND_PREV,153SEARCH_REPLACE,154SEARCH_LOCATE_FUNCTION,155SEARCH_GOTO_LINE,156SEARCH_IN_FILES,157REPLACE_IN_FILES,158BOOKMARK_TOGGLE,159BOOKMARK_GOTO_NEXT,160BOOKMARK_GOTO_PREV,161BOOKMARK_REMOVE_ALL,162DEBUG_TOGGLE_BREAKPOINT,163DEBUG_REMOVE_ALL_BREAKPOINTS,164DEBUG_GOTO_NEXT_BREAKPOINT,165DEBUG_GOTO_PREV_BREAKPOINT,166HELP_CONTEXTUAL,167LOOKUP_SYMBOL,168EDIT_EMOJI_AND_SYMBOL,169};170171enum COLOR_MODE {172MODE_RGB,173MODE_STRING,174MODE_HSV,175MODE_OKHSL,176MODE_RGB8,177MODE_HEX,178MODE_MAX179};180181void _enable_code_editor();182183protected:184void _update_breakpoint_list();185void _breakpoint_item_pressed(int p_idx);186void _breakpoint_toggled(int p_row);187188void _on_caret_moved();189190void _validate_script(); // No longer virtual.191void _update_warnings();192void _update_errors();193void _update_bookmark_list();194void _bookmark_item_pressed(int p_idx);195196static void _code_complete_scripts(void *p_ud, const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force);197void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force);198199void _load_theme_settings();200void _set_theme_for_script();201void _show_errors_panel(bool p_show);202void _show_warnings_panel(bool p_show);203void _error_clicked(const Variant &p_line);204void _warning_clicked(const Variant &p_line);205206bool _is_valid_color_info(const Dictionary &p_info);207Array _inline_object_parse(const String &p_text);208void _inline_object_draw(const Dictionary &p_info, const Rect2 &p_rect);209void _inline_object_handle_click(const Dictionary &p_info, const Rect2 &p_rect);210String _picker_color_stringify(const Color &p_color, COLOR_MODE p_mode);211void _picker_color_changed(const Color &p_color);212void _update_color_constructor_options();213void _update_background_color();214void _update_color_text();215216void _notification(int p_what);217218HashMap<String, Ref<EditorSyntaxHighlighter>> highlighters;219void _change_syntax_highlighter(int p_idx);220221void _edit_option(int p_op);222void _edit_option_toggle_inline_comment();223void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos);224void _text_edit_gui_input(const Ref<InputEvent> &ev);225void _color_changed(const Color &p_color);226void _prepare_edit_menu();227228void _goto_line(int p_line) { goto_line(p_line); }229void _lookup_symbol(const String &p_symbol, int p_row, int p_column);230void _validate_symbol(const String &p_symbol);231232void _show_symbol_tooltip(const String &p_symbol, int p_row, int p_column);233234void _convert_case(CodeTextEditor::CaseStyle p_case);235236Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);237bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;238void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);239240String _get_absolute_path(const String &rel_path);241242public:243void _update_connected_methods();244245virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;246virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;247void update_toggle_files_button() override;248249virtual void apply_code() override;250virtual Ref<Resource> get_edited_resource() const override;251virtual void set_edited_resource(const Ref<Resource> &p_res) override;252virtual void enable_editor(Control *p_shortcut_context = nullptr) override;253virtual Vector<String> get_functions() override;254virtual void reload_text() override;255virtual String get_name() override;256virtual Ref<Texture2D> get_theme_icon() override;257virtual bool is_unsaved() override;258virtual Variant get_edit_state() override;259virtual void set_edit_state(const Variant &p_state) override;260virtual Variant get_navigation_state() override;261virtual void ensure_focus() override;262virtual void trim_trailing_whitespace() override;263virtual void trim_final_newlines() override;264virtual void insert_final_newline() override;265virtual void convert_indent() override;266virtual void tag_saved_version() override;267268virtual void goto_line(int p_line, int p_column = 0) override;269void goto_line_selection(int p_line, int p_begin, int p_end);270void goto_line_centered(int p_line, int p_column = 0);271virtual void set_executing_line(int p_line) override;272virtual void clear_executing_line() override;273274virtual void reload(bool p_soft) override;275virtual PackedInt32Array get_breakpoints() override;276virtual void set_breakpoint(int p_line, bool p_enabled) override;277virtual void clear_breakpoints() override;278279virtual void add_callback(const String &p_function, const PackedStringArray &p_args) override;280virtual void update_settings() override;281282virtual bool show_members_overview() override;283284virtual void set_tooltip_request_func(const Callable &p_toolip_callback) override;285286virtual void set_debugger_active(bool p_active) override;287288Control *get_edit_menu() override;289virtual void clear_edit_menu() override;290virtual void set_find_replace_bar(FindReplaceBar *p_bar) override;291292static void register_editor();293294virtual Control *get_base_editor() const override;295virtual CodeTextEditor *get_code_editor() const override;296297virtual void validate() override;298299Variant get_previous_state();300void store_previous_state();301302ScriptTextEditor();303~ScriptTextEditor();304};305306307