script_editor_plugin.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*************************************************************************/
  2. /* script_editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef SCRIPT_EDITOR_PLUGIN_H
  30. #define SCRIPT_EDITOR_PLUGIN_H
  31. #include "tools/editor/editor_plugin.h"
  32. #include "tools/editor/script_create_dialog.h"
  33. #include "scene/gui/tab_container.h"
  34. #include "scene/gui/text_edit.h"
  35. #include "scene/gui/menu_button.h"
  36. #include "scene/gui/tool_button.h"
  37. #include "scene/gui/tree.h"
  38. #include "scene/main/timer.h"
  39. #include "script_language.h"
  40. #include "tools/editor/code_editor.h"
  41. #include "scene/gui/split_container.h"
  42. #include "scene/gui/item_list.h"
  43. #include "tools/editor/editor_help.h"
  44. class ScriptEditorQuickOpen : public ConfirmationDialog {
  45. OBJ_TYPE(ScriptEditorQuickOpen,ConfirmationDialog )
  46. LineEdit *search_box;
  47. Tree *search_options;
  48. String function;
  49. void _update_search();
  50. void _sbox_input(const InputEvent& p_ie);
  51. Vector<String> functions;
  52. void _confirmed();
  53. void _text_changed(const String& p_newtext);
  54. protected:
  55. void _notification(int p_what);
  56. static void _bind_methods();
  57. public:
  58. void popup(const Vector<String>& p_base,bool p_dontclear=false);
  59. ScriptEditorQuickOpen();
  60. };
  61. class ScriptEditorDebugger;
  62. class ScriptTextEditor : public CodeTextEditor {
  63. OBJ_TYPE( ScriptTextEditor, CodeTextEditor );
  64. Ref<Script> script;
  65. Vector<String> functions;
  66. protected:
  67. virtual void _validate_script();
  68. virtual void _code_complete_script(const String& p_code, List<String>* r_options);
  69. virtual void _load_theme_settings();
  70. void _notification(int p_what);
  71. static void _bind_methods();
  72. public:
  73. virtual void apply_code();
  74. Ref<Script> get_edited_script() const;
  75. Vector<String> get_functions() ;
  76. void set_edited_script(const Ref<Script>& p_script);
  77. void reload_text();
  78. String get_name() ;
  79. Ref<Texture> get_icon() ;
  80. bool is_unsaved();
  81. ScriptTextEditor();
  82. };
  83. class EditorScriptCodeCompletionCache;
  84. class ScriptEditor : public VBoxContainer {
  85. OBJ_TYPE(ScriptEditor, VBoxContainer );
  86. EditorNode *editor;
  87. enum {
  88. FILE_NEW,
  89. FILE_OPEN,
  90. FILE_SAVE,
  91. FILE_SAVE_AS,
  92. FILE_SAVE_ALL,
  93. FILE_IMPORT_THEME,
  94. FILE_RELOAD_THEME,
  95. FILE_SAVE_THEME,
  96. FILE_SAVE_THEME_AS,
  97. FILE_CLOSE,
  98. CLOSE_DOCS,
  99. EDIT_UNDO,
  100. EDIT_REDO,
  101. EDIT_CUT,
  102. EDIT_COPY,
  103. EDIT_PASTE,
  104. EDIT_SELECT_ALL,
  105. EDIT_COMPLETE,
  106. EDIT_AUTO_INDENT,
  107. EDIT_TRIM_TRAILING_WHITESAPCE,
  108. EDIT_TOGGLE_COMMENT,
  109. EDIT_MOVE_LINE_UP,
  110. EDIT_MOVE_LINE_DOWN,
  111. EDIT_INDENT_RIGHT,
  112. EDIT_INDENT_LEFT,
  113. EDIT_CLONE_DOWN,
  114. FILE_TOOL_RELOAD,
  115. FILE_TOOL_RELOAD_SOFT,
  116. SEARCH_FIND,
  117. SEARCH_FIND_NEXT,
  118. SEARCH_FIND_PREV,
  119. SEARCH_REPLACE,
  120. SEARCH_LOCATE_FUNCTION,
  121. SEARCH_GOTO_LINE,
  122. SEARCH_HELP,
  123. SEARCH_CLASSES,
  124. SEARCH_WEBSITE,
  125. DEBUG_TOGGLE_BREAKPOINT,
  126. DEBUG_REMOVE_ALL_BREAKPOINTS,
  127. DEBUG_GOTO_NEXT_BREAKPOINT,
  128. DEBUG_GOTO_PREV_BREAKPOINT,
  129. DEBUG_NEXT,
  130. DEBUG_STEP,
  131. DEBUG_BREAK,
  132. DEBUG_CONTINUE,
  133. DEBUG_SHOW,
  134. DEBUG_SHOW_KEEP_OPEN,
  135. HELP_CONTEXTUAL,
  136. WINDOW_MOVE_LEFT,
  137. WINDOW_MOVE_RIGHT,
  138. WINDOW_NEXT,
  139. WINDOW_PREV,
  140. WINDOW_SELECT_BASE=100
  141. };
  142. HBoxContainer *menu_hb;
  143. MenuButton *file_menu;
  144. MenuButton *edit_menu;
  145. MenuButton *search_menu;
  146. MenuButton *script_search_menu;
  147. MenuButton *debug_menu;
  148. MenuButton *help_menu;
  149. Timer *autosave_timer;
  150. uint64_t idle;
  151. Button *help_search;
  152. Button *site_search;
  153. Button *class_search;
  154. EditorHelpSearch *help_search_dialog;
  155. ItemList *script_list;
  156. HSplitContainer *script_split;
  157. TabContainer *tab_container;
  158. EditorFileDialog *file_dialog;
  159. GotoLineDialog *goto_line_dialog;
  160. ConfirmationDialog *erase_tab_confirm;
  161. ScriptCreateDialog *script_create_dialog;
  162. ScriptEditorDebugger* debugger;
  163. ToolButton *scripts_visible;
  164. String current_theme;
  165. TextureFrame *script_icon;
  166. Label *script_name_label;
  167. ToolButton *script_back;
  168. ToolButton *script_forward;
  169. struct ScriptHistory {
  170. Control *control;
  171. int scroll_pos;
  172. int cursor_column;
  173. int cursor_row;
  174. };
  175. Vector<ScriptHistory> history;
  176. int history_pos;
  177. EditorHelpIndex *help_index;
  178. void _tab_changed(int p_which);
  179. void _menu_option(int p_optin);
  180. Tree *disk_changed_list;
  181. ConfirmationDialog *disk_changed;
  182. bool restoring_layout;
  183. String _get_debug_tooltip(const String&p_text,Node *_ste);
  184. void _resave_scripts(const String& p_str);
  185. void _reload_scripts();
  186. bool _test_script_times_on_disk(Ref<Script> p_for_script=Ref<Script>());
  187. void _close_tab(int p_idx);
  188. void _close_current_tab();
  189. void _close_docs_tab();
  190. bool grab_focus_block;
  191. bool pending_auto_reload;
  192. bool auto_reload_running_scripts;
  193. void _live_auto_reload_running_scripts();
  194. ScriptEditorQuickOpen *quick_open;
  195. EditorScriptCodeCompletionCache *completion_cache;
  196. void _editor_play();
  197. void _editor_pause();
  198. void _editor_stop();
  199. int edit_pass;
  200. void _add_callback(Object *p_obj, const String& p_function, const StringArray& p_args);
  201. void _res_saved_callback(const Ref<Resource>& p_res);
  202. bool trim_trailing_whitespace_on_save;
  203. void _trim_trailing_whitespace(TextEdit *tx);
  204. void _goto_script_line2(int p_line);
  205. void _goto_script_line(REF p_script,int p_line);
  206. void _breaked(bool p_breaked,bool p_can_debug);
  207. void _show_debugger(bool p_show);
  208. void _update_window_menu();
  209. void _script_created(Ref<Script> p_script);
  210. void _editor_settings_changed();
  211. void _autosave_scripts();
  212. void _update_script_names();
  213. void _script_selected(int p_idx);
  214. void _find_scripts(Node* p_base, Node* p_current,Set<Ref<Script> >& used);
  215. void _tree_changed();
  216. void _script_split_dragged(float);
  217. void _unhandled_input(const InputEvent& p_event);
  218. void _history_forward();
  219. void _history_back();
  220. bool waiting_update_names;
  221. void _help_class_open(const String& p_class);
  222. void _help_class_goto(const String& p_desc);
  223. void _update_history_arrows();
  224. void _go_to_tab(int p_idx);
  225. void _update_history_pos(int p_new_pos);
  226. void _update_script_colors();
  227. void _update_modified_scripts_for_external_editor(Ref<Script> p_for_script=Ref<Script>());
  228. int file_dialog_option;
  229. void _file_dialog_action(String p_file);
  230. static ScriptEditor *script_editor;
  231. protected:
  232. void _notification(int p_what);
  233. static void _bind_methods();
  234. public:
  235. static ScriptEditor *get_singleton() { return script_editor; }
  236. void ensure_focus_current();
  237. void apply_scripts() const;
  238. void ensure_select_current();
  239. void edit(const Ref<Script>& p_script);
  240. Dictionary get_state() const;
  241. void set_state(const Dictionary& p_state);
  242. void clear();
  243. void get_breakpoints(List<String> *p_breakpoints);
  244. void swap_lines(TextEdit *tx, int line1, int line2);
  245. void save_all_scripts();
  246. void set_window_layout(Ref<ConfigFile> p_layout);
  247. void get_window_layout(Ref<ConfigFile> p_layout);
  248. void set_scene_root_script( Ref<Script> p_script );
  249. bool script_go_to_method(Ref<Script> p_script, const String& p_method);
  250. virtual void edited_scene_changed();
  251. void close_builtin_scripts_from_scene(const String& p_scene);
  252. ScriptEditorDebugger *get_debugger() { return debugger; }
  253. void set_live_auto_reload_running_scripts(bool p_enabled);
  254. ScriptEditor(EditorNode *p_editor);
  255. ~ScriptEditor();
  256. };
  257. class ScriptEditorPlugin : public EditorPlugin {
  258. OBJ_TYPE( ScriptEditorPlugin, EditorPlugin );
  259. ScriptEditor *script_editor;
  260. EditorNode *editor;
  261. public:
  262. virtual String get_name() const { return "Script"; }
  263. bool has_main_screen() const { return true; }
  264. virtual void edit(Object *p_node);
  265. virtual bool handles(Object *p_node) const;
  266. virtual void make_visible(bool p_visible);
  267. virtual void selected_notify();
  268. Dictionary get_state() const;
  269. virtual void set_state(const Dictionary& p_state);
  270. virtual void clear();
  271. virtual void save_external_data();
  272. virtual void apply_changes();
  273. virtual void restore_global_state();
  274. virtual void save_global_state();
  275. virtual void set_window_layout(Ref<ConfigFile> p_layout);
  276. virtual void get_window_layout(Ref<ConfigFile> p_layout);
  277. virtual void get_breakpoints(List<String> *p_breakpoints);
  278. virtual void edited_scene_changed();
  279. ScriptEditorPlugin(EditorNode *p_node);
  280. ~ScriptEditorPlugin();
  281. };
  282. #endif // SCRIPT_EDITOR_PLUGIN_H