text_editor.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. 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 control_flow_keyword_color;
  51. Color basetype_color;
  52. Color type_color;
  53. Color comment_color;
  54. Color string_color;
  55. } colors_cache;
  56. enum {
  57. EDIT_UNDO,
  58. EDIT_REDO,
  59. EDIT_CUT,
  60. EDIT_COPY,
  61. EDIT_PASTE,
  62. EDIT_SELECT_ALL,
  63. EDIT_TRIM_TRAILING_WHITESAPCE,
  64. EDIT_CONVERT_INDENT_TO_SPACES,
  65. EDIT_CONVERT_INDENT_TO_TABS,
  66. EDIT_MOVE_LINE_UP,
  67. EDIT_MOVE_LINE_DOWN,
  68. EDIT_INDENT_RIGHT,
  69. EDIT_INDENT_LEFT,
  70. EDIT_DELETE_LINE,
  71. EDIT_DUPLICATE_SELECTION,
  72. EDIT_TO_UPPERCASE,
  73. EDIT_TO_LOWERCASE,
  74. EDIT_CAPITALIZE,
  75. EDIT_TOGGLE_FOLD_LINE,
  76. EDIT_FOLD_ALL_LINES,
  77. EDIT_UNFOLD_ALL_LINES,
  78. SEARCH_FIND,
  79. SEARCH_FIND_NEXT,
  80. SEARCH_FIND_PREV,
  81. SEARCH_REPLACE,
  82. SEARCH_IN_FILES,
  83. REPLACE_IN_FILES,
  84. SEARCH_GOTO_LINE,
  85. BOOKMARK_TOGGLE,
  86. BOOKMARK_GOTO_NEXT,
  87. BOOKMARK_GOTO_PREV,
  88. BOOKMARK_REMOVE_ALL,
  89. };
  90. static ScriptEditorBase *create_editor(const RES &p_resource);
  91. protected:
  92. static void _bind_methods();
  93. void _edit_option(int p_op);
  94. void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position);
  95. void _text_edit_gui_input(const Ref<InputEvent> &ev);
  96. void _prepare_edit_menu();
  97. Map<String, SyntaxHighlighter *> highlighters;
  98. void _change_syntax_highlighter(int p_idx);
  99. void _load_theme_settings();
  100. void _convert_case(CodeTextEditor::CaseStyle p_case);
  101. void _validate_script();
  102. void _update_bookmark_list();
  103. void _bookmark_item_pressed(int p_idx);
  104. public:
  105. virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter);
  106. virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter);
  107. virtual String get_name();
  108. virtual Ref<Texture> get_icon();
  109. virtual RES get_edited_resource() const;
  110. virtual void set_edited_resource(const RES &p_res);
  111. virtual void enable_editor();
  112. virtual void reload_text();
  113. virtual void apply_code();
  114. virtual bool is_unsaved();
  115. virtual Variant get_edit_state();
  116. virtual void set_edit_state(const Variant &p_state);
  117. virtual Vector<String> get_functions();
  118. virtual void get_breakpoints(List<int> *p_breakpoints);
  119. virtual void goto_line(int p_line, bool p_with_error = false);
  120. void goto_line_selection(int p_line, int p_begin, int p_end);
  121. virtual void set_executing_line(int p_line);
  122. virtual void clear_executing_line();
  123. virtual void trim_trailing_whitespace();
  124. virtual void insert_final_newline();
  125. virtual void convert_indent_to_spaces();
  126. virtual void convert_indent_to_tabs();
  127. virtual void ensure_focus();
  128. virtual void tag_saved_version();
  129. virtual void update_settings();
  130. virtual bool show_members_overview();
  131. virtual bool can_lose_focus_on_node_selection() { return true; }
  132. virtual void set_debugger_active(bool p_active);
  133. virtual void set_tooltip_request_func(String p_method, Object *p_obj);
  134. virtual void add_callback(const String &p_function, PoolStringArray p_args);
  135. virtual Control *get_edit_menu();
  136. virtual void clear_edit_menu();
  137. virtual void validate();
  138. static void register_editor();
  139. TextEditor();
  140. ~TextEditor();
  141. };
  142. #endif // TEXT_EDITOR_H