script_text_editor.h 7.2 KB

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