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