Debian Codegraph @

editor/script/text_editor.h

raw symbols SCIP
1 /**************************************************************************/
2 /* 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_plugin.h"
34
35 #include "editor/gui/code_editor.h"
36
37 class TextEditor : public ScriptEditorBase {
38 GDCLASS(TextEditor, ScriptEditorBase);
39
40 static ScriptEditorBase *create_editor(const Ref<Resource> &p_resource);
41
42 private:
43 CodeTextEditor *code_editor = nullptr;
44
45 Ref<Resource> edited_res;
46 bool editor_enabled = false;
47
48 HBoxContainer *edit_hb = nullptr;
49 MenuButton *edit_menu = nullptr;
50 PopupMenu *highlighter_menu = nullptr;
51 MenuButton *search_menu = nullptr;
52 PopupMenu *bookmarks_menu = nullptr;
53 PopupMenu *context_menu = nullptr;
54
55 GotoLinePopup *goto_line_popup = nullptr;
56
57 enum {
58 EDIT_UNDO,
59 EDIT_REDO,
60 EDIT_CUT,
61 EDIT_COPY,
62 EDIT_PASTE,
63 EDIT_SELECT_ALL,
64 EDIT_TRIM_TRAILING_WHITESAPCE,
65 EDIT_TRIM_FINAL_NEWLINES,
66 EDIT_CONVERT_INDENT_TO_SPACES,
67 EDIT_CONVERT_INDENT_TO_TABS,
68 EDIT_MOVE_LINE_UP,
69 EDIT_MOVE_LINE_DOWN,
70 EDIT_INDENT,
71 EDIT_UNINDENT,
72 EDIT_DELETE_LINE,
73 EDIT_DUPLICATE_SELECTION,
74 EDIT_DUPLICATE_LINES,
75 EDIT_TO_UPPERCASE,
76 EDIT_TO_LOWERCASE,
77 EDIT_CAPITALIZE,
78 EDIT_TOGGLE_WORD_WRAP,
79 EDIT_TOGGLE_FOLD_LINE,
80 EDIT_FOLD_ALL_LINES,
81 EDIT_UNFOLD_ALL_LINES,
82 SEARCH_FIND,
83 SEARCH_FIND_NEXT,
84 SEARCH_FIND_PREV,
85 SEARCH_REPLACE,
86 SEARCH_IN_FILES,
87 REPLACE_IN_FILES,
88 SEARCH_GOTO_LINE,
89 BOOKMARK_TOGGLE,
90 BOOKMARK_GOTO_NEXT,
91 BOOKMARK_GOTO_PREV,
92 BOOKMARK_REMOVE_ALL,
93 EDIT_EMOJI_AND_SYMBOL,
94 };
95
96 protected:
97 void _edit_option(int p_op);
98 void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position);
99 void _text_edit_gui_input(const Ref<InputEvent> &ev);
100 void _prepare_edit_menu();
101
102 HashMap<String, Ref<EditorSyntaxHighlighter>> highlighters;
103 void _change_syntax_highlighter(int p_idx);
104 void _load_theme_settings();
105
106 void _convert_case(CodeTextEditor::CaseStyle p_case);
107
108 void _validate_script();
109
110 void _update_bookmark_list();
111 void _bookmark_item_pressed(int p_idx);
112
113 public:
114 virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
115 virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
116
117 virtual String get_name() override;
118 virtual Ref<Texture2D> get_theme_icon() override;
119 virtual Ref<Resource> get_edited_resource() const override;
120 virtual void set_edited_resource(const Ref<Resource> &p_res) override;
121 virtual void enable_editor(Control *p_shortcut_context = nullptr) override;
122 virtual void reload_text() override;
123 virtual void apply_code() override;
124 virtual bool is_unsaved() override;
125 virtual Variant get_edit_state() override;
126 virtual void set_edit_state(const Variant &p_state) override;
127 virtual Variant get_navigation_state() override;
128 virtual Vector<String> get_functions() override;
129 virtual PackedInt32Array get_breakpoints() override;
130 virtual void set_breakpoint(int p_line, bool p_enabled) override {}
131 virtual void clear_breakpoints() override {}
132 virtual void goto_line(int p_line, int p_column = 0) override;
133 void goto_line_selection(int p_line, int p_begin, int p_end);
134 virtual void set_executing_line(int p_line) override;
135 virtual void clear_executing_line() override;
136 virtual void trim_trailing_whitespace() override;
137 virtual void trim_final_newlines() override;
138 virtual void insert_final_newline() override;
139 virtual void convert_indent() override;
140 virtual void ensure_focus() override;
141 virtual void tag_saved_version() override;
142 virtual void update_settings() override;
143 virtual bool show_members_overview() override;
144 virtual void set_debugger_active(bool p_active) override;
145 virtual void set_tooltip_request_func(const Callable &p_toolip_callback) override;
146 virtual void add_callback(const String &p_function, const PackedStringArray &p_args) override;
147 void update_toggle_files_button() override;
148
149 virtual Control *get_edit_menu() override;
150 virtual void clear_edit_menu() override;
151 virtual void set_find_replace_bar(FindReplaceBar *p_bar) override;
152
153 virtual void validate() override;
154
155 virtual Control *get_base_editor() const override;
156 virtual CodeTextEditor *get_code_editor() const override;
157
158 static void register_editor();
159
160 TextEditor();
161 ~TextEditor();
162 };