2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* code_editor.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
2020-01-01 18:16:22 +08:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 09:10:30 +08:00
|
|
|
/* */
|
|
|
|
/* 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 07:50:27 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
#ifndef CODE_EDITOR_H
|
|
|
|
#define CODE_EDITOR_H
|
|
|
|
|
2017-03-05 21:21:25 +08:00
|
|
|
#include "editor/editor_plugin.h"
|
2016-05-29 00:25:45 +08:00
|
|
|
#include "scene/gui/check_box.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "scene/gui/check_button.h"
|
|
|
|
#include "scene/gui/dialogs.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
#include "scene/gui/line_edit.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "scene/gui/text_edit.h"
|
|
|
|
#include "scene/main/timer.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
class GotoLineDialog : public ConfirmationDialog {
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(GotoLineDialog, ConfirmationDialog);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
Label *line_label;
|
|
|
|
LineEdit *line;
|
|
|
|
|
|
|
|
TextEdit *text_editor;
|
|
|
|
|
2020-07-10 18:34:39 +08:00
|
|
|
virtual void ok_pressed() override;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
public:
|
2014-02-10 09:10:30 +08:00
|
|
|
void popup_find_line(TextEdit *p_edit);
|
|
|
|
int get_line() const;
|
|
|
|
|
|
|
|
void set_text_editor(TextEdit *p_text_editor);
|
2016-03-09 07:00:52 +08:00
|
|
|
GotoLineDialog();
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
2016-05-29 00:25:45 +08:00
|
|
|
class FindReplaceBar : public HBoxContainer {
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(FindReplaceBar, HBoxContainer);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-29 00:25:45 +08:00
|
|
|
LineEdit *search_text;
|
2019-08-09 14:47:09 +08:00
|
|
|
Label *matches_label;
|
2020-06-20 02:49:04 +08:00
|
|
|
Button *find_prev;
|
|
|
|
Button *find_next;
|
2016-05-29 00:25:45 +08:00
|
|
|
CheckBox *case_sensitive;
|
|
|
|
CheckBox *whole_words;
|
|
|
|
TextureButton *hide_button;
|
|
|
|
|
|
|
|
LineEdit *replace_text;
|
2016-09-11 21:01:52 +08:00
|
|
|
Button *replace;
|
|
|
|
Button *replace_all;
|
2016-05-29 00:25:45 +08:00
|
|
|
CheckBox *selection_only;
|
|
|
|
|
2018-01-18 07:52:17 +08:00
|
|
|
VBoxContainer *vbc_lineedit;
|
|
|
|
HBoxContainer *hbc_button_replace;
|
|
|
|
HBoxContainer *hbc_option_replace;
|
2016-05-29 00:25:45 +08:00
|
|
|
|
|
|
|
TextEdit *text_edit;
|
|
|
|
|
2016-05-31 00:15:41 +08:00
|
|
|
int result_line;
|
|
|
|
int result_col;
|
2019-07-09 01:33:04 +08:00
|
|
|
int results_count;
|
2016-05-29 00:25:45 +08:00
|
|
|
|
|
|
|
bool replace_all_mode;
|
2016-05-31 00:15:41 +08:00
|
|
|
bool preserve_cursor;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void _get_search_from(int &r_line, int &r_col);
|
2019-07-09 01:33:04 +08:00
|
|
|
void _update_results_count();
|
2019-08-09 14:47:09 +08:00
|
|
|
void _update_matches_label();
|
2016-05-29 00:25:45 +08:00
|
|
|
|
2019-08-13 02:31:53 +08:00
|
|
|
void _show_search(bool p_focus_replace = false, bool p_show_only = false);
|
2016-05-29 00:25:45 +08:00
|
|
|
void _hide_bar();
|
2016-05-31 00:15:41 +08:00
|
|
|
|
|
|
|
void _editor_text_changed();
|
2016-05-29 00:25:45 +08:00
|
|
|
void _search_options_changed(bool p_pressed);
|
2017-03-05 23:44:50 +08:00
|
|
|
void _search_text_changed(const String &p_text);
|
|
|
|
void _search_text_entered(const String &p_text);
|
|
|
|
void _replace_text_entered(const String &p_text);
|
2018-01-18 07:52:17 +08:00
|
|
|
void _update_size();
|
2016-05-29 00:25:45 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
2017-05-20 23:38:03 +08:00
|
|
|
void _unhandled_input(const Ref<InputEvent> &p_event);
|
2016-05-29 00:25:45 +08:00
|
|
|
|
2016-05-31 00:15:41 +08:00
|
|
|
bool _search(uint32_t p_flags, int p_from_line, int p_from_col);
|
2016-05-29 00:25:45 +08: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 23:44:50 +08:00
|
|
|
void set_error(const String &p_label);
|
2016-05-29 00:25:45 +08:00
|
|
|
|
|
|
|
void set_text_edit(TextEdit *p_text_edit);
|
|
|
|
|
2019-08-13 02:31:53 +08:00
|
|
|
void popup_search(bool p_show_only = false);
|
2016-05-29 00:25:45 +08:00
|
|
|
void popup_replace();
|
|
|
|
|
2016-05-31 00:15:41 +08:00
|
|
|
bool search_current();
|
|
|
|
bool search_prev();
|
|
|
|
bool search_next();
|
2016-05-29 00:25:45 +08:00
|
|
|
|
|
|
|
FindReplaceBar();
|
|
|
|
};
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-06-13 17:17:20 +08:00
|
|
|
typedef void (*CodeTextEditorCodeCompleteFunc)(void *p_ud, const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_forced);
|
2016-08-03 06:11:05 +08:00
|
|
|
|
2016-05-29 00:25:45 +08:00
|
|
|
class CodeTextEditor : public VBoxContainer {
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(CodeTextEditor, VBoxContainer);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
TextEdit *text_editor;
|
2016-05-29 00:25:45 +08:00
|
|
|
FindReplaceBar *find_replace_bar;
|
2018-02-08 20:04:39 +08:00
|
|
|
HBoxContainer *status_bar;
|
2019-02-02 00:20:59 +08:00
|
|
|
|
2020-06-20 02:49:04 +08:00
|
|
|
Button *toggle_scripts_button;
|
|
|
|
Button *warning_button;
|
2018-07-02 00:17:40 +08:00
|
|
|
Label *warning_count_label;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-02-02 00:20:59 +08:00
|
|
|
Label *line_and_col_txt;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Label *info;
|
|
|
|
Timer *idle;
|
2014-05-04 11:22:49 +08:00
|
|
|
Timer *code_complete_timer;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-06-18 03:58:50 +08:00
|
|
|
Timer *font_resize_timer;
|
|
|
|
int font_resize_val;
|
2017-11-02 04:49:39 +08:00
|
|
|
real_t font_size;
|
2016-06-18 03:58:50 +08:00
|
|
|
|
2018-12-21 16:05:29 +08:00
|
|
|
Label *error;
|
2018-11-21 18:56:02 +08:00
|
|
|
int error_line;
|
|
|
|
int error_column;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2014-05-01 00:21:58 +08:00
|
|
|
void _on_settings_change();
|
2014-04-05 23:39:30 +08:00
|
|
|
|
2016-05-29 22:37:26 +08:00
|
|
|
void _update_font();
|
2014-12-17 09:31:57 +08:00
|
|
|
void _complete_request();
|
2019-06-12 02:43:37 +08:00
|
|
|
Ref<Texture2D> _get_completion_icon(const ScriptCodeCompletionOption &p_option);
|
2016-06-18 03:58:50 +08:00
|
|
|
void _font_resize_timeout();
|
2017-11-02 04:49:39 +08:00
|
|
|
bool _add_font_size(int p_delta);
|
2016-06-18 03:58:50 +08:00
|
|
|
|
2019-05-10 00:26:33 +08:00
|
|
|
void _input(const Ref<InputEvent> &event);
|
2017-05-20 23:38:03 +08:00
|
|
|
void _text_editor_gui_input(const Ref<InputEvent> &p_event);
|
2016-07-15 03:03:40 +08:00
|
|
|
void _zoom_in();
|
|
|
|
void _zoom_out();
|
2017-11-02 04:49:39 +08:00
|
|
|
void _zoom_changed();
|
2016-07-15 03:03:40 +08:00
|
|
|
void _reset_zoom();
|
2016-06-18 03:58:50 +08:00
|
|
|
|
2020-05-04 00:08:15 +08:00
|
|
|
Color completion_font_color;
|
|
|
|
Color completion_string_color;
|
|
|
|
Color completion_comment_color;
|
2016-08-03 06:11:05 +08:00
|
|
|
CodeTextEditorCodeCompleteFunc code_complete_func;
|
|
|
|
void *code_complete_ud;
|
|
|
|
|
2019-02-02 00:20:59 +08:00
|
|
|
void _warning_label_gui_input(const Ref<InputEvent> &p_event);
|
|
|
|
void _warning_button_pressed();
|
2019-02-13 17:12:31 +08:00
|
|
|
void _set_show_warnings_panel(bool p_show);
|
2019-02-02 00:20:59 +08:00
|
|
|
void _error_pressed(const Ref<InputEvent> &p_event);
|
|
|
|
|
2019-12-09 14:29:24 +08:00
|
|
|
void _delete_line(int p_line);
|
2019-12-15 21:35:16 +08:00
|
|
|
void _toggle_scripts_pressed();
|
2019-12-09 14:29:24 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
protected:
|
|
|
|
virtual void _load_theme_settings() {}
|
2016-08-03 06:11:05 +08:00
|
|
|
virtual void _validate_script() {}
|
2019-06-13 17:17:20 +08:00
|
|
|
virtual void _code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options) {}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
void _text_changed_idle_timeout();
|
2014-05-04 11:22:49 +08:00
|
|
|
void _code_complete_timer_timeout();
|
2014-02-10 09:10:30 +08:00
|
|
|
void _text_changed();
|
|
|
|
void _line_col_changed();
|
|
|
|
void _notification(int);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2019-02-13 17:12:31 +08:00
|
|
|
bool is_warnings_panel_opened;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
public:
|
2018-05-26 06:49:35 +08:00
|
|
|
void trim_trailing_whitespace();
|
2019-05-29 05:27:32 +08:00
|
|
|
void insert_final_newline();
|
2018-05-26 06:49:35 +08:00
|
|
|
|
|
|
|
void convert_indent_to_spaces();
|
|
|
|
void convert_indent_to_tabs();
|
|
|
|
|
|
|
|
enum CaseStyle {
|
|
|
|
UPPER,
|
|
|
|
LOWER,
|
|
|
|
CAPITALIZE,
|
|
|
|
};
|
|
|
|
void convert_case(CaseStyle p_case);
|
|
|
|
|
|
|
|
void move_lines_up();
|
|
|
|
void move_lines_down();
|
|
|
|
void delete_lines();
|
2018-11-05 02:26:08 +08:00
|
|
|
void clone_lines_down();
|
2018-05-26 06:49:35 +08:00
|
|
|
|
2019-02-05 03:17:44 +08: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);
|
|
|
|
|
2018-05-26 06:49:35 +08:00
|
|
|
void goto_line(int p_line);
|
|
|
|
void goto_line_selection(int p_line, int p_begin, int p_end);
|
2019-01-04 20:09:01 +08:00
|
|
|
void goto_line_centered(int p_line);
|
2019-04-23 00:20:27 +08:00
|
|
|
void set_executing_line(int p_line);
|
|
|
|
void clear_executing_line();
|
2018-05-26 06:49:35 +08:00
|
|
|
|
|
|
|
Variant get_edit_state();
|
|
|
|
void set_edit_state(const Variant &p_state);
|
|
|
|
|
2019-02-02 00:20:59 +08:00
|
|
|
void set_warning_nb(int p_warning_nb);
|
|
|
|
|
2016-10-10 16:38:12 +08:00
|
|
|
void update_editor_settings();
|
2017-03-05 23:44:50 +08:00
|
|
|
void set_error(const String &p_error);
|
2018-11-21 18:56:02 +08:00
|
|
|
void set_error_pos(int p_line, int p_column);
|
2016-08-03 06:11:05 +08:00
|
|
|
void update_line_and_column() { _line_col_changed(); }
|
2014-02-10 09:10:30 +08:00
|
|
|
TextEdit *get_text_edit() { return text_editor; }
|
2016-05-29 00:25:45 +08:00
|
|
|
FindReplaceBar *get_find_replace_bar() { return find_replace_bar; }
|
2014-02-10 09:10:30 +08:00
|
|
|
virtual void apply_code() {}
|
2018-12-21 16:05:29 +08:00
|
|
|
void goto_error();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-04-20 07:51:25 +08:00
|
|
|
void toggle_bookmark();
|
|
|
|
void goto_next_bookmark();
|
|
|
|
void goto_prev_bookmark();
|
|
|
|
void remove_all_bookmarks();
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void set_code_complete_func(CodeTextEditorCodeCompleteFunc p_code_complete_func, void *p_ud);
|
2016-08-03 06:11:05 +08:00
|
|
|
|
2019-05-09 00:49:49 +08:00
|
|
|
void validate_script();
|
|
|
|
|
2019-12-17 16:16:17 +08:00
|
|
|
void show_toggle_scripts_button();
|
2019-12-17 21:51:49 +08:00
|
|
|
void update_toggle_scripts_button();
|
2019-12-17 16:16:17 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
CodeTextEditor();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CODE_EDITOR_H
|