1 | /**************************************************************************/ |
2 | /* script_text_editor.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
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 "script_editor_plugin.h" |
35 | |
36 | #include "editor/code_editor.h" |
37 | #include "scene/gui/color_picker.h" |
38 | #include "scene/gui/dialogs.h" |
39 | #include "scene/gui/tree.h" |
40 | |
41 | class RichTextLabel; |
42 | |
43 | class ConnectionInfoDialog : public AcceptDialog { |
44 | GDCLASS(ConnectionInfoDialog, AcceptDialog); |
45 | |
46 | Label *method = nullptr; |
47 | Tree *tree = nullptr; |
48 | |
49 | virtual void ok_pressed() override; |
50 | |
51 | public: |
52 | void (String p_method, Vector<Node *> p_nodes); |
53 | |
54 | ConnectionInfoDialog(); |
55 | }; |
56 | |
57 | class ScriptTextEditor : public ScriptEditorBase { |
58 | GDCLASS(ScriptTextEditor, ScriptEditorBase); |
59 | |
60 | CodeTextEditor *code_editor = nullptr; |
61 | RichTextLabel *warnings_panel = nullptr; |
62 | RichTextLabel *errors_panel = nullptr; |
63 | |
64 | Ref<Script> script; |
65 | bool script_is_valid = false; |
66 | bool editor_enabled = false; |
67 | |
68 | Vector<String> functions; |
69 | List<ScriptLanguage::Warning> warnings; |
70 | List<ScriptLanguage::ScriptError> errors; |
71 | HashMap<String, List<ScriptLanguage::ScriptError>> depended_errors; |
72 | HashSet<int> safe_lines; |
73 | |
74 | List<Connection> missing_connections; |
75 | |
76 | Vector<String> member_keywords; |
77 | |
78 | HBoxContainer *edit_hb = nullptr; |
79 | |
80 | MenuButton * = nullptr; |
81 | MenuButton * = nullptr; |
82 | MenuButton * = nullptr; |
83 | PopupMenu * = nullptr; |
84 | PopupMenu * = nullptr; |
85 | PopupMenu * = nullptr; |
86 | PopupMenu * = nullptr; |
87 | |
88 | GotoLineDialog *goto_line_dialog = nullptr; |
89 | ScriptEditorQuickOpen *quick_open = nullptr; |
90 | ConnectionInfoDialog *connection_info_dialog = nullptr; |
91 | |
92 | int connection_gutter = -1; |
93 | void _gutter_clicked(int p_line, int p_gutter); |
94 | void _update_gutter_indexes(); |
95 | |
96 | int line_number_gutter = -1; |
97 | Color default_line_number_color = Color(1, 1, 1); |
98 | Color safe_line_number_color = Color(1, 1, 1); |
99 | |
100 | Color marked_line_color = Color(1, 1, 1); |
101 | Color folded_code_region_color = Color(1, 1, 1); |
102 | |
103 | PopupPanel *color_panel = nullptr; |
104 | ColorPicker *color_picker = nullptr; |
105 | Vector2 color_position; |
106 | String color_args; |
107 | |
108 | bool theme_loaded = false; |
109 | |
110 | enum { |
111 | EDIT_UNDO, |
112 | EDIT_REDO, |
113 | EDIT_CUT, |
114 | EDIT_COPY, |
115 | EDIT_PASTE, |
116 | EDIT_SELECT_ALL, |
117 | EDIT_COMPLETE, |
118 | EDIT_AUTO_INDENT, |
119 | EDIT_TRIM_TRAILING_WHITESAPCE, |
120 | EDIT_CONVERT_INDENT_TO_SPACES, |
121 | EDIT_CONVERT_INDENT_TO_TABS, |
122 | , |
123 | EDIT_MOVE_LINE_UP, |
124 | EDIT_MOVE_LINE_DOWN, |
125 | EDIT_INDENT, |
126 | EDIT_UNINDENT, |
127 | EDIT_DELETE_LINE, |
128 | EDIT_DUPLICATE_SELECTION, |
129 | EDIT_PICK_COLOR, |
130 | EDIT_TO_UPPERCASE, |
131 | EDIT_TO_LOWERCASE, |
132 | EDIT_CAPITALIZE, |
133 | EDIT_EVALUATE, |
134 | EDIT_TOGGLE_WORD_WRAP, |
135 | EDIT_TOGGLE_FOLD_LINE, |
136 | EDIT_FOLD_ALL_LINES, |
137 | EDIT_CREATE_CODE_REGION, |
138 | EDIT_UNFOLD_ALL_LINES, |
139 | SEARCH_FIND, |
140 | SEARCH_FIND_NEXT, |
141 | SEARCH_FIND_PREV, |
142 | SEARCH_REPLACE, |
143 | SEARCH_LOCATE_FUNCTION, |
144 | SEARCH_GOTO_LINE, |
145 | SEARCH_IN_FILES, |
146 | REPLACE_IN_FILES, |
147 | BOOKMARK_TOGGLE, |
148 | BOOKMARK_GOTO_NEXT, |
149 | BOOKMARK_GOTO_PREV, |
150 | BOOKMARK_REMOVE_ALL, |
151 | DEBUG_TOGGLE_BREAKPOINT, |
152 | DEBUG_REMOVE_ALL_BREAKPOINTS, |
153 | DEBUG_GOTO_NEXT_BREAKPOINT, |
154 | DEBUG_GOTO_PREV_BREAKPOINT, |
155 | HELP_CONTEXTUAL, |
156 | LOOKUP_SYMBOL, |
157 | }; |
158 | |
159 | void _enable_code_editor(); |
160 | |
161 | protected: |
162 | void _update_breakpoint_list(); |
163 | void _breakpoint_item_pressed(int p_idx); |
164 | void _breakpoint_toggled(int p_row); |
165 | |
166 | void _validate_script(); // No longer virtual. |
167 | void _update_warnings(); |
168 | void _update_errors(); |
169 | void _update_bookmark_list(); |
170 | void _bookmark_item_pressed(int p_idx); |
171 | |
172 | static void _code_complete_scripts(void *p_ud, const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force); |
173 | void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force); |
174 | |
175 | void _load_theme_settings(); |
176 | void _set_theme_for_script(); |
177 | void _show_errors_panel(bool p_show); |
178 | void _show_warnings_panel(bool p_show); |
179 | void _error_clicked(Variant p_line); |
180 | void _warning_clicked(Variant p_line); |
181 | |
182 | void _notification(int p_what); |
183 | |
184 | HashMap<String, Ref<EditorSyntaxHighlighter>> highlighters; |
185 | void _change_syntax_highlighter(int p_idx); |
186 | |
187 | void _edit_option(int p_op); |
188 | void (); |
189 | void (bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos); |
190 | void _text_edit_gui_input(const Ref<InputEvent> &ev); |
191 | void _color_changed(const Color &p_color); |
192 | void (); |
193 | |
194 | void _goto_line(int p_line) { goto_line(p_line); } |
195 | void _lookup_symbol(const String &p_symbol, int p_row, int p_column); |
196 | void _validate_symbol(const String &p_symbol); |
197 | |
198 | void _convert_case(CodeTextEditor::CaseStyle p_case); |
199 | |
200 | Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); |
201 | bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; |
202 | void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); |
203 | |
204 | String _get_absolute_path(const String &rel_path); |
205 | |
206 | public: |
207 | void _update_connected_methods(); |
208 | |
209 | virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override; |
210 | virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override; |
211 | void update_toggle_scripts_button() override; |
212 | |
213 | virtual void apply_code() override; |
214 | virtual Ref<Resource> get_edited_resource() const override; |
215 | virtual void set_edited_resource(const Ref<Resource> &p_res) override; |
216 | virtual void enable_editor(Control *p_shortcut_context = nullptr) override; |
217 | virtual Vector<String> get_functions() override; |
218 | virtual void reload_text() override; |
219 | virtual String get_name() override; |
220 | virtual Ref<Texture2D> get_theme_icon() override; |
221 | virtual bool is_unsaved() override; |
222 | virtual Variant get_edit_state() override; |
223 | virtual void set_edit_state(const Variant &p_state) override; |
224 | virtual Variant get_navigation_state() override; |
225 | virtual void ensure_focus() override; |
226 | virtual void trim_trailing_whitespace() override; |
227 | virtual void insert_final_newline() override; |
228 | virtual void convert_indent() override; |
229 | virtual void tag_saved_version() override; |
230 | |
231 | virtual void goto_line(int p_line, bool p_with_error = false) override; |
232 | void goto_line_selection(int p_line, int p_begin, int p_end); |
233 | void goto_line_centered(int p_line); |
234 | virtual void set_executing_line(int p_line) override; |
235 | virtual void clear_executing_line() override; |
236 | |
237 | virtual void reload(bool p_soft) override; |
238 | virtual PackedInt32Array get_breakpoints() override; |
239 | virtual void set_breakpoint(int p_line, bool p_enabled) override; |
240 | virtual void clear_breakpoints() override; |
241 | |
242 | virtual void add_callback(const String &p_function, PackedStringArray p_args) override; |
243 | virtual void update_settings() override; |
244 | |
245 | virtual bool show_members_overview() override; |
246 | |
247 | virtual void set_tooltip_request_func(const Callable &p_toolip_callback) override; |
248 | |
249 | virtual void set_debugger_active(bool p_active) override; |
250 | |
251 | Control *() override; |
252 | virtual void () override; |
253 | virtual void set_find_replace_bar(FindReplaceBar *p_bar) override; |
254 | |
255 | static void register_editor(); |
256 | |
257 | virtual Control *get_base_editor() const override; |
258 | |
259 | virtual void validate() override; |
260 | |
261 | ScriptTextEditor(); |
262 | ~ScriptTextEditor(); |
263 | }; |
264 | |
265 | #endif // SCRIPT_TEXT_EDITOR_H |
266 | |