script_text_editor.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*************************************************************************/
  2. /* script_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 SCRIPT_TEXT_EDITOR_H
  31. #define SCRIPT_TEXT_EDITOR_H
  32. #include "scene/gui/color_picker.h"
  33. #include "script_editor_plugin.h"
  34. class ScriptTextEditor : public ScriptEditorBase {
  35. GDCLASS(ScriptTextEditor, ScriptEditorBase);
  36. CodeTextEditor *code_editor;
  37. RichTextLabel *warnings_panel;
  38. Ref<Script> script;
  39. Vector<String> functions;
  40. Vector<String> member_keywords;
  41. HBoxContainer *edit_hb;
  42. MenuButton *edit_menu;
  43. MenuButton *search_menu;
  44. PopupMenu *highlighter_menu;
  45. PopupMenu *context_menu;
  46. GotoLineDialog *goto_line_dialog;
  47. ScriptEditorQuickOpen *quick_open;
  48. PopupPanel *color_panel;
  49. ColorPicker *color_picker;
  50. int color_line;
  51. String color_args;
  52. void _update_member_keywords();
  53. struct ColorsCache {
  54. Color symbol_color;
  55. Color keyword_color;
  56. Color basetype_color;
  57. Color type_color;
  58. Color comment_color;
  59. Color string_color;
  60. } colors_cache;
  61. bool theme_loaded;
  62. enum {
  63. EDIT_UNDO,
  64. EDIT_REDO,
  65. EDIT_CUT,
  66. EDIT_COPY,
  67. EDIT_PASTE,
  68. EDIT_SELECT_ALL,
  69. EDIT_COMPLETE,
  70. EDIT_AUTO_INDENT,
  71. EDIT_TRIM_TRAILING_WHITESAPCE,
  72. EDIT_CONVERT_INDENT_TO_SPACES,
  73. EDIT_CONVERT_INDENT_TO_TABS,
  74. EDIT_TOGGLE_COMMENT,
  75. EDIT_MOVE_LINE_UP,
  76. EDIT_MOVE_LINE_DOWN,
  77. EDIT_INDENT_RIGHT,
  78. EDIT_INDENT_LEFT,
  79. EDIT_DELETE_LINE,
  80. EDIT_CLONE_DOWN,
  81. EDIT_PICK_COLOR,
  82. EDIT_TO_UPPERCASE,
  83. EDIT_TO_LOWERCASE,
  84. EDIT_CAPITALIZE,
  85. EDIT_TOGGLE_FOLD_LINE,
  86. EDIT_FOLD_ALL_LINES,
  87. EDIT_UNFOLD_ALL_LINES,
  88. SEARCH_FIND,
  89. SEARCH_FIND_NEXT,
  90. SEARCH_FIND_PREV,
  91. SEARCH_REPLACE,
  92. SEARCH_LOCATE_FUNCTION,
  93. SEARCH_GOTO_LINE,
  94. SEARCH_IN_FILES,
  95. DEBUG_TOGGLE_BREAKPOINT,
  96. DEBUG_REMOVE_ALL_BREAKPOINTS,
  97. DEBUG_GOTO_NEXT_BREAKPOINT,
  98. DEBUG_GOTO_PREV_BREAKPOINT,
  99. HELP_CONTEXTUAL,
  100. LOOKUP_SYMBOL,
  101. };
  102. protected:
  103. static void _code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options, bool &r_force);
  104. void _breakpoint_toggled(int p_row);
  105. //no longer virtual
  106. void _validate_script();
  107. void _code_complete_script(const String &p_code, List<String> *r_options, bool &r_force);
  108. void _load_theme_settings();
  109. void _set_theme_for_script();
  110. void _show_warnings_panel(bool p_show);
  111. void _error_pressed();
  112. void _warning_clicked(Variant p_line);
  113. void _notification(int p_what);
  114. static void _bind_methods();
  115. Map<String, SyntaxHighlighter *> highlighters;
  116. void _change_syntax_highlighter(int p_idx);
  117. void _edit_option(int p_op);
  118. void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition);
  119. void _text_edit_gui_input(const Ref<InputEvent> &ev);
  120. void _color_changed(const Color &p_color);
  121. void _goto_line(int p_line) { goto_line(p_line); }
  122. void _lookup_symbol(const String &p_symbol, int p_row, int p_column);
  123. void _convert_case(CodeTextEditor::CaseStyle p_case);
  124. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  125. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  126. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  127. public:
  128. virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter);
  129. virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter);
  130. virtual void apply_code();
  131. virtual RES get_edited_resource() const;
  132. virtual void set_edited_resource(const RES &p_res);
  133. virtual Vector<String> get_functions();
  134. virtual void reload_text();
  135. virtual String get_name();
  136. virtual Ref<Texture> get_icon();
  137. virtual bool is_unsaved();
  138. virtual Variant get_edit_state();
  139. virtual void set_edit_state(const Variant &p_state);
  140. virtual void ensure_focus();
  141. virtual void trim_trailing_whitespace();
  142. virtual void convert_indent_to_spaces();
  143. virtual void convert_indent_to_tabs();
  144. virtual void tag_saved_version();
  145. virtual void goto_line(int p_line, bool p_with_error = false);
  146. void goto_line_selection(int p_line, int p_begin, int p_end);
  147. virtual void reload(bool p_soft);
  148. virtual void get_breakpoints(List<int> *p_breakpoints);
  149. virtual void add_callback(const String &p_function, PoolStringArray p_args);
  150. virtual void update_settings();
  151. virtual bool show_members_overview();
  152. virtual void set_tooltip_request_func(String p_method, Object *p_obj);
  153. virtual void set_debugger_active(bool p_active);
  154. Control *get_edit_menu();
  155. virtual void clear_edit_menu();
  156. static void register_editor();
  157. ScriptTextEditor();
  158. };
  159. #endif // SCRIPT_TEXT_EDITOR_H