2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* code_editor.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef CODE_EDITOR_H
|
|
|
|
#define CODE_EDITOR_H
|
|
|
|
|
2022-02-14 14:00:03 +01:00
|
|
|
#include "scene/gui/box_container.h"
|
|
|
|
#include "scene/gui/button.h"
|
2016-05-28 18:25:45 +02:00
|
|
|
#include "scene/gui/check_box.h"
|
2020-07-24 16:50:35 +02:00
|
|
|
#include "scene/gui/code_edit.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/dialogs.h"
|
2022-02-14 14:00:03 +01:00
|
|
|
#include "scene/gui/label.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/gui/line_edit.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/main/timer.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2024-02-18 03:16:58 +01:00
|
|
|
class MenuButton;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
class GotoLineDialog : public ConfirmationDialog {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(GotoLineDialog, ConfirmationDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Label *line_label = nullptr;
|
|
|
|
LineEdit *line = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
CodeEdit *text_editor = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void ok_pressed() override;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2020-07-24 16:50:35 +02:00
|
|
|
void popup_find_line(CodeEdit *p_edit);
|
2014-02-10 02:10:30 +01:00
|
|
|
int get_line() const;
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
GotoLineDialog();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2021-06-03 01:05:41 +02:00
|
|
|
class CodeTextEditor;
|
|
|
|
|
2016-05-28 18:25:45 +02:00
|
|
|
class FindReplaceBar : public HBoxContainer {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(FindReplaceBar, HBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2024-06-27 20:04:40 +02:00
|
|
|
enum SearchMode {
|
|
|
|
SEARCH_CURRENT,
|
|
|
|
SEARCH_NEXT,
|
|
|
|
SEARCH_PREV,
|
|
|
|
};
|
|
|
|
|
2024-09-07 15:14:38 +02:00
|
|
|
Button *toggle_replace_button = nullptr;
|
2022-04-04 15:06:57 +02:00
|
|
|
LineEdit *search_text = nullptr;
|
|
|
|
Label *matches_label = nullptr;
|
|
|
|
Button *find_prev = nullptr;
|
|
|
|
Button *find_next = nullptr;
|
|
|
|
CheckBox *case_sensitive = nullptr;
|
|
|
|
CheckBox *whole_words = nullptr;
|
|
|
|
TextureButton *hide_button = nullptr;
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
LineEdit *replace_text = nullptr;
|
|
|
|
Button *replace = nullptr;
|
|
|
|
Button *replace_all = nullptr;
|
|
|
|
CheckBox *selection_only = nullptr;
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
VBoxContainer *vbc_lineedit = nullptr;
|
|
|
|
HBoxContainer *hbc_button_replace = nullptr;
|
|
|
|
HBoxContainer *hbc_option_replace = nullptr;
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2021-06-03 01:05:41 +02:00
|
|
|
CodeTextEditor *base_text_editor = nullptr;
|
2022-04-04 15:06:57 +02:00
|
|
|
CodeEdit *text_editor = nullptr;
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2022-04-27 14:21:28 +02:00
|
|
|
uint32_t flags = 0;
|
|
|
|
|
2022-05-02 16:28:25 +02:00
|
|
|
int result_line = 0;
|
|
|
|
int result_col = 0;
|
|
|
|
int results_count = -1;
|
|
|
|
int results_count_to_current = -1;
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2022-02-15 15:56:58 +01:00
|
|
|
bool replace_all_mode = false;
|
|
|
|
bool preserve_cursor = false;
|
2016-05-30 18:15:41 +02:00
|
|
|
|
2024-06-27 20:04:40 +02:00
|
|
|
void _get_search_from(int &r_line, int &r_col, SearchMode p_search_mode);
|
2019-07-08 19:33:04 +02:00
|
|
|
void _update_results_count();
|
2023-11-15 11:10:59 +01:00
|
|
|
void _update_matches_display();
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2023-11-15 11:10:59 +01:00
|
|
|
void _show_search(bool p_with_replace, bool p_show_only);
|
2023-10-14 16:16:13 +02:00
|
|
|
void _hide_bar(bool p_force_focus = false);
|
2024-09-07 15:14:38 +02:00
|
|
|
void _update_toggle_replace_button(bool p_replace_visible);
|
2016-05-30 18:15:41 +02:00
|
|
|
|
|
|
|
void _editor_text_changed();
|
2016-05-28 18:25:45 +02:00
|
|
|
void _search_options_changed(bool p_pressed);
|
2017-03-05 16:44:50 +01:00
|
|
|
void _search_text_changed(const String &p_text);
|
2021-06-16 18:43:34 +02:00
|
|
|
void _search_text_submitted(const String &p_text);
|
|
|
|
void _replace_text_submitted(const String &p_text);
|
2024-09-07 15:14:38 +02:00
|
|
|
void _toggle_replace_pressed();
|
2016-05-28 18:25:45 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
2021-08-22 17:37:22 +02:00
|
|
|
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
|
2023-10-14 16:16:13 +02:00
|
|
|
void _focus_lost();
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2023-10-03 03:44:54 +02:00
|
|
|
void _update_flags(bool p_direction_backwards);
|
|
|
|
|
2016-05-30 18:15:41 +02:00
|
|
|
bool _search(uint32_t p_flags, int p_from_line, int p_from_col);
|
2016-05-28 18:25:45 +02:00
|
|
|
|
|
|
|
void _replace();
|
|
|
|
void _replace_all();
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
String get_search_text() const;
|
|
|
|
String get_replace_text() const;
|
|
|
|
|
|
|
|
bool is_case_sensitive() const;
|
|
|
|
bool is_whole_words() const;
|
|
|
|
bool is_selection_only() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_error(const String &p_label);
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2021-06-03 01:05:41 +02:00
|
|
|
void set_text_edit(CodeTextEditor *p_text_editor);
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2019-08-12 20:31:53 +02:00
|
|
|
void popup_search(bool p_show_only = false);
|
2016-05-28 18:25:45 +02:00
|
|
|
void popup_replace();
|
|
|
|
|
2016-05-30 18:15:41 +02:00
|
|
|
bool search_current();
|
|
|
|
bool search_prev();
|
|
|
|
bool search_next();
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2022-04-27 14:21:28 +02:00
|
|
|
bool needs_to_count_results = true;
|
|
|
|
bool line_col_changed_for_result = false;
|
|
|
|
|
2016-05-28 18:25:45 +02:00
|
|
|
FindReplaceBar();
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-26 16:48:43 +01:00
|
|
|
typedef void (*CodeTextEditorCodeCompleteFunc)(void *p_ud, const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_forced);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2016-05-28 18:25:45 +02:00
|
|
|
class CodeTextEditor : public VBoxContainer {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(CodeTextEditor, VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
CodeEdit *text_editor = nullptr;
|
2021-06-03 01:05:41 +02:00
|
|
|
FindReplaceBar *find_replace_bar = nullptr;
|
2022-04-04 15:06:57 +02:00
|
|
|
HBoxContainer *status_bar = nullptr;
|
2019-02-01 17:20:59 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Button *toggle_scripts_button = nullptr;
|
2022-07-31 23:07:10 +02:00
|
|
|
Control *toggle_scripts_list = nullptr;
|
2022-04-04 15:06:57 +02:00
|
|
|
Button *error_button = nullptr;
|
|
|
|
Button *warning_button = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2024-02-18 03:16:58 +01:00
|
|
|
MenuButton *zoom_button = nullptr;
|
2022-04-04 15:06:57 +02:00
|
|
|
Label *line_and_col_txt = nullptr;
|
2024-02-18 03:16:58 +01:00
|
|
|
Label *indentation_txt = nullptr;
|
2019-02-01 17:20:59 +01:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Label *info = nullptr;
|
|
|
|
Timer *idle = nullptr;
|
2022-11-01 20:03:43 +01:00
|
|
|
bool code_complete_enabled = true;
|
2022-04-04 15:06:57 +02:00
|
|
|
Timer *code_complete_timer = nullptr;
|
2022-12-06 10:23:11 +01:00
|
|
|
int code_complete_timer_line = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2024-02-18 03:16:58 +01:00
|
|
|
float zoom_factor = 1.0f;
|
2016-06-17 21:58:50 +02:00
|
|
|
|
2022-04-04 15:06:57 +02:00
|
|
|
Label *error = nullptr;
|
2018-11-21 11:56:02 +01:00
|
|
|
int error_line;
|
|
|
|
int error_column;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-10-22 23:54:37 +02:00
|
|
|
Dictionary previous_state;
|
|
|
|
|
2020-09-10 22:25:00 +02:00
|
|
|
void _update_text_editor_theme();
|
2024-02-18 03:16:58 +01:00
|
|
|
void _update_font_ligatures();
|
2014-12-17 02:31:57 +01:00
|
|
|
void _complete_request();
|
2022-03-26 16:48:43 +01:00
|
|
|
Ref<Texture2D> _get_completion_icon(const ScriptLanguage::CodeCompletionOption &p_option);
|
2016-06-17 21:58:50 +02:00
|
|
|
|
2021-08-22 17:37:22 +02:00
|
|
|
virtual void input(const Ref<InputEvent> &event) override;
|
2017-05-20 17:38:03 +02:00
|
|
|
void _text_editor_gui_input(const Ref<InputEvent> &p_event);
|
2016-06-17 21:58:50 +02:00
|
|
|
|
2020-05-03 18:08:15 +02:00
|
|
|
Color completion_font_color;
|
|
|
|
Color completion_string_color;
|
2022-10-06 22:08:01 +02:00
|
|
|
Color completion_string_name_color;
|
|
|
|
Color completion_node_path_color;
|
2020-05-03 18:08:15 +02:00
|
|
|
Color completion_comment_color;
|
2023-02-05 10:01:01 +01:00
|
|
|
Color completion_doc_comment_color;
|
2016-08-03 00:11:05 +02:00
|
|
|
CodeTextEditorCodeCompleteFunc code_complete_func;
|
2022-04-04 15:06:57 +02:00
|
|
|
void *code_complete_ud = nullptr;
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2024-02-18 03:16:58 +01:00
|
|
|
void _zoom_in();
|
|
|
|
void _zoom_out();
|
|
|
|
void _zoom_to(float p_zoom_factor);
|
|
|
|
|
2021-05-18 05:09:19 +02:00
|
|
|
void _error_button_pressed();
|
2019-02-01 17:20:59 +01:00
|
|
|
void _warning_button_pressed();
|
2021-05-18 05:09:19 +02:00
|
|
|
void _set_show_errors_panel(bool p_show);
|
2019-02-13 10:12:31 +01:00
|
|
|
void _set_show_warnings_panel(bool p_show);
|
2019-02-01 17:20:59 +01:00
|
|
|
void _error_pressed(const Ref<InputEvent> &p_event);
|
|
|
|
|
2024-02-18 03:16:58 +01:00
|
|
|
void _zoom_popup_id_pressed(int p_idx);
|
2022-02-16 00:52:32 +01:00
|
|
|
|
2019-12-15 14:35:16 +01:00
|
|
|
void _toggle_scripts_pressed();
|
2019-12-09 07:29:24 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
|
|
|
virtual void _load_theme_settings() {}
|
2016-08-03 00:11:05 +02:00
|
|
|
virtual void _validate_script() {}
|
2022-03-26 16:48:43 +01:00
|
|
|
virtual void _code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options) {}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void _text_changed_idle_timeout();
|
2014-05-04 05:22:49 +02:00
|
|
|
void _code_complete_timer_timeout();
|
2014-02-10 02:10:30 +01:00
|
|
|
void _text_changed();
|
|
|
|
void _line_col_changed();
|
|
|
|
void _notification(int);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-02-15 15:56:58 +01:00
|
|
|
bool is_warnings_panel_opened = false;
|
|
|
|
bool is_errors_panel_opened = false;
|
2019-02-13 10:12:31 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
2018-05-26 00:49:35 +02:00
|
|
|
void trim_trailing_whitespace();
|
2024-01-12 06:32:13 +01:00
|
|
|
void trim_final_newlines();
|
2019-05-28 23:27:32 +02:00
|
|
|
void insert_final_newline();
|
2018-05-26 00:49:35 +02:00
|
|
|
|
|
|
|
enum CaseStyle {
|
|
|
|
UPPER,
|
|
|
|
LOWER,
|
|
|
|
CAPITALIZE,
|
|
|
|
};
|
|
|
|
void convert_case(CaseStyle p_case);
|
|
|
|
|
2024-02-18 03:16:58 +01:00
|
|
|
void set_indent_using_spaces(bool p_use_spaces);
|
|
|
|
|
2019-02-04 20:17:44 +01:00
|
|
|
/// Toggle inline comment on currently selected lines, or on current line if nothing is selected,
|
|
|
|
/// by adding or removing comment delimiter
|
|
|
|
void toggle_inline_comment(const String &delimiter);
|
|
|
|
|
2024-07-06 01:27:19 +02:00
|
|
|
void goto_line(int p_line, int p_column = 0);
|
2018-05-26 00:49:35 +02:00
|
|
|
void goto_line_selection(int p_line, int p_begin, int p_end);
|
2024-07-06 01:27:19 +02:00
|
|
|
void goto_line_centered(int p_line, int p_column = 0);
|
2019-04-22 18:20:27 +02:00
|
|
|
void set_executing_line(int p_line);
|
|
|
|
void clear_executing_line();
|
2018-05-26 00:49:35 +02:00
|
|
|
|
|
|
|
Variant get_edit_state();
|
|
|
|
void set_edit_state(const Variant &p_state);
|
2022-09-23 14:46:28 +02:00
|
|
|
Variant get_navigation_state();
|
2022-10-22 23:54:37 +02:00
|
|
|
Variant get_previous_state();
|
|
|
|
void store_previous_state();
|
2018-05-26 00:49:35 +02:00
|
|
|
|
2021-05-18 05:09:19 +02:00
|
|
|
void set_error_count(int p_error_count);
|
|
|
|
void set_warning_count(int p_warning_count);
|
2019-02-01 17:20:59 +01:00
|
|
|
|
2016-10-10 10:38:12 +02:00
|
|
|
void update_editor_settings();
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_error(const String &p_error);
|
2018-11-21 11:56:02 +01:00
|
|
|
void set_error_pos(int p_line, int p_column);
|
2022-03-08 11:39:16 +01:00
|
|
|
Point2i get_error_pos() const;
|
2016-08-03 00:11:05 +02:00
|
|
|
void update_line_and_column() { _line_col_changed(); }
|
2020-07-24 16:50:35 +02:00
|
|
|
CodeEdit *get_text_editor() { return text_editor; }
|
2016-05-28 18:25:45 +02:00
|
|
|
FindReplaceBar *get_find_replace_bar() { return find_replace_bar; }
|
2021-06-03 01:05:41 +02:00
|
|
|
void set_find_replace_bar(FindReplaceBar *p_bar);
|
|
|
|
void remove_find_replace_bar();
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void apply_code() {}
|
2022-03-08 11:39:16 +01:00
|
|
|
virtual void goto_error();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-04-20 01:51:25 +02:00
|
|
|
void toggle_bookmark();
|
|
|
|
void goto_next_bookmark();
|
|
|
|
void goto_prev_bookmark();
|
|
|
|
void remove_all_bookmarks();
|
|
|
|
|
2024-02-18 03:16:58 +01:00
|
|
|
void set_zoom_factor(float p_zoom_factor);
|
|
|
|
float get_zoom_factor();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_code_complete_func(CodeTextEditorCodeCompleteFunc p_code_complete_func, void *p_ud);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2019-05-08 18:49:49 +02:00
|
|
|
void validate_script();
|
|
|
|
|
2022-07-31 23:07:10 +02:00
|
|
|
void set_toggle_list_control(Control *p_control);
|
2019-12-17 09:16:17 +01:00
|
|
|
void show_toggle_scripts_button();
|
2019-12-17 14:51:49 +01:00
|
|
|
void update_toggle_scripts_button();
|
2019-12-17 09:16:17 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
CodeTextEditor();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CODE_EDITOR_H
|