2
0

script_editor_plugin.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /**************************************************************************/
  2. /* script_editor_plugin.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_EDITOR_PLUGIN_H
  31. #define SCRIPT_EDITOR_PLUGIN_H
  32. #include "core/object/script_language.h"
  33. #include "editor/plugins/editor_plugin.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/panel_container.h"
  36. #include "scene/resources/syntax_highlighter.h"
  37. #include "scene/resources/text_file.h"
  38. class CodeTextEditor;
  39. class EditorFileDialog;
  40. class EditorHelpSearch;
  41. class FindReplaceBar;
  42. class HSplitContainer;
  43. class ItemList;
  44. class MenuButton;
  45. class TabContainer;
  46. class TextureRect;
  47. class Tree;
  48. class VSplitContainer;
  49. class WindowWrapper;
  50. class EditorSyntaxHighlighter : public SyntaxHighlighter {
  51. GDCLASS(EditorSyntaxHighlighter, SyntaxHighlighter)
  52. private:
  53. Ref<RefCounted> edited_resource;
  54. protected:
  55. static void _bind_methods();
  56. GDVIRTUAL0RC(String, _get_name)
  57. GDVIRTUAL0RC(PackedStringArray, _get_supported_languages)
  58. public:
  59. virtual String _get_name() const;
  60. virtual PackedStringArray _get_supported_languages() const;
  61. void _set_edited_resource(const Ref<Resource> &p_res) { edited_resource = p_res; }
  62. Ref<RefCounted> _get_edited_resource() { return edited_resource; }
  63. virtual Ref<EditorSyntaxHighlighter> _create() const;
  64. };
  65. class EditorStandardSyntaxHighlighter : public EditorSyntaxHighlighter {
  66. GDCLASS(EditorStandardSyntaxHighlighter, EditorSyntaxHighlighter)
  67. private:
  68. Ref<CodeHighlighter> highlighter;
  69. ScriptLanguage *script_language = nullptr; // See GH-89610.
  70. public:
  71. virtual void _update_cache() override;
  72. virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); }
  73. virtual String _get_name() const override { return TTR("Standard"); }
  74. virtual Ref<EditorSyntaxHighlighter> _create() const override;
  75. void _set_script_language(ScriptLanguage *p_script_language) { script_language = p_script_language; }
  76. EditorStandardSyntaxHighlighter() { highlighter.instantiate(); }
  77. };
  78. class EditorPlainTextSyntaxHighlighter : public EditorSyntaxHighlighter {
  79. GDCLASS(EditorPlainTextSyntaxHighlighter, EditorSyntaxHighlighter)
  80. public:
  81. virtual String _get_name() const override { return TTR("Plain Text"); }
  82. virtual Ref<EditorSyntaxHighlighter> _create() const override;
  83. };
  84. class EditorJSONSyntaxHighlighter : public EditorSyntaxHighlighter {
  85. GDCLASS(EditorJSONSyntaxHighlighter, EditorSyntaxHighlighter)
  86. private:
  87. Ref<CodeHighlighter> highlighter;
  88. public:
  89. virtual void _update_cache() override;
  90. virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); }
  91. virtual PackedStringArray _get_supported_languages() const override { return PackedStringArray{ "json" }; }
  92. virtual String _get_name() const override { return TTR("JSON"); }
  93. virtual Ref<EditorSyntaxHighlighter> _create() const override;
  94. EditorJSONSyntaxHighlighter() { highlighter.instantiate(); }
  95. };
  96. class EditorMarkdownSyntaxHighlighter : public EditorSyntaxHighlighter {
  97. GDCLASS(EditorMarkdownSyntaxHighlighter, EditorSyntaxHighlighter)
  98. private:
  99. Ref<CodeHighlighter> highlighter;
  100. public:
  101. virtual void _update_cache() override;
  102. virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); }
  103. virtual PackedStringArray _get_supported_languages() const override { return PackedStringArray{ "md", "markdown" }; }
  104. virtual String _get_name() const override { return TTR("Markdown"); }
  105. virtual Ref<EditorSyntaxHighlighter> _create() const override;
  106. EditorMarkdownSyntaxHighlighter() { highlighter.instantiate(); }
  107. };
  108. ///////////////////////////////////////////////////////////////////////////////
  109. class ScriptEditorQuickOpen : public ConfirmationDialog {
  110. GDCLASS(ScriptEditorQuickOpen, ConfirmationDialog);
  111. LineEdit *search_box = nullptr;
  112. Tree *search_options = nullptr;
  113. String function;
  114. void _update_search();
  115. void _sbox_input(const Ref<InputEvent> &p_event);
  116. Vector<String> functions;
  117. void _confirmed();
  118. void _text_changed(const String &p_newtext);
  119. protected:
  120. void _notification(int p_what);
  121. static void _bind_methods();
  122. public:
  123. void popup_dialog(const Vector<String> &p_functions, bool p_dontclear = false);
  124. ScriptEditorQuickOpen();
  125. };
  126. class EditorDebuggerNode;
  127. class ScriptEditorBase : public VBoxContainer {
  128. GDCLASS(ScriptEditorBase, VBoxContainer);
  129. protected:
  130. static void _bind_methods();
  131. public:
  132. struct EditedFileData {
  133. String path;
  134. uint64_t last_modified_time = -1;
  135. } edited_file_data;
  136. virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) = 0;
  137. virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) = 0;
  138. virtual void apply_code() = 0;
  139. virtual Ref<Resource> get_edited_resource() const = 0;
  140. virtual Vector<String> get_functions() = 0;
  141. virtual void set_edited_resource(const Ref<Resource> &p_res) = 0;
  142. virtual void enable_editor(Control *p_shortcut_context = nullptr) = 0;
  143. virtual void reload_text() = 0;
  144. virtual String get_name() = 0;
  145. virtual Ref<Texture2D> get_theme_icon() = 0;
  146. virtual bool is_unsaved() = 0;
  147. virtual Variant get_edit_state() = 0;
  148. virtual void set_edit_state(const Variant &p_state) = 0;
  149. virtual Variant get_navigation_state() = 0;
  150. virtual void goto_line(int p_line, int p_column = 0) = 0;
  151. virtual void set_executing_line(int p_line) = 0;
  152. virtual void clear_executing_line() = 0;
  153. virtual void trim_trailing_whitespace() = 0;
  154. virtual void trim_final_newlines() = 0;
  155. virtual void insert_final_newline() = 0;
  156. virtual void convert_indent() = 0;
  157. virtual void ensure_focus() = 0;
  158. virtual void tag_saved_version() = 0;
  159. virtual void reload(bool p_soft) {}
  160. virtual PackedInt32Array get_breakpoints() = 0;
  161. virtual void set_breakpoint(int p_line, bool p_enabled) = 0;
  162. virtual void clear_breakpoints() = 0;
  163. virtual void add_callback(const String &p_function, const PackedStringArray &p_args) = 0;
  164. virtual void update_settings() = 0;
  165. virtual void set_debugger_active(bool p_active) = 0;
  166. virtual bool can_lose_focus_on_node_selection() { return true; }
  167. virtual void update_toggle_scripts_button() {}
  168. virtual bool show_members_overview() = 0;
  169. virtual void set_tooltip_request_func(const Callable &p_toolip_callback) = 0;
  170. virtual Control *get_edit_menu() = 0;
  171. virtual void clear_edit_menu() = 0;
  172. virtual void set_find_replace_bar(FindReplaceBar *p_bar) = 0;
  173. virtual Control *get_base_editor() const = 0;
  174. virtual CodeTextEditor *get_code_editor() const = 0;
  175. virtual void validate() = 0;
  176. ScriptEditorBase() {}
  177. };
  178. typedef ScriptEditorBase *(*CreateScriptEditorFunc)(const Ref<Resource> &p_resource);
  179. class EditorScriptCodeCompletionCache;
  180. class FindInFilesDialog;
  181. class FindInFilesPanel;
  182. #ifdef MINGW_ENABLED
  183. #undef FILE_OPEN
  184. #endif
  185. class ScriptEditor : public PanelContainer {
  186. GDCLASS(ScriptEditor, PanelContainer);
  187. enum {
  188. FILE_NEW,
  189. FILE_NEW_TEXTFILE,
  190. FILE_OPEN,
  191. FILE_REOPEN_CLOSED,
  192. FILE_OPEN_RECENT,
  193. FILE_SAVE,
  194. FILE_SAVE_AS,
  195. FILE_SAVE_ALL,
  196. FILE_THEME,
  197. FILE_RUN,
  198. FILE_CLOSE,
  199. CLOSE_DOCS,
  200. CLOSE_ALL,
  201. CLOSE_OTHER_TABS,
  202. TOGGLE_SCRIPTS_PANEL,
  203. SHOW_IN_FILE_SYSTEM,
  204. FILE_COPY_PATH,
  205. FILE_COPY_UID,
  206. FILE_TOOL_RELOAD_SOFT,
  207. SEARCH_IN_FILES,
  208. REPLACE_IN_FILES,
  209. SEARCH_HELP,
  210. SEARCH_WEBSITE,
  211. HELP_SEARCH_FIND,
  212. HELP_SEARCH_FIND_NEXT,
  213. HELP_SEARCH_FIND_PREVIOUS,
  214. WINDOW_MOVE_UP,
  215. WINDOW_MOVE_DOWN,
  216. WINDOW_NEXT,
  217. WINDOW_PREV,
  218. WINDOW_SORT,
  219. WINDOW_SELECT_BASE = 100,
  220. };
  221. enum {
  222. THEME_IMPORT,
  223. THEME_RELOAD,
  224. THEME_SAVE,
  225. THEME_SAVE_AS
  226. };
  227. enum ScriptSortBy {
  228. SORT_BY_NAME,
  229. SORT_BY_PATH,
  230. SORT_BY_NONE
  231. };
  232. enum ScriptListName {
  233. DISPLAY_NAME,
  234. DISPLAY_DIR_AND_NAME,
  235. DISPLAY_FULL_PATH,
  236. };
  237. HBoxContainer *menu_hb = nullptr;
  238. MenuButton *file_menu = nullptr;
  239. MenuButton *edit_menu = nullptr;
  240. MenuButton *script_search_menu = nullptr;
  241. MenuButton *debug_menu = nullptr;
  242. PopupMenu *context_menu = nullptr;
  243. Timer *autosave_timer = nullptr;
  244. uint64_t idle = 0;
  245. PopupMenu *recent_scripts = nullptr;
  246. PopupMenu *theme_submenu = nullptr;
  247. Button *help_search = nullptr;
  248. Button *site_search = nullptr;
  249. Button *make_floating = nullptr;
  250. bool is_floating = false;
  251. EditorHelpSearch *help_search_dialog = nullptr;
  252. ItemList *script_list = nullptr;
  253. HSplitContainer *script_split = nullptr;
  254. ItemList *members_overview = nullptr;
  255. LineEdit *filter_scripts = nullptr;
  256. LineEdit *filter_methods = nullptr;
  257. VBoxContainer *scripts_vbox = nullptr;
  258. VBoxContainer *overview_vbox = nullptr;
  259. HBoxContainer *buttons_hbox = nullptr;
  260. Label *filename = nullptr;
  261. Button *members_overview_alphabeta_sort_button = nullptr;
  262. bool members_overview_enabled;
  263. ItemList *help_overview = nullptr;
  264. bool help_overview_enabled;
  265. VSplitContainer *list_split = nullptr;
  266. TabContainer *tab_container = nullptr;
  267. EditorFileDialog *file_dialog = nullptr;
  268. AcceptDialog *error_dialog = nullptr;
  269. ConfirmationDialog *erase_tab_confirm = nullptr;
  270. ScriptCreateDialog *script_create_dialog = nullptr;
  271. Button *scripts_visible = nullptr;
  272. FindReplaceBar *find_replace_bar = nullptr;
  273. String current_theme;
  274. float zoom_factor = 1.0f;
  275. TextureRect *script_icon = nullptr;
  276. Label *script_name_label = nullptr;
  277. Button *script_back = nullptr;
  278. Button *script_forward = nullptr;
  279. FindInFilesDialog *find_in_files_dialog = nullptr;
  280. FindInFilesPanel *find_in_files = nullptr;
  281. Button *find_in_files_button = nullptr;
  282. WindowWrapper *window_wrapper = nullptr;
  283. enum {
  284. SCRIPT_EDITOR_FUNC_MAX = 32,
  285. };
  286. static int script_editor_func_count;
  287. static CreateScriptEditorFunc script_editor_funcs[SCRIPT_EDITOR_FUNC_MAX];
  288. Vector<Ref<EditorSyntaxHighlighter>> syntax_highlighters;
  289. struct ScriptHistory {
  290. Control *control = nullptr;
  291. Variant state;
  292. };
  293. Vector<ScriptHistory> history;
  294. int history_pos;
  295. List<String> previous_scripts;
  296. List<int> script_close_queue;
  297. void _tab_changed(int p_which);
  298. void _menu_option(int p_option);
  299. void _theme_option(int p_option);
  300. void _show_save_theme_as_dialog();
  301. bool _has_docs_tab() const;
  302. bool _has_script_tab() const;
  303. void _prepare_file_menu();
  304. void _file_menu_closed();
  305. Tree *disk_changed_list = nullptr;
  306. ConfirmationDialog *disk_changed = nullptr;
  307. bool restoring_layout;
  308. void _resave_scripts(const String &p_str);
  309. bool _test_script_times_on_disk(Ref<Resource> p_for_script = Ref<Resource>());
  310. void _add_recent_script(const String &p_path);
  311. void _update_recent_scripts();
  312. void _open_recent_script(int p_idx);
  313. void _show_error_dialog(const String &p_path);
  314. void _close_tab(int p_idx, bool p_save = true, bool p_history_back = true);
  315. void _update_find_replace_bar();
  316. void _close_current_tab(bool p_save = true, bool p_history_back = true);
  317. void _close_discard_current_tab(const String &p_str);
  318. void _close_docs_tab();
  319. void _close_other_tabs();
  320. void _close_all_tabs();
  321. void _queue_close_tabs();
  322. void _copy_script_path();
  323. void _copy_script_uid();
  324. void _ask_close_current_unsaved_tab(ScriptEditorBase *current);
  325. bool grab_focus_block;
  326. bool pending_auto_reload;
  327. bool auto_reload_running_scripts;
  328. bool reload_all_scripts = false;
  329. Vector<String> script_paths_to_reload;
  330. void _live_auto_reload_running_scripts();
  331. void _update_selected_editor_menu();
  332. EditorScriptCodeCompletionCache *completion_cache = nullptr;
  333. void _editor_stop();
  334. int edit_pass;
  335. void _add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args);
  336. void _res_saved_callback(const Ref<Resource> &p_res);
  337. void _scene_saved_callback(const String &p_path);
  338. void _mark_built_in_scripts_as_saved(const String &p_parent_path);
  339. bool open_textfile_after_create = true;
  340. bool trim_trailing_whitespace_on_save;
  341. bool trim_final_newlines_on_save;
  342. bool convert_indent_on_save;
  343. bool external_editor_active;
  344. void _goto_script_line2(int p_line);
  345. void _goto_script_line(Ref<RefCounted> p_script, int p_line);
  346. void _set_execution(Ref<RefCounted> p_script, int p_line);
  347. void _clear_execution(Ref<RefCounted> p_script);
  348. String _get_debug_tooltip(const String &p_text, Node *p_se);
  349. void _breaked(bool p_breaked, bool p_can_debug);
  350. void _script_created(Ref<Script> p_script);
  351. void _set_breakpoint(Ref<RefCounted> p_script, int p_line, bool p_enabled);
  352. void _clear_breakpoints();
  353. Array _get_cached_breakpoints_for_script(const String &p_path) const;
  354. ScriptEditorBase *_get_current_editor() const;
  355. TypedArray<ScriptEditorBase> _get_open_script_editors() const;
  356. Ref<ConfigFile> script_editor_cache;
  357. void _save_editor_state(ScriptEditorBase *p_editor);
  358. void _save_layout();
  359. void _editor_settings_changed();
  360. void _apply_editor_settings();
  361. void _filesystem_changed();
  362. void _files_moved(const String &p_old_file, const String &p_new_file);
  363. void _file_removed(const String &p_file);
  364. void _autosave_scripts();
  365. void _update_autosave_timer();
  366. void _reload_scripts(bool p_refresh_only = false);
  367. void _update_members_overview_visibility();
  368. void _update_members_overview();
  369. void _toggle_members_overview_alpha_sort(bool p_alphabetic_sort);
  370. void _filter_scripts_text_changed(const String &p_newtext);
  371. void _filter_methods_text_changed(const String &p_newtext);
  372. void _update_script_names();
  373. bool _sort_list_on_update;
  374. void _members_overview_selected(int p_idx);
  375. void _script_selected(int p_idx);
  376. void _update_help_overview_visibility();
  377. void _update_help_overview();
  378. void _help_overview_selected(int p_idx);
  379. void _update_online_doc();
  380. void _find_scripts(Node *p_base, Node *p_current, HashSet<Ref<Script>> &used);
  381. void _tree_changed();
  382. void _split_dragged(float);
  383. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  384. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  385. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  386. virtual void input(const Ref<InputEvent> &p_event) override;
  387. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  388. void _script_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index);
  389. void _make_script_list_context_menu();
  390. void _help_search(const String &p_text);
  391. void _history_forward();
  392. void _history_back();
  393. bool waiting_update_names;
  394. bool lock_history = false;
  395. void _help_class_open(const String &p_class);
  396. void _help_class_goto(const String &p_desc);
  397. bool _help_tab_goto(const String &p_name, const String &p_desc);
  398. void _update_history_arrows();
  399. void _save_history();
  400. void _save_previous_state(Dictionary p_state);
  401. void _go_to_tab(int p_idx);
  402. void _update_history_pos(int p_new_pos);
  403. void _update_script_colors();
  404. void _update_modified_scripts_for_external_editor(Ref<Script> p_for_script = Ref<Script>());
  405. void _script_changed();
  406. int file_dialog_option;
  407. void _file_dialog_action(const String &p_file);
  408. Ref<Script> _get_current_script();
  409. TypedArray<Script> _get_open_scripts() const;
  410. HashSet<String> textfile_extensions;
  411. Ref<TextFile> _load_text_file(const String &p_path, Error *r_error) const;
  412. Error _save_text_file(Ref<TextFile> p_text_file, const String &p_path);
  413. void _on_find_in_files_requested(const String &text);
  414. void _on_replace_in_files_requested(const String &text);
  415. void _on_find_in_files_result_selected(const String &fpath, int line_number, int begin, int end);
  416. void _start_find_in_files(bool with_replace);
  417. void _on_find_in_files_modified_files(const PackedStringArray &paths);
  418. void _on_find_in_files_close_button_clicked();
  419. void _set_zoom_factor(float p_zoom_factor);
  420. void _window_changed(bool p_visible);
  421. static void _open_script_request(const String &p_path);
  422. void _close_builtin_scripts_from_scene(const String &p_scene);
  423. static ScriptEditor *script_editor;
  424. protected:
  425. void _notification(int p_what);
  426. static void _bind_methods();
  427. public:
  428. static ScriptEditor *get_singleton() { return script_editor; }
  429. bool toggle_scripts_panel();
  430. bool is_scripts_panel_toggled();
  431. void apply_scripts() const;
  432. void reload_scripts(bool p_refresh_only = false);
  433. void open_script_create_dialog(const String &p_base_name, const String &p_base_path);
  434. void open_text_file_create_dialog(const String &p_base_path, const String &p_base_name = "");
  435. Ref<Resource> open_file(const String &p_file);
  436. void ensure_select_current();
  437. bool is_editor_floating();
  438. _FORCE_INLINE_ bool edit(const Ref<Resource> &p_resource, bool p_grab_focus = true) { return edit(p_resource, -1, 0, p_grab_focus); }
  439. bool edit(const Ref<Resource> &p_resource, int p_line, int p_col, bool p_grab_focus = true);
  440. Vector<String> _get_breakpoints();
  441. void get_breakpoints(List<String> *p_breakpoints);
  442. PackedStringArray get_unsaved_scripts() const;
  443. void save_current_script();
  444. void save_all_scripts();
  445. void set_window_layout(Ref<ConfigFile> p_layout);
  446. void get_window_layout(Ref<ConfigFile> p_layout);
  447. void set_scene_root_script(Ref<Script> p_script);
  448. Vector<Ref<Script>> get_open_scripts() const;
  449. bool script_goto_method(Ref<Script> p_script, const String &p_method);
  450. virtual void edited_scene_changed();
  451. void notify_script_close(const Ref<Script> &p_script);
  452. void notify_script_changed(const Ref<Script> &p_script);
  453. void goto_help(const String &p_desc) { _help_class_goto(p_desc); }
  454. void update_doc(const String &p_name);
  455. void clear_docs_from_script(const Ref<Script> &p_script);
  456. void update_docs_from_script(const Ref<Script> &p_script);
  457. void trigger_live_script_reload(const String &p_script_path);
  458. void trigger_live_script_reload_all();
  459. bool can_take_away_focus() const;
  460. VSplitContainer *get_left_list_split() { return list_split; }
  461. void set_live_auto_reload_running_scripts(bool p_enabled);
  462. void register_syntax_highlighter(const Ref<EditorSyntaxHighlighter> &p_syntax_highlighter);
  463. void unregister_syntax_highlighter(const Ref<EditorSyntaxHighlighter> &p_syntax_highlighter);
  464. static void register_create_script_editor_function(CreateScriptEditorFunc p_func);
  465. ScriptEditor(WindowWrapper *p_wrapper);
  466. ~ScriptEditor();
  467. };
  468. class ScriptEditorPlugin : public EditorPlugin {
  469. GDCLASS(ScriptEditorPlugin, EditorPlugin);
  470. ScriptEditor *script_editor = nullptr;
  471. WindowWrapper *window_wrapper = nullptr;
  472. String last_editor;
  473. void _focus_another_editor();
  474. void _save_last_editor(const String &p_editor);
  475. void _window_visibility_changed(bool p_visible);
  476. protected:
  477. void _notification(int p_what);
  478. public:
  479. virtual String get_plugin_name() const override { return "Script"; }
  480. bool has_main_screen() const override { return true; }
  481. virtual void edit(Object *p_object) override;
  482. virtual bool handles(Object *p_object) const override;
  483. virtual void make_visible(bool p_visible) override;
  484. virtual void selected_notify() override;
  485. virtual String get_unsaved_status(const String &p_for_scene) const override;
  486. virtual void save_external_data() override;
  487. virtual void apply_changes() override;
  488. virtual void set_window_layout(Ref<ConfigFile> p_layout) override;
  489. virtual void get_window_layout(Ref<ConfigFile> p_layout) override;
  490. virtual void get_breakpoints(List<String> *p_breakpoints) override;
  491. virtual void edited_scene_changed() override;
  492. ScriptEditorPlugin();
  493. ~ScriptEditorPlugin();
  494. };
  495. #endif // SCRIPT_EDITOR_PLUGIN_H