text_editor.h 5.5 KB

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