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
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**************************************************************************/
/*  text_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.                 */
/**************************************************************************/

#ifndef TEXT_EDITOR_H
#define TEXT_EDITOR_H

#include "script_editor_plugin.h"

class TextEditor : public ScriptEditorBase {
	GDCLASS(TextEditor, ScriptEditorBase);

private:
	CodeTextEditor *code_editor;

	Ref<TextFile> text_file;
	bool editor_enabled;

	HBoxContainer *edit_hb;
	MenuButton *edit_menu;
	PopupMenu *highlighter_menu;
	MenuButton *search_menu;
	PopupMenu *bookmarks_menu;
	PopupMenu *context_menu;

	GotoLineDialog *goto_line_dialog;

	struct ColorsCache {
		Color font_color;
		Color symbol_color;
		Color keyword_color;
		Color control_flow_keyword_color;
		Color basetype_color;
		Color type_color;
		Color comment_color;
		Color string_color;
	} colors_cache;

	enum {
		EDIT_UNDO,
		EDIT_REDO,
		EDIT_CUT,
		EDIT_COPY,
		EDIT_PASTE,
		EDIT_SELECT_ALL,
		EDIT_TRIM_TRAILING_WHITESAPCE,
		EDIT_CONVERT_INDENT_TO_SPACES,
		EDIT_CONVERT_INDENT_TO_TABS,
		EDIT_MOVE_LINE_UP,
		EDIT_MOVE_LINE_DOWN,
		EDIT_INDENT_RIGHT,
		EDIT_INDENT_LEFT,
		EDIT_DELETE_LINE,
		EDIT_DUPLICATE_SELECTION,
		EDIT_TO_UPPERCASE,
		EDIT_TO_LOWERCASE,
		EDIT_CAPITALIZE,
		EDIT_TOGGLE_FOLD_LINE,
		EDIT_FOLD_ALL_LINES,
		EDIT_UNFOLD_ALL_LINES,
		SEARCH_FIND,
		SEARCH_FIND_NEXT,
		SEARCH_FIND_PREV,
		SEARCH_REPLACE,
		SEARCH_IN_FILES,
		REPLACE_IN_FILES,
		SEARCH_GOTO_LINE,
		BOOKMARK_TOGGLE,
		BOOKMARK_GOTO_NEXT,
		BOOKMARK_GOTO_PREV,
		BOOKMARK_REMOVE_ALL,
	};
	static ScriptEditorBase *create_editor(const RES &p_resource);

protected:
	static void _bind_methods();

	void _edit_option(int p_op);
	void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position);
	void _text_edit_gui_input(const Ref<InputEvent> &ev);
	void _prepare_edit_menu();

	Map<String, SyntaxHighlighter *> highlighters;
	void _change_syntax_highlighter(int p_idx);
	void _load_theme_settings();

	void _convert_case(CodeTextEditor::CaseStyle p_case);

	void _validate_script();

	void _update_bookmark_list();
	void _bookmark_item_pressed(int p_idx);

public:
	virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter);<--- Function in derived class
	virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter);<--- Function in derived class

	virtual String get_name();<--- Function in derived class
	virtual Ref<Texture> get_icon();<--- Function in derived class
	virtual RES get_edited_resource() const;<--- Function in derived class
	virtual void set_edited_resource(const RES &p_res);<--- Function in derived class
	virtual void enable_editor();<--- Function in derived class
	virtual void reload_text();<--- Function in derived class
	virtual void apply_code();<--- Function in derived class
	virtual bool is_unsaved();<--- Function in derived class
	virtual Variant get_edit_state();<--- Function in derived class
	virtual void set_edit_state(const Variant &p_state);<--- Function in derived class
	virtual Vector<String> get_functions();<--- Function in derived class
	virtual void get_breakpoints(List<int> *p_breakpoints);<--- Function in derived class
	virtual void goto_line(int p_line, bool p_with_error = false);<--- Function in derived class
	void goto_line_selection(int p_line, int p_begin, int p_end);
	virtual void set_executing_line(int p_line);<--- Function in derived class
	virtual void clear_executing_line();<--- Function in derived class
	virtual void trim_trailing_whitespace();<--- Function in derived class
	virtual void insert_final_newline();<--- Function in derived class
	virtual void convert_indent_to_spaces();<--- Function in derived class
	virtual void convert_indent_to_tabs();<--- Function in derived class
	virtual void ensure_focus();<--- Function in derived class
	virtual void tag_saved_version();<--- Function in derived class
	virtual void update_settings();<--- Function in derived class<--- update_settings is a virtual function
	virtual bool show_members_overview();<--- Function in derived class
	virtual bool can_lose_focus_on_node_selection() { return true; }<--- Function in derived class
	virtual void set_debugger_active(bool p_active);<--- Function in derived class
	virtual void set_tooltip_request_func(String p_method, Object *p_obj);<--- Function in derived class
	virtual void add_callback(const String &p_function, PoolStringArray p_args);<--- Function in derived class

	virtual Control *get_edit_menu();<--- Function in derived class
	virtual void clear_edit_menu();<--- Function in derived class

	virtual void validate();<--- Function in derived class

	static void register_editor();

	TextEditor();
	~TextEditor();
};

#endif // TEXT_EDITOR_H