script_editor_plugin.h 22 KB

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