text_editor.h 6.3 KB

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