script_text_editor.h 7.9 KB

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