Debian Codegraph @

editor/script/script_text_editor.h

raw symbols SCIP
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 #pragma once
32
33 #include "script_editor_plugin.h"
34
35 #include "editor/gui/code_editor.h"
36 #include "scene/gui/color_picker.h"
37 #include "scene/gui/dialogs.h"
38 #include "scene/gui/option_button.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 popup_connections(const String &p_method, const 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 Variant pending_state;
66 bool script_is_valid = false;
67 bool editor_enabled = false;
68
69 Vector<String> functions;
70 List<ScriptLanguage::Warning> warnings;
71 List<ScriptLanguage::ScriptError> errors;
72 HashMap<String, List<ScriptLanguage::ScriptError>> depended_errors;
73 HashSet<int> safe_lines;
74
75 List<Connection> missing_connections;
76
77 HBoxContainer *edit_hb = nullptr;
78
79 MenuButton *edit_menu = nullptr;
80 MenuButton *search_menu = nullptr;
81 MenuButton *goto_menu = nullptr;
82 PopupMenu *bookmarks_menu = nullptr;
83 PopupMenu *breakpoints_menu = nullptr;
84 PopupMenu *highlighter_menu = nullptr;
85 PopupMenu *context_menu = nullptr;
86
87 int inline_color_line = -1;
88 int inline_color_start = -1;
89 int inline_color_end = -1;
90 PopupPanel *inline_color_popup = nullptr;
91 ColorPicker *inline_color_picker = nullptr;
92 OptionButton *inline_color_options = nullptr;
93 Ref<Texture2D> color_alpha_texture;
94
95 GotoLinePopup *goto_line_popup = nullptr;
96 ScriptEditorQuickOpen *quick_open = nullptr;
97 ConnectionInfoDialog *connection_info_dialog = nullptr;
98
99 int connection_gutter = -1;
100 void _gutter_clicked(int p_line, int p_gutter);
101 void _update_gutter_indexes();
102
103 int line_number_gutter = -1;
104 Color default_line_number_color = Color(1, 1, 1);
105 Color safe_line_number_color = Color(1, 1, 1);
106
107 Color marked_line_color = Color(1, 1, 1);
108 Color warning_line_color = Color(1, 1, 1);
109 Color folded_code_region_color = Color(1, 1, 1);
110 int previous_line = 0;
111
112 PopupPanel *color_panel = nullptr;
113 ColorPicker *color_picker = nullptr;
114 Vector3i color_position;
115 String color_args;
116
117 bool theme_loaded = false;
118
119 enum {
120 EDIT_UNDO,
121 EDIT_REDO,
122 EDIT_CUT,
123 EDIT_COPY,
124 EDIT_PASTE,
125 EDIT_SELECT_ALL,
126 EDIT_COMPLETE,
127 EDIT_AUTO_INDENT,
128 EDIT_TRIM_TRAILING_WHITESAPCE,
129 EDIT_TRIM_FINAL_NEWLINES,
130 EDIT_CONVERT_INDENT_TO_SPACES,
131 EDIT_CONVERT_INDENT_TO_TABS,
132 EDIT_TOGGLE_COMMENT,
133 EDIT_MOVE_LINE_UP,
134 EDIT_MOVE_LINE_DOWN,
135 EDIT_INDENT,
136 EDIT_UNINDENT,
137 EDIT_DELETE_LINE,
138 EDIT_DUPLICATE_SELECTION,
139 EDIT_DUPLICATE_LINES,
140 EDIT_PICK_COLOR,
141 EDIT_TO_UPPERCASE,
142 EDIT_TO_LOWERCASE,
143 EDIT_CAPITALIZE,
144 EDIT_EVALUATE,
145 EDIT_TOGGLE_WORD_WRAP,
146 EDIT_TOGGLE_FOLD_LINE,
147 EDIT_FOLD_ALL_LINES,
148 EDIT_CREATE_CODE_REGION,
149 EDIT_UNFOLD_ALL_LINES,
150 SEARCH_FIND,
151 SEARCH_FIND_NEXT,
152 SEARCH_FIND_PREV,
153 SEARCH_REPLACE,
154 SEARCH_LOCATE_FUNCTION,
155 SEARCH_GOTO_LINE,
156 SEARCH_IN_FILES,
157 REPLACE_IN_FILES,
158 BOOKMARK_TOGGLE,
159 BOOKMARK_GOTO_NEXT,
160 BOOKMARK_GOTO_PREV,
161 BOOKMARK_REMOVE_ALL,
162 DEBUG_TOGGLE_BREAKPOINT,
163 DEBUG_REMOVE_ALL_BREAKPOINTS,
164 DEBUG_GOTO_NEXT_BREAKPOINT,
165 DEBUG_GOTO_PREV_BREAKPOINT,
166 HELP_CONTEXTUAL,
167 LOOKUP_SYMBOL,
168 EDIT_EMOJI_AND_SYMBOL,
169 };
170
171 enum COLOR_MODE {
172 MODE_RGB,
173 MODE_STRING,
174 MODE_HSV,
175 MODE_OKHSL,
176 MODE_RGB8,
177 MODE_HEX,
178 MODE_MAX
179 };
180
181 void _enable_code_editor();
182
183 struct DraggedExport {
184 ObjectID obj_id;
185 String variable_name;
186 Variant value;
187 String class_name;
188 };
189
190 LocalVector<DraggedExport> pending_dragged_exports;
191 Vector<ObjectID> _get_objects_for_export_assignment() const;
192 String _get_dropped_resource_as_exported_member(const Ref<Resource> &p_resource, const Vector<ObjectID> &p_script_instance_obj_ids);
193 void _assign_dragged_export_variables();
194
195 protected:
196 void _update_breakpoint_list();
197 void _breakpoint_item_pressed(int p_idx);
198 void _breakpoint_toggled(int p_row);
199
200 void _on_caret_moved();
201
202 void _validate_script(); // No longer virtual.
203 void _update_warnings();
204 void _update_errors();
205 void _update_bookmark_list();
206 void _bookmark_item_pressed(int p_idx);
207
208 static void _code_complete_scripts(void *p_ud, const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force);
209 void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force);
210
211 void _load_theme_settings();
212 void _set_theme_for_script();
213 void _show_errors_panel(bool p_show);
214 void _show_warnings_panel(bool p_show);
215 void _error_clicked(const Variant &p_line);
216 void _warning_clicked(const Variant &p_line);
217
218 bool _is_valid_color_info(const Dictionary &p_info);
219 Array _inline_object_parse(const String &p_text);
220 void _inline_object_draw(const Dictionary &p_info, const Rect2 &p_rect);
221 void _inline_object_handle_click(const Dictionary &p_info, const Rect2 &p_rect);
222 String _picker_color_stringify(const Color &p_color, COLOR_MODE p_mode);
223 void _picker_color_changed(const Color &p_color);
224 void _update_color_constructor_options();
225 void _update_background_color();
226 void _update_color_text();
227
228 void _notification(int p_what);
229
230 HashMap<String, Ref<EditorSyntaxHighlighter>> highlighters;
231 void _change_syntax_highlighter(int p_idx);
232
233 void _edit_option(int p_op);
234 void _edit_option_toggle_inline_comment();
235 void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos);
236 void _text_edit_gui_input(const Ref<InputEvent> &ev);
237 void _color_changed(const Color &p_color);
238 void _prepare_edit_menu();
239
240 void _goto_line(int p_line) { goto_line(p_line); }
241 void _lookup_symbol(const String &p_symbol, int p_row, int p_column);
242 void _validate_symbol(const String &p_symbol);
243
244 void _show_symbol_tooltip(const String &p_symbol, int p_row, int p_column);
245
246 void _convert_case(CodeTextEditor::CaseStyle p_case);
247
248 Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
249 bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
250 void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
251
252 String _get_absolute_path(const String &rel_path);
253
254 public:
255 void _update_connected_methods();
256
257 virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
258 virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
259 void update_toggle_files_button() override;
260
261 virtual void apply_code() override;
262 virtual Ref<Resource> get_edited_resource() const override;
263 virtual void set_edited_resource(const Ref<Resource> &p_res) override;
264 virtual void enable_editor(Control *p_shortcut_context = nullptr) override;
265 virtual Vector<String> get_functions() override;
266 virtual void reload_text() override;
267 virtual String get_name() override;
268 virtual Ref<Texture2D> get_theme_icon() override;
269 virtual bool is_unsaved() override;
270 virtual Variant get_edit_state() override;
271 virtual void set_edit_state(const Variant &p_state) override;
272 virtual Variant get_navigation_state() override;
273 virtual void ensure_focus() override;
274 virtual void trim_trailing_whitespace() override;
275 virtual void trim_final_newlines() override;
276 virtual void insert_final_newline() override;
277 virtual void convert_indent() override;
278 virtual void tag_saved_version() override;
279
280 virtual void goto_line(int p_line, int p_column = 0) override;
281 void goto_line_selection(int p_line, int p_begin, int p_end);
282 void goto_line_centered(int p_line, int p_column = 0);
283 virtual void set_executing_line(int p_line) override;
284 virtual void clear_executing_line() override;
285
286 virtual void reload(bool p_soft) override;
287 virtual PackedInt32Array get_breakpoints() override;
288 virtual void set_breakpoint(int p_line, bool p_enabled) override;
289 virtual void clear_breakpoints() override;
290
291 virtual void add_callback(const String &p_function, const PackedStringArray &p_args) override;
292 virtual void update_settings() override;
293
294 virtual bool show_members_overview() override;
295
296 virtual void set_tooltip_request_func(const Callable &p_toolip_callback) override;
297
298 virtual void set_debugger_active(bool p_active) override;
299
300 Control *get_edit_menu() override;
301 virtual void clear_edit_menu() override;
302 virtual void set_find_replace_bar(FindReplaceBar *p_bar) override;
303
304 static void register_editor();
305
306 virtual Control *get_base_editor() const override;
307 virtual CodeTextEditor *get_code_editor() const override;
308
309 virtual void validate() override;
310
311 Variant get_previous_state();
312 void store_previous_state();
313
314 ScriptTextEditor();
315 ~ScriptTextEditor();
316 };