2
0

script_text_editor.h 7.6 KB

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