| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/gui/box_container.h" |
| 34 |
#include "scene/gui/code_edit.h" |
| 35 |
#include "scene/gui/dialogs.h" |
| 36 |
|
| 37 |
class Button; |
| 38 |
class CheckBox; |
| 39 |
class CodeTextEditor; |
| 40 |
class Label; |
| 41 |
class LineEdit; |
| 42 |
class MenuButton; |
| 43 |
class RichTextLabel; |
| 44 |
class Timer; |
| 45 |
|
| 46 |
class GotoLinePopup : public PopupPanel { |
| 47 |
GDCLASS(GotoLinePopup, PopupPanel); |
| 48 |
|
| 49 |
Variant original_state; |
| 50 |
LineEdit *line_input = nullptr; |
| 51 |
CodeTextEditor *text_editor = nullptr; |
| 52 |
|
| 53 |
void _goto_line(); |
| 54 |
void _submit(); |
| 55 |
|
| 56 |
protected: |
| 57 |
void _notification(int p_what); |
| 58 |
virtual void _input_from_window(const Ref<InputEvent> &p_event) override; |
| 59 |
|
| 60 |
public: |
| 61 |
void popup_find_line(CodeTextEditor *p_text_editor); |
| 62 |
|
| 63 |
GotoLinePopup(); |
| 64 |
}; |
| 65 |
|
| 66 |
class FindReplaceBar : public HBoxContainer { |
| 67 |
GDCLASS(FindReplaceBar, HBoxContainer); |
| 68 |
|
| 69 |
enum SearchMode { |
| 70 |
SEARCH_CURRENT, |
| 71 |
SEARCH_NEXT, |
| 72 |
SEARCH_PREV, |
| 73 |
}; |
| 74 |
|
| 75 |
Button *toggle_replace_button = nullptr; |
| 76 |
LineEdit *search_text = nullptr; |
| 77 |
Label *matches_label = nullptr; |
| 78 |
Button *find_prev = nullptr; |
| 79 |
Button *find_next = nullptr; |
| 80 |
CheckBox *case_sensitive = nullptr; |
| 81 |
CheckBox *whole_words = nullptr; |
| 82 |
Button *hide_button = nullptr; |
| 83 |
|
| 84 |
LineEdit *replace_text = nullptr; |
| 85 |
Button *replace = nullptr; |
| 86 |
Button *replace_all = nullptr; |
| 87 |
CheckBox *selection_only = nullptr; |
| 88 |
|
| 89 |
HBoxContainer *hbc_button_replace = nullptr; |
| 90 |
HBoxContainer *hbc_option_replace = nullptr; |
| 91 |
|
| 92 |
CodeTextEditor *base_text_editor = nullptr; |
| 93 |
CodeEdit *text_editor = nullptr; |
| 94 |
|
| 95 |
uint32_t flags = 0; |
| 96 |
|
| 97 |
int result_line = 0; |
| 98 |
int result_col = 0; |
| 99 |
int results_count = -1; |
| 100 |
int results_count_to_current = -1; |
| 101 |
|
| 102 |
bool replace_all_mode = false; |
| 103 |
bool preserve_cursor = false; |
| 104 |
|
| 105 |
virtual void input(const Ref<InputEvent> &p_event) override; |
| 106 |
|
| 107 |
void _get_search_from(int &r_line, int &r_col, SearchMode p_search_mode); |
| 108 |
void _update_results_count(); |
| 109 |
void _update_matches_display(); |
| 110 |
|
| 111 |
void _show_search(bool p_with_replace, bool p_show_only); |
| 112 |
void _hide_bar(); |
| 113 |
void _update_toggle_replace_button(bool p_replace_visible); |
| 114 |
|
| 115 |
void _editor_text_changed(); |
| 116 |
void _search_options_changed(bool p_pressed); |
| 117 |
void _search_text_changed(const String &p_text); |
| 118 |
void _search_text_submitted(const String &p_text); |
| 119 |
void _replace_text_submitted(const String &p_text); |
| 120 |
void _toggle_replace_pressed(); |
| 121 |
|
| 122 |
protected: |
| 123 |
void _notification(int p_what); |
| 124 |
|
| 125 |
void _update_flags(bool p_direction_backwards); |
| 126 |
|
| 127 |
bool _search(uint32_t p_flags, int p_from_line, int p_from_col); |
| 128 |
|
| 129 |
void _replace(); |
| 130 |
void _replace_all(); |
| 131 |
|
| 132 |
static void _bind_methods(); |
| 133 |
|
| 134 |
public: |
| 135 |
String get_search_text() const; |
| 136 |
String get_replace_text() const; |
| 137 |
|
| 138 |
bool is_case_sensitive() const; |
| 139 |
bool is_whole_words() const; |
| 140 |
bool is_selection_only() const; |
| 141 |
|
| 142 |
void set_text_edit(CodeTextEditor *p_text_editor); |
| 143 |
|
| 144 |
void popup_search(bool p_show_only = false); |
| 145 |
void popup_replace(); |
| 146 |
|
| 147 |
bool search_current(); |
| 148 |
bool search_prev(); |
| 149 |
bool search_next(); |
| 150 |
|
| 151 |
bool needs_to_count_results = true; |
| 152 |
bool line_col_changed_for_result = false; |
| 153 |
|
| 154 |
FindReplaceBar(); |
| 155 |
}; |
| 156 |
|
| 157 |
typedef void (*CodeTextEditorCodeCompleteFunc)(void *p_ud, const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_forced); |
| 158 |
|
| 159 |
class CodeTextEditor : public VBoxContainer { |
| 160 |
GDCLASS(CodeTextEditor, VBoxContainer); |
| 161 |
|
| 162 |
CodeEdit *text_editor = nullptr; |
| 163 |
FindReplaceBar *find_replace_bar = nullptr; |
| 164 |
HBoxContainer *status_bar = nullptr; |
| 165 |
|
| 166 |
Button *toggle_files_button = nullptr; |
| 167 |
Control *toggle_files_list = nullptr; |
| 168 |
Button *error_button = nullptr; |
| 169 |
Button *warning_button = nullptr; |
| 170 |
|
| 171 |
MenuButton *zoom_button = nullptr; |
| 172 |
Label *line_and_col_txt = nullptr; |
| 173 |
Label *indentation_txt = nullptr; |
| 174 |
|
| 175 |
Timer *idle = nullptr; |
| 176 |
float idle_time = 0.0f; |
| 177 |
float idle_time_with_errors = 0.0f; |
| 178 |
bool code_complete_enabled = true; |
| 179 |
Timer *code_complete_timer = nullptr; |
| 180 |
int code_complete_timer_line = 0; |
| 181 |
|
| 182 |
float zoom_factor = 1.0f; |
| 183 |
|
| 184 |
RichTextLabel *error = nullptr; |
| 185 |
int error_line; |
| 186 |
int error_column; |
| 187 |
|
| 188 |
bool preview_navigation_change = false; |
| 189 |
Dictionary previous_state; |
| 190 |
|
| 191 |
void _update_text_editor_theme(); |
| 192 |
void _update_font_ligatures(); |
| 193 |
void _complete_request(); |
| 194 |
Ref<Texture2D> _get_completion_icon(const ScriptLanguage::CodeCompletionOption &p_option); |
| 195 |
|
| 196 |
virtual void input(const Ref<InputEvent> &event) override; |
| 197 |
void _text_editor_gui_input(const Ref<InputEvent> &p_event); |
| 198 |
|
| 199 |
Color completion_font_color; |
| 200 |
Color completion_string_color; |
| 201 |
Color completion_string_name_color; |
| 202 |
Color completion_node_path_color; |
| 203 |
Color completion_comment_color; |
| 204 |
Color completion_doc_comment_color; |
| 205 |
CodeTextEditorCodeCompleteFunc code_complete_func; |
| 206 |
void *code_complete_ud = nullptr; |
| 207 |
|
| 208 |
void _zoom_in(); |
| 209 |
void _zoom_out(); |
| 210 |
void _zoom_to(float p_zoom_factor); |
| 211 |
|
| 212 |
void _update_error_content_height(); |
| 213 |
|
| 214 |
void _error_button_pressed(); |
| 215 |
void _warning_button_pressed(); |
| 216 |
void _set_show_errors_panel(bool p_show); |
| 217 |
void _set_show_warnings_panel(bool p_show); |
| 218 |
void _error_pressed(const Ref<InputEvent> &p_event); |
| 219 |
|
| 220 |
void _zoom_popup_id_pressed(int p_idx); |
| 221 |
|
| 222 |
void _toggle_files_pressed(); |
| 223 |
|
| 224 |
protected: |
| 225 |
virtual void _load_theme_settings() {} |
| 226 |
virtual void _validate_script() {} |
| 227 |
virtual void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options) {} |
| 228 |
|
| 229 |
void _text_changed_idle_timeout(); |
| 230 |
void _code_complete_timer_timeout(); |
| 231 |
void _text_changed(); |
| 232 |
void _line_col_changed(); |
| 233 |
void _notification(int); |
| 234 |
static void _bind_methods(); |
| 235 |
|
| 236 |
bool is_warnings_panel_opened = false; |
| 237 |
bool is_errors_panel_opened = false; |
| 238 |
|
| 239 |
public: |
| 240 |
void trim_trailing_whitespace(); |
| 241 |
void trim_final_newlines(); |
| 242 |
void insert_final_newline(); |
| 243 |
|
| 244 |
enum CaseStyle { |
| 245 |
UPPER, |
| 246 |
LOWER, |
| 247 |
CAPITALIZE, |
| 248 |
}; |
| 249 |
void convert_case(CaseStyle p_case); |
| 250 |
|
| 251 |
void set_indent_using_spaces(bool p_use_spaces); |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
void toggle_inline_comment(const String &delimiter); |
| 256 |
|
| 257 |
void goto_line(int p_line, int p_column = 0); |
| 258 |
void goto_line_selection(int p_line, int p_begin, int p_end); |
| 259 |
void goto_line_centered(int p_line, int p_column = 0); |
| 260 |
void set_executing_line(int p_line); |
| 261 |
void clear_executing_line(); |
| 262 |
|
| 263 |
Variant get_edit_state(); |
| 264 |
void set_edit_state(const Variant &p_state); |
| 265 |
Variant get_navigation_state(); |
| 266 |
Variant get_previous_state(); |
| 267 |
void store_previous_state(); |
| 268 |
|
| 269 |
bool is_previewing_navigation_change() const; |
| 270 |
void set_preview_navigation_change(bool p_preview); |
| 271 |
|
| 272 |
void set_error_count(int p_error_count); |
| 273 |
void set_warning_count(int p_warning_count); |
| 274 |
|
| 275 |
void update_editor_settings(); |
| 276 |
void set_error(const String &p_error); |
| 277 |
void set_error_pos(int p_line, int p_column); |
| 278 |
Point2i get_error_pos() const; |
| 279 |
void update_line_and_column() { _line_col_changed(); } |
| 280 |
CodeEdit *get_text_editor() { return text_editor; } |
| 281 |
FindReplaceBar *get_find_replace_bar() { return find_replace_bar; } |
| 282 |
void set_find_replace_bar(FindReplaceBar *p_bar); |
| 283 |
void remove_find_replace_bar(); |
| 284 |
virtual void apply_code() {} |
| 285 |
virtual void goto_error(); |
| 286 |
|
| 287 |
void toggle_bookmark(); |
| 288 |
void goto_next_bookmark(); |
| 289 |
void goto_prev_bookmark(); |
| 290 |
void remove_all_bookmarks(); |
| 291 |
|
| 292 |
void set_zoom_factor(float p_zoom_factor); |
| 293 |
float get_zoom_factor(); |
| 294 |
|
| 295 |
void set_code_complete_func(CodeTextEditorCodeCompleteFunc p_code_complete_func, void *p_ud); |
| 296 |
|
| 297 |
void validate_script(); |
| 298 |
|
| 299 |
void set_toggle_list_control(Control *p_toggle_list_control); |
| 300 |
void show_toggle_files_button(); |
| 301 |
void update_toggle_files_button(); |
| 302 |
|
| 303 |
CodeTextEditor(); |
| 304 |
}; |