1 /*************************************************************************/ 2 /* script_text_editor.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 /* */ 11 /* Permission is hereby granted, free of charge, to any person obtaining */ 12 /* a copy of this software and associated documentation files (the */ 13 /* "Software"), to deal in the Software without restriction, including */ 14 /* without limitation the rights to use, copy, modify, merge, publish, */ 15 /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 /* permit persons to whom the Software is furnished to do so, subject to */ 17 /* the following conditions: */ 18 /* */ 19 /* The above copyright notice and this permission notice shall be */ 20 /* included in all copies or substantial portions of the Software. */ 21 /* */ 22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 /*************************************************************************/ 30 31 #ifndef SCRIPT_TEXT_EDITOR_H 32 #define SCRIPT_TEXT_EDITOR_H 33 34 #include "scene/gui/color_picker.h" 35 #include "scene/gui/dialogs.h" 36 #include "scene/gui/tree.h" 37 #include "script_editor_plugin.h" 38 39 class ConnectionInfoDialog : public AcceptDialog { 40 41 GDCLASS(ConnectionInfoDialog, AcceptDialog); 42 43 Label *method; 44 Tree *tree; 45 46 virtual void ok_pressed(); 47 48 public: 49 void popup_connections(String p_method, Vector<Node *> p_nodes); 50 51 ConnectionInfoDialog(); 52 }; 53 54 class ScriptTextEditor : public ScriptEditorBase { 55 56 GDCLASS(ScriptTextEditor, ScriptEditorBase); 57 58 CodeTextEditor *code_editor; 59 RichTextLabel *warnings_panel; 60 61 Ref<Script> script; 62 bool script_is_valid; 63 64 Vector<String> functions; 65 66 List<Connection> missing_connections; 67 68 Vector<String> member_keywords; 69 70 HBoxContainer *edit_hb; 71 72 MenuButton *edit_menu; 73 MenuButton *search_menu; 74 PopupMenu *bookmarks_menu; 75 PopupMenu *breakpoints_menu; 76 PopupMenu *highlighter_menu; 77 PopupMenu *context_menu; 78 79 GotoLineDialog *goto_line_dialog; 80 ScriptEditorQuickOpen *quick_open; 81 ConnectionInfoDialog *connection_info_dialog; 82 83 PopupPanel *color_panel; 84 ColorPicker *color_picker; 85 Vector2 color_position; 86 String color_args; 87 88 void _update_member_keywords(); 89 90 struct ColorsCache { 91 Color symbol_color; 92 Color keyword_color; 93 Color basetype_color; 94 Color type_color; 95 Color usertype_color; 96 Color comment_color; 97 Color string_color; 98 } colors_cache; 99 100 bool theme_loaded; 101 102 enum { 103 EDIT_UNDO, 104 EDIT_REDO, 105 EDIT_CUT, 106 EDIT_COPY, 107 EDIT_PASTE, 108 EDIT_SELECT_ALL, 109 EDIT_COMPLETE, 110 EDIT_AUTO_INDENT, 111 EDIT_TRIM_TRAILING_WHITESAPCE, 112 EDIT_CONVERT_INDENT_TO_SPACES, 113 EDIT_CONVERT_INDENT_TO_TABS, 114 EDIT_TOGGLE_COMMENT, 115 EDIT_MOVE_LINE_UP, 116 EDIT_MOVE_LINE_DOWN, 117 EDIT_INDENT_RIGHT, 118 EDIT_INDENT_LEFT, 119 EDIT_DELETE_LINE, 120 EDIT_CLONE_DOWN, 121 EDIT_PICK_COLOR, 122 EDIT_TO_UPPERCASE, 123 EDIT_TO_LOWERCASE, 124 EDIT_CAPITALIZE, 125 EDIT_EVALUATE, 126 EDIT_TOGGLE_FOLD_LINE, 127 EDIT_FOLD_ALL_LINES, 128 EDIT_UNFOLD_ALL_LINES, 129 SEARCH_FIND, 130 SEARCH_FIND_NEXT, 131 SEARCH_FIND_PREV, 132 SEARCH_REPLACE, 133 SEARCH_LOCATE_FUNCTION, 134 SEARCH_GOTO_LINE, 135 SEARCH_IN_FILES, 136 BOOKMARK_TOGGLE, 137 BOOKMARK_GOTO_NEXT, 138 BOOKMARK_GOTO_PREV, 139 BOOKMARK_REMOVE_ALL, 140 DEBUG_TOGGLE_BREAKPOINT, 141 DEBUG_REMOVE_ALL_BREAKPOINTS, 142 DEBUG_GOTO_NEXT_BREAKPOINT, 143 DEBUG_GOTO_PREV_BREAKPOINT, 144 HELP_CONTEXTUAL, 145 LOOKUP_SYMBOL, 146 }; 147 148 protected: 149 void _update_breakpoint_list(); 150 void _breakpoint_item_pressed(int p_idx); 151 void _breakpoint_toggled(int p_row); 152 153 void _validate_script(); // No longer virtual. 154 void _update_bookmark_list(); 155 void _bookmark_item_pressed(int p_idx); 156 157 static void _code_complete_scripts(void *p_ud, const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force); 158 void _code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force); 159 160 void _load_theme_settings(); 161 void _set_theme_for_script(); 162 void _show_warnings_panel(bool p_show); 163 void _warning_clicked(Variant p_line); 164 165 void _notification(int p_what); 166 static void _bind_methods(); 167 168 Map<String, SyntaxHighlighter *> highlighters; 169 void _change_syntax_highlighter(int p_idx); 170 171 void _edit_option(int p_op); 172 void _edit_option_toggle_inline_comment(); 173 void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos); 174 void _text_edit_gui_input(const Ref<InputEvent> &ev); 175 void _color_changed(const Color &p_color); 176 _goto_line(int p_line)177 void _goto_line(int p_line) { goto_line(p_line); } 178 void _lookup_symbol(const String &p_symbol, int p_row, int p_column); 179 180 void _lookup_connections(int p_row, String p_method); 181 182 void _convert_case(CodeTextEditor::CaseStyle p_case); 183 184 Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); 185 bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; 186 void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); 187 188 String _get_absolute_path(const String &rel_path); 189 190 public: 191 void _update_connected_methods(); 192 193 virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter); 194 virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter); 195 void update_toggle_scripts_button(); 196 197 virtual void apply_code(); 198 virtual RES get_edited_resource() const; 199 virtual void set_edited_resource(const RES &p_res); 200 virtual Vector<String> get_functions(); 201 virtual void reload_text(); 202 virtual String get_name(); 203 virtual Ref<Texture> get_icon(); 204 virtual bool is_unsaved(); 205 virtual Variant get_edit_state(); 206 virtual void set_edit_state(const Variant &p_state); 207 virtual void ensure_focus(); 208 virtual void trim_trailing_whitespace(); 209 virtual void insert_final_newline(); 210 virtual void convert_indent_to_spaces(); 211 virtual void convert_indent_to_tabs(); 212 virtual void tag_saved_version(); 213 214 virtual void goto_line(int p_line, bool p_with_error = false); 215 void goto_line_selection(int p_line, int p_begin, int p_end); 216 void goto_line_centered(int p_line); 217 virtual void set_executing_line(int p_line); 218 virtual void clear_executing_line(); 219 220 virtual void reload(bool p_soft); 221 virtual void get_breakpoints(List<int> *p_breakpoints); 222 223 virtual void add_callback(const String &p_function, PoolStringArray p_args); 224 virtual void update_settings(); 225 226 virtual bool show_members_overview(); 227 228 virtual void set_tooltip_request_func(String p_method, Object *p_obj); 229 230 virtual void set_debugger_active(bool p_active); 231 232 Control *get_edit_menu(); 233 virtual void clear_edit_menu(); 234 static void register_editor(); 235 236 virtual void validate(); 237 238 ScriptTextEditor(); 239 ~ScriptTextEditor(); 240 }; 241 242 #endif // SCRIPT_TEXT_EDITOR_H 243