text_editor.h 5.0 KB

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