1 /*************************************************************************/ 2 /* text_editor.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 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 class TextEditor : public ScriptEditorBase { 37 38 GDCLASS(TextEditor, ScriptEditorBase); 39 40 private: 41 CodeTextEditor *code_editor; 42 43 Ref<TextFile> text_file; 44 45 HBoxContainer *edit_hb; 46 MenuButton *edit_menu; 47 PopupMenu *highlighter_menu; 48 MenuButton *search_menu; 49 PopupMenu *bookmarks_menu; 50 PopupMenu *context_menu; 51 52 GotoLineDialog *goto_line_dialog; 53 54 struct ColorsCache { 55 Color font_color; 56 Color symbol_color; 57 Color keyword_color; 58 Color basetype_color; 59 Color type_color; 60 Color comment_color; 61 Color string_color; 62 } colors_cache; 63 64 enum { 65 EDIT_UNDO, 66 EDIT_REDO, 67 EDIT_CUT, 68 EDIT_COPY, 69 EDIT_PASTE, 70 EDIT_SELECT_ALL, 71 EDIT_TRIM_TRAILING_WHITESAPCE, 72 EDIT_CONVERT_INDENT_TO_SPACES, 73 EDIT_CONVERT_INDENT_TO_TABS, 74 EDIT_MOVE_LINE_UP, 75 EDIT_MOVE_LINE_DOWN, 76 EDIT_INDENT_RIGHT, 77 EDIT_INDENT_LEFT, 78 EDIT_DELETE_LINE, 79 EDIT_CLONE_DOWN, 80 EDIT_TO_UPPERCASE, 81 EDIT_TO_LOWERCASE, 82 EDIT_CAPITALIZE, 83 EDIT_TOGGLE_FOLD_LINE, 84 EDIT_FOLD_ALL_LINES, 85 EDIT_UNFOLD_ALL_LINES, 86 SEARCH_FIND, 87 SEARCH_FIND_NEXT, 88 SEARCH_FIND_PREV, 89 SEARCH_REPLACE, 90 SEARCH_IN_FILES, 91 SEARCH_GOTO_LINE, 92 BOOKMARK_TOGGLE, 93 BOOKMARK_GOTO_NEXT, 94 BOOKMARK_GOTO_PREV, 95 BOOKMARK_REMOVE_ALL, 96 }; 97 98 protected: 99 static void _bind_methods(); 100 101 void _notification(int p_what); 102 103 void _edit_option(int p_op); 104 void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position); 105 void _text_edit_gui_input(const Ref<InputEvent> &ev); 106 107 Map<String, SyntaxHighlighter *> highlighters; 108 void _change_syntax_highlighter(int p_idx); 109 void _load_theme_settings(); 110 111 void _convert_case(CodeTextEditor::CaseStyle p_case); 112 113 void _validate_script(); 114 115 void _update_bookmark_list(); 116 void _bookmark_item_pressed(int p_idx); 117 118 public: 119 virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter); 120 virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter); 121 122 virtual String get_name(); 123 virtual Ref<Texture> get_icon(); 124 virtual RES get_edited_resource() const; 125 virtual void set_edited_resource(const RES &p_res); 126 void set_edited_file(const Ref<TextFile> &p_file); 127 virtual void reload_text(); 128 virtual void apply_code(); 129 virtual bool is_unsaved(); 130 virtual Variant get_edit_state(); 131 virtual void set_edit_state(const Variant &p_state); 132 virtual Vector<String> get_functions(); 133 virtual void get_breakpoints(List<int> *p_breakpoints); 134 virtual void goto_line(int p_line, bool p_with_error = false); 135 void goto_line_selection(int p_line, int p_begin, int p_end); 136 virtual void set_executing_line(int p_line); 137 virtual void clear_executing_line(); 138 virtual void trim_trailing_whitespace(); 139 virtual void insert_final_newline(); 140 virtual void convert_indent_to_spaces(); 141 virtual void convert_indent_to_tabs(); 142 virtual void ensure_focus(); 143 virtual void tag_saved_version(); 144 virtual void update_settings(); 145 virtual bool show_members_overview(); can_lose_focus_on_node_selection()146 virtual bool can_lose_focus_on_node_selection() { return true; } 147 virtual void set_debugger_active(bool p_active); 148 virtual void set_tooltip_request_func(String p_method, Object *p_obj); 149 virtual void add_callback(const String &p_function, PoolStringArray p_args); 150 151 virtual Control *get_edit_menu(); 152 virtual void clear_edit_menu(); 153 154 virtual void validate(); 155 156 static void register_editor(); 157 158 TextEditor(); 159 ~TextEditor(); 160 }; 161 162 #endif // TEXT_EDITOR_H 163