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