script_text_editor.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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. Ref<Script> script;
  38. Vector<String> functions;
  39. HBoxContainer *edit_hb;
  40. MenuButton *edit_menu;
  41. MenuButton *search_menu;
  42. PopupMenu *context_menu;
  43. GotoLineDialog *goto_line_dialog;
  44. ScriptEditorQuickOpen *quick_open;
  45. PopupPanel *color_panel;
  46. ColorPicker *color_picker;
  47. int color_line;
  48. String color_args;
  49. struct ColorsCache {
  50. Color symbol_color;
  51. Color keyword_color;
  52. Color basetype_color;
  53. Color type_color;
  54. Color comment_color;
  55. Color string_color;
  56. } colors_cache;
  57. bool theme_loaded;
  58. enum {
  59. EDIT_UNDO,
  60. EDIT_REDO,
  61. EDIT_CUT,
  62. EDIT_COPY,
  63. EDIT_PASTE,
  64. EDIT_SELECT_ALL,
  65. EDIT_COMPLETE,
  66. EDIT_AUTO_INDENT,
  67. EDIT_TRIM_TRAILING_WHITESAPCE,
  68. EDIT_CONVERT_INDENT_TO_SPACES,
  69. EDIT_CONVERT_INDENT_TO_TABS,
  70. EDIT_TOGGLE_COMMENT,
  71. EDIT_MOVE_LINE_UP,
  72. EDIT_MOVE_LINE_DOWN,
  73. EDIT_INDENT_RIGHT,
  74. EDIT_INDENT_LEFT,
  75. EDIT_DELETE_LINE,
  76. EDIT_CLONE_DOWN,
  77. EDIT_PICK_COLOR,
  78. EDIT_TO_UPPERCASE,
  79. EDIT_TO_LOWERCASE,
  80. EDIT_CAPITALIZE,
  81. SEARCH_FIND,
  82. SEARCH_FIND_NEXT,
  83. SEARCH_FIND_PREV,
  84. SEARCH_REPLACE,
  85. SEARCH_LOCATE_FUNCTION,
  86. SEARCH_GOTO_LINE,
  87. DEBUG_TOGGLE_BREAKPOINT,
  88. DEBUG_REMOVE_ALL_BREAKPOINTS,
  89. DEBUG_GOTO_NEXT_BREAKPOINT,
  90. DEBUG_GOTO_PREV_BREAKPOINT,
  91. HELP_CONTEXTUAL,
  92. };
  93. protected:
  94. static void _code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options, bool &r_force);
  95. void _breakpoint_toggled(int p_row);
  96. //no longer virtual
  97. void _validate_script();
  98. void _code_complete_script(const String &p_code, List<String> *r_options, bool &r_force);
  99. void _load_theme_settings();
  100. void _set_theme_for_script();
  101. void _notification(int p_what);
  102. static void _bind_methods();
  103. void _edit_option(int p_op);
  104. void _make_context_menu(bool p_selection, bool p_color);
  105. void _text_edit_gui_input(const Ref<InputEvent> &ev);
  106. void _color_changed(const Color &p_color);
  107. void _goto_line(int p_line) { goto_line(p_line); }
  108. void _lookup_symbol(const String &p_symbol, int p_row, int p_column);
  109. enum CaseStyle {
  110. UPPER,
  111. LOWER,
  112. CAPITALIZE,
  113. };
  114. void _convert_case(CaseStyle p_case);
  115. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  116. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  117. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  118. public:
  119. virtual void apply_code();
  120. virtual Ref<Script> get_edited_script() const;
  121. virtual Vector<String> get_functions();
  122. virtual void set_edited_script(const Ref<Script> &p_script);
  123. virtual void reload_text();
  124. virtual String get_name();
  125. virtual Ref<Texture> get_icon();
  126. virtual bool is_unsaved();
  127. virtual Variant get_edit_state();
  128. virtual void set_edit_state(const Variant &p_state);
  129. virtual void ensure_focus();
  130. virtual void trim_trailing_whitespace();
  131. virtual void convert_indent_to_spaces();
  132. virtual void convert_indent_to_tabs();
  133. virtual void tag_saved_version();
  134. virtual void goto_line(int p_line, bool p_with_error = false);
  135. virtual void reload(bool p_soft);
  136. virtual void get_breakpoints(List<int> *p_breakpoints);
  137. virtual void add_callback(const String &p_function, PoolStringArray p_args);
  138. virtual void update_settings();
  139. virtual bool show_members_overview();
  140. virtual void set_tooltip_request_func(String p_method, Object *p_obj);
  141. virtual void set_debugger_active(bool p_active);
  142. Control *get_edit_menu();
  143. virtual void clear_edit_menu();
  144. static void register_editor();
  145. ScriptTextEditor();
  146. };
  147. #endif // SCRIPT_TEXT_EDITOR_H