Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/script/script_text_editor.h
20854 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 "editor/script/script_editor_base.h"
34
#include "script_editor_plugin.h"
35
36
#include "editor/gui/code_editor.h"
37
#include "scene/gui/color_picker.h"
38
#include "scene/gui/dialogs.h"
39
#include "scene/gui/option_button.h"
40
#include "scene/gui/tree.h"
41
42
class RichTextLabel;
43
44
class ConnectionInfoDialog : public AcceptDialog {
45
GDCLASS(ConnectionInfoDialog, AcceptDialog);
46
47
Label *method = nullptr;
48
Tree *tree = nullptr;
49
50
virtual void ok_pressed() override;
51
52
public:
53
void popup_connections(const String &p_method, const Vector<Node *> &p_nodes);
54
55
ConnectionInfoDialog();
56
};
57
58
class ScriptTextEditor : public CodeEditorBase {
59
GDCLASS(ScriptTextEditor, CodeEditorBase);
60
61
Variant pending_state;
62
bool script_is_valid = false;
63
64
RichTextLabel *errors_panel = nullptr;
65
66
Vector<String> functions;
67
List<ScriptLanguage::Warning> warnings;
68
List<ScriptLanguage::ScriptError> errors;
69
HashMap<String, List<ScriptLanguage::ScriptError>> depended_errors;
70
HashSet<int> safe_lines;
71
72
List<Connection> missing_connections;
73
74
int inline_color_line = -1;
75
int inline_color_start = -1;
76
int inline_color_end = -1;
77
PopupPanel *inline_color_popup = nullptr;
78
ColorPicker *inline_color_picker = nullptr;
79
OptionButton *inline_color_options = nullptr;
80
Ref<Texture2D> color_alpha_texture;
81
82
ScriptEditorQuickOpen *quick_open = nullptr;
83
ConnectionInfoDialog *connection_info_dialog = nullptr;
84
85
int connection_gutter = -1;
86
void _gutter_clicked(int p_line, int p_gutter);
87
void _update_gutter_indexes();
88
89
int line_number_gutter = -1;
90
Color default_line_number_color = Color(1, 1, 1);
91
Color safe_line_number_color = Color(1, 1, 1);
92
93
Color marked_line_color = Color(1, 1, 1);
94
Color warning_line_color = Color(1, 1, 1);
95
Color folded_code_region_color = Color(1, 1, 1);
96
int previous_line = 0;
97
98
PopupPanel *color_panel = nullptr;
99
ColorPicker *color_picker = nullptr;
100
Vector3i color_position;
101
String color_args;
102
103
bool theme_loaded = false;
104
105
enum {
106
EDIT_AUTO_INDENT = CODE_ENUM_COUNT,
107
EDIT_PICK_COLOR,
108
EDIT_EVALUATE,
109
EDIT_CREATE_CODE_REGION,
110
111
SEARCH_LOCATE_FUNCTION,
112
113
DEBUG_TOGGLE_BREAKPOINT,
114
DEBUG_REMOVE_ALL_BREAKPOINTS,
115
DEBUG_GOTO_NEXT_BREAKPOINT,
116
DEBUG_GOTO_PREV_BREAKPOINT,
117
118
HELP_CONTEXTUAL,
119
LOOKUP_SYMBOL,
120
};
121
122
enum COLOR_MODE {
123
MODE_RGB,
124
MODE_STRING,
125
MODE_HSV,
126
MODE_OKHSL,
127
MODE_RGB8,
128
MODE_HEX,
129
MODE_MAX
130
};
131
132
class EditMenusSTE : public EditMenusCEB {
133
GDCLASS(EditMenusSTE, EditMenusCEB);
134
PopupMenu *breakpoints_menu = nullptr;
135
136
void _update_breakpoint_list();
137
void _breakpoint_item_pressed(int p_idx);
138
139
public:
140
EditMenusSTE();
141
};
142
143
void _enable_code_editor();
144
145
struct DraggedExport {
146
ObjectID obj_id;
147
String variable_name;
148
Variant value;
149
String class_name;
150
};
151
152
LocalVector<DraggedExport> pending_dragged_exports;
153
Vector<ObjectID> _get_objects_for_export_assignment() const;
154
String _get_dropped_resource_as_exported_member(const Ref<Resource> &p_resource, const Vector<ObjectID> &p_script_instance_obj_ids);
155
void _assign_dragged_export_variables();
156
157
static ScriptEditorBase *create_editor(const Ref<Resource> &p_resource);
158
159
protected:
160
void _breakpoint_toggled(int p_row);
161
162
void _on_caret_moved();
163
164
void _update_warnings();
165
void _update_errors();
166
167
static void _code_complete_scripts(void *p_ud, const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force);
168
virtual void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force) override;
169
170
void _set_theme_for_script();
171
void _show_errors_panel(bool p_show);
172
void _show_warnings_panel(bool p_show);
173
void _error_clicked(const Variant &p_line);
174
virtual bool _warning_clicked(const Variant &p_line) override;
175
176
bool _is_valid_color_info(const Dictionary &p_info);
177
Array _inline_object_parse(const String &p_text);
178
void _inline_object_draw(const Dictionary &p_info, const Rect2 &p_rect);
179
void _inline_object_handle_click(const Dictionary &p_info, const Rect2 &p_rect);
180
String _picker_color_stringify(const Color &p_color, COLOR_MODE p_mode);
181
void _picker_color_changed(const Color &p_color);
182
void _update_color_constructor_options();
183
void _update_background_color();
184
void _update_color_text();
185
186
void _notification(int p_what);
187
188
void _edit_option_toggle_inline_comment();
189
void _color_changed(const Color &p_color);
190
191
void _lookup_symbol(const String &p_symbol, int p_row, int p_column);
192
void _validate_symbol(const String &p_symbol);
193
194
void _show_symbol_tooltip(const String &p_symbol, int p_row, int p_column);
195
196
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
197
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
198
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
199
200
String _get_absolute_path(const String &rel_path);
201
202
void _goto_line(int p_line) { goto_line(p_line); }
203
204
void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, const Vector2 &p_pos);
205
206
virtual void _text_edit_gui_input(const Ref<InputEvent> &p_ev) override;
207
virtual bool _edit_option(int p_op) override;
208
209
virtual void _load_theme_settings() override;
210
virtual void _validate_script() override;
211
212
public:
213
void _update_connected_methods();
214
215
virtual void apply_code() override;
216
virtual void set_edited_resource(const Ref<Resource> &p_res) override;
217
virtual void enable_editor() override;
218
virtual Vector<String> get_functions() override;
219
220
virtual Control *get_edit_menu() override;
221
222
virtual Ref<Texture2D> get_theme_icon() override;
223
224
virtual Variant get_edit_state() override;
225
virtual void set_edit_state(const Variant &p_state) override;
226
227
virtual PackedInt32Array get_breakpoints() override;
228
virtual void set_breakpoint(int p_line, bool p_enabled) override;
229
virtual void clear_breakpoints() override;
230
231
virtual void add_callback(const String &p_function, const PackedStringArray &p_args);
232
virtual void update_settings() override;
233
234
static void register_editor();
235
236
Variant get_previous_state();
237
void store_previous_state();
238
239
ScriptTextEditor();
240
~ScriptTextEditor();
241
};
242
243