Debian Codegraph @

editor/editor_node.h

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_node.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
31 #pragma once
32
33 #include "core/object/script_language.h"
34 #include "core/templates/safe_refcount.h"
35 #include "editor/editor_data.h"
36 #include "editor/plugins/editor_plugin.h"
37 #include "editor/settings/editor_folding.h"
38
39 typedef void (*EditorNodeInitCallback)();
40 typedef void (*EditorPluginInitializeCallback)();
41 typedef bool (*EditorBuildCallback)();
42
43 class AcceptDialog;
44 class ColorPicker;
45 class ConfirmationDialog;
46 class Control;
47 class FileDialog;
48 class HBoxContainer;
49 class ImageTexture;
50 class MenuBar;
51 class MenuButton;
52 class OptionButton;
53 class Panel;
54 class PanelContainer;
55 class RichTextLabel;
56 class SubViewport;
57 class TextureProgressBar;
58 class Timer;
59 class Translation;
60 class Tree;
61 class VBoxContainer;
62 class VSplitContainer;
63 class Window;
64
65 class AudioStreamImportSettingsDialog;
66 class AudioStreamPreviewGenerator;
67 class BackgroundProgress;
68 class DependencyErrorDialog;
69 class DockSplitContainer;
70 class DynamicFontImportSettingsDialog;
71 class EditorAbout;
72 class EditorBuildProfileManager;
73 class EditorBottomPanel;
74 class EditorCommandPalette;
75 class EditorDockManager;
76 class EditorExport;
77 class EditorExportPreset;
78 class EditorFeatureProfileManager;
79 class EditorFileDialog;
80 class EditorFolding;
81 class EditorLayoutsDialog;
82 class EditorLog;
83 class EditorMainScreen;
84 class EditorNativeShaderSourceVisualizer;
85 class EditorPluginList;
86 class EditorResourcePreview;
87 class EditorResourceConversionPlugin;
88 class EditorRunBar;
89 class EditorSceneTabs;
90 class EditorSelectionHistory;
91 class EditorSettingsDialog;
92 class EditorTitleBar;
93 class ExportTemplateManager;
94 class EditorQuickOpenDialog;
95 class FBXImporterManager;
96 class FileSystemDock;
97 class HistoryDock;
98 class OrphanResourcesDialog;
99 class ProgressDialog;
100 class ProjectExportDialog;
101 class ProjectSettingsEditor;
102 class SceneImportSettingsDialog;
103 class ProjectUpgradeTool;
104
105 #ifdef ANDROID_ENABLED
106 class TouchActionsPanel;
107 #endif
108
109 struct EditorProgress {
110 String task;
111 bool force_background = false;
112 bool step(const String &p_state, int p_step = -1, bool p_force_refresh = true);
113
114 EditorProgress(const String &p_task, const String &p_label, int p_amount, bool p_can_cancel = false, bool p_force_background = false);
115 ~EditorProgress();
116 };
117
118 class EditorNode : public Node {
119 GDCLASS(EditorNode, Node);
120
121 public:
122 enum SceneNameCasing {
123 SCENE_NAME_CASING_AUTO,
124 SCENE_NAME_CASING_PASCAL_CASE,
125 SCENE_NAME_CASING_SNAKE_CASE,
126 SCENE_NAME_CASING_KEBAB_CASE,
127 SCENE_NAME_CASING_CAMEL_CASE,
128 };
129
130 enum ActionOnPlay {
131 ACTION_ON_PLAY_DO_NOTHING,
132 ACTION_ON_PLAY_OPEN_OUTPUT,
133 ACTION_ON_PLAY_OPEN_DEBUGGER,
134 };
135
136 enum ActionOnStop {
137 ACTION_ON_STOP_DO_NOTHING,
138 ACTION_ON_STOP_CLOSE_BUTTOM_PANEL,
139 };
140
141 enum MenuOptions {
142 // Scene menu.
143 SCENE_NEW_SCENE,
144 SCENE_NEW_INHERITED_SCENE,
145 SCENE_OPEN_SCENE,
146 SCENE_OPEN_PREV,
147 SCENE_OPEN_RECENT,
148 SCENE_SAVE_SCENE,
149 SCENE_SAVE_AS_SCENE,
150 SCENE_SAVE_ALL_SCENES,
151 SCENE_MULTI_SAVE_AS_SCENE,
152 SCENE_QUICK_OPEN,
153 SCENE_QUICK_OPEN_SCENE,
154 SCENE_QUICK_OPEN_SCRIPT,
155 SCENE_EXPORT_AS,
156 SCENE_UNDO,
157 SCENE_REDO,
158 SCENE_RELOAD_SAVED_SCENE,
159 SCENE_CLOSE,
160 SCENE_CLOSE_ALL,
161 SCENE_QUIT,
162
163 FILE_EXPORT_MESH_LIBRARY,
164
165 // Project menu.
166 PROJECT_OPEN_SETTINGS,
167 PROJECT_FIND_IN_FILES,
168 PROJECT_VERSION_CONTROL,
169 PROJECT_EXPORT,
170 PROJECT_PACK_AS_ZIP,
171 PROJECT_INSTALL_ANDROID_SOURCE,
172 PROJECT_OPEN_USER_DATA_FOLDER,
173 PROJECT_RELOAD_CURRENT_PROJECT,
174 PROJECT_QUIT_TO_PROJECT_MANAGER,
175
176 TOOLS_ORPHAN_RESOURCES,
177 TOOLS_BUILD_PROFILE_MANAGER,
178 TOOLS_PROJECT_UPGRADE,
179 TOOLS_CUSTOM,
180
181 VCS_METADATA,
182 VCS_SETTINGS,
183
184 // Editor menu.
185 EDITOR_OPEN_SETTINGS,
186 EDITOR_COMMAND_PALETTE,
187 EDITOR_TAKE_SCREENSHOT,
188 EDITOR_TOGGLE_FULLSCREEN,
189 EDITOR_OPEN_DATA_FOLDER,
190 EDITOR_OPEN_CONFIG_FOLDER,
191 EDITOR_MANAGE_FEATURE_PROFILES,
192 EDITOR_MANAGE_EXPORT_TEMPLATES,
193 EDITOR_CONFIGURE_FBX_IMPORTER,
194
195 LAYOUT_SAVE,
196 LAYOUT_DELETE,
197 LAYOUT_DEFAULT,
198
199 // Help menu.
200 HELP_SEARCH,
201 HELP_DOCS,
202 HELP_FORUM,
203 HELP_COMMUNITY,
204 HELP_COPY_SYSTEM_INFO,
205 HELP_REPORT_A_BUG,
206 HELP_SUGGEST_A_FEATURE,
207 HELP_SEND_DOCS_FEEDBACK,
208 HELP_ABOUT,
209 HELP_SUPPORT_GODOT_DEVELOPMENT,
210
211 // Update spinner menu.
212 SPINNER_UPDATE_CONTINUOUSLY,
213 SPINNER_UPDATE_WHEN_CHANGED,
214 SPINNER_UPDATE_SPINNER_HIDE,
215
216 // Non-menu options.
217 SCENE_TAB_CLOSE,
218 SCENE_TAB_SET_AS_MAIN_SCENE,
219 SAVE_AND_RUN,
220 SAVE_AND_RUN_MAIN_SCENE,
221 SAVE_AND_SET_MAIN_SCENE,
222 RESOURCE_SAVE,
223 RESOURCE_SAVE_AS,
224 SETTINGS_PICK_MAIN_SCENE,
225 };
226
227 struct ExecuteThreadArgs {
228 String path;
229 List<String> args;
230 String output;
231 Thread execute_output_thread;
232 Mutex execute_output_mutex;
233 int exitcode = 0;
234 SafeFlag done;
235 };
236
237 private:
238 friend class EditorSceneTabs;
239
240 enum {
241 MAX_INIT_CALLBACKS = 128,
242 MAX_BUILD_CALLBACKS = 128,
243 };
244
245 struct ExportDefer {
246 String preset;
247 String path;
248 bool debug = false;
249 bool pack_only = false;
250 bool android_build_template = false;
251 bool patch = false;
252 Vector<String> patches;
253 } export_defer;
254
255 static EditorNode *singleton;
256
257 EditorData editor_data;
258 EditorFolding editor_folding;
259 EditorSelectionHistory editor_history;
260
261 EditorCommandPalette *command_palette = nullptr;
262 EditorQuickOpenDialog *quick_open_dialog = nullptr;
263 EditorExport *editor_export = nullptr;
264 EditorLog *log = nullptr;
265 EditorNativeShaderSourceVisualizer *native_shader_source_visualizer = nullptr;
266 EditorPluginList *editor_plugins_force_input_forwarding = nullptr;
267 EditorPluginList *editor_plugins_force_over = nullptr;
268 EditorPluginList *editor_plugins_over = nullptr;
269 EditorQuickOpenDialog *quick_open_color_palette = nullptr;
270 EditorResourcePreview *resource_preview = nullptr;
271 EditorSelection *editor_selection = nullptr;
272 EditorSettingsDialog *editor_settings_dialog = nullptr;
273 HistoryDock *history_dock = nullptr;
274
275 ProjectExportDialog *project_export = nullptr;
276 ProjectSettingsEditor *project_settings_editor = nullptr;
277
278 FBXImporterManager *fbx_importer_manager = nullptr;
279
280 Vector<EditorPlugin *> editor_plugins;
281 bool _initializing_plugins = false;
282 HashMap<String, EditorPlugin *> addon_name_to_plugin;
283 LocalVector<String> pending_addons;
284 HashMap<ObjectID, HashSet<EditorPlugin *>> active_plugins;
285 bool is_main_screen_editing = false;
286
287 Control *gui_base = nullptr;
288 VBoxContainer *main_vbox = nullptr;
289 OptionButton *renderer = nullptr;
290
291 #ifdef ANDROID_ENABLED
292 VBoxContainer *base_vbox = nullptr; // It only contains the title_bar and main_hbox.
293 HBoxContainer *main_hbox = nullptr; // It only contains the touch_actions_panel and main_vbox.
294 TouchActionsPanel *touch_actions_panel = nullptr;
295 void _touch_actions_panel_mode_changed();
296 #endif
297
298 ConfirmationDialog *video_restart_dialog = nullptr;
299
300 // Split containers.
301 DockSplitContainer *left_l_vsplit = nullptr;
302 DockSplitContainer *left_r_vsplit = nullptr;
303 DockSplitContainer *main_hsplit = nullptr;
304 DockSplitContainer *right_l_vsplit = nullptr;
305 DockSplitContainer *right_r_vsplit = nullptr;
306 DockSplitContainer *center_split = nullptr;
307
308 // Main tabs.
309 EditorSceneTabs *scene_tabs = nullptr;
310
311 int tab_closing_idx = 0;
312 List<String> tabs_to_close;
313 List<int> scenes_to_save_as;
314 int tab_closing_menu_option = -1;
315
316 bool exiting = false;
317 bool dimmed = false;
318
319 DisplayServer::WindowMode prev_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
320 int old_split_ofs = 0;
321 VSplitContainer *top_split = nullptr;
322 Control *vp_base = nullptr;
323
324 Label *project_title = nullptr;
325 Control *left_menu_spacer = nullptr;
326 Control *right_menu_spacer = nullptr;
327 EditorTitleBar *title_bar = nullptr;
328 EditorRunBar *project_run_bar = nullptr;
329 HBoxContainer *right_menu_hb = nullptr;
330
331 // Spacers to center 2D / 3D / Script buttons.
332 HBoxContainer *left_spacer = nullptr;
333 Control *right_spacer = nullptr;
334
335 Control *menu_btn_spacer = nullptr;
336 MenuButton *main_menu_button = nullptr;
337 MenuBar *main_menu_bar = nullptr;
338
339 PopupMenu *apple_menu = nullptr;
340 PopupMenu *file_menu = nullptr;
341 PopupMenu *project_menu = nullptr;
342 PopupMenu *debug_menu = nullptr;
343 PopupMenu *settings_menu = nullptr;
344 PopupMenu *help_menu = nullptr;
345 PopupMenu *tool_menu = nullptr;
346 PopupMenu *export_as_menu = nullptr;
347 Button *export_button = nullptr;
348
349 Timer *screenshot_timer = nullptr;
350
351 uint64_t started_timestamp = 0;
352
353 RichTextLabel *load_errors = nullptr;
354 AcceptDialog *load_error_dialog = nullptr;
355 bool load_errors_queued_to_display = false;
356
357 RichTextLabel *execute_outputs = nullptr;
358 AcceptDialog *execute_output_dialog = nullptr;
359
360 Ref<Theme> theme;
361
362 bool follow_system_theme = false;
363 bool use_system_accent_color = false;
364 bool last_dark_mode_state = false;
365 Color last_system_base_color = Color(0, 0, 0, 0);
366 Color last_system_accent_color = Color(0, 0, 0, 0);
367
368 PopupMenu *recent_scenes = nullptr;
369 String _recent_scene;
370 List<String> prev_closed_scenes;
371 String defer_load_scene;
372 Node *_last_instantiated_scene = nullptr;
373
374 ConfirmationDialog *confirmation = nullptr;
375 bool stop_project_confirmation = false;
376 Button *confirmation_button = nullptr;
377 ConfirmationDialog *save_confirmation = nullptr;
378 ConfirmationDialog *import_confirmation = nullptr;
379 ConfirmationDialog *pick_main_scene = nullptr;
380 ConfirmationDialog *open_project_settings = nullptr;
381 Button *select_current_scene_button = nullptr;
382 AcceptDialog *accept = nullptr;
383 AcceptDialog *save_accept = nullptr;
384 EditorAbout *about = nullptr;
385 AcceptDialog *warning = nullptr;
386 EditorPlugin *plugin_to_save = nullptr;
387
388 bool overridden_default_layout = false;
389 Ref<ConfigFile> default_layout;
390 PopupMenu *editor_layouts = nullptr;
391 EditorLayoutsDialog *layout_dialog = nullptr;
392
393 ConfirmationDialog *gradle_build_manage_templates = nullptr;
394 ConfirmationDialog *install_android_build_template = nullptr;
395 ConfirmationDialog *remove_android_build_template = nullptr;
396 Label *install_android_build_template_message = nullptr;
397 OptionButton *choose_android_export_profile = nullptr;
398 Ref<EditorExportPreset> android_export_preset;
399
400 PopupMenu *vcs_actions_menu = nullptr;
401 EditorFileDialog *file = nullptr;
402 ExportTemplateManager *export_template_manager = nullptr;
403 EditorFeatureProfileManager *feature_profile_manager = nullptr;
404 EditorBuildProfileManager *build_profile_manager = nullptr;
405 EditorFileDialog *file_templates = nullptr;
406 EditorFileDialog *file_export_lib = nullptr;
407 EditorFileDialog *file_android_build_source = nullptr;
408 EditorFileDialog *file_pack_zip = nullptr;
409 MenuButton *update_spinner = nullptr;
410
411 EditorMainScreen *editor_main_screen = nullptr;
412
413 AudioStreamPreviewGenerator *audio_preview_gen = nullptr;
414 ProgressDialog *progress_dialog = nullptr;
415 BackgroundProgress *progress_hb = nullptr;
416
417 DependencyErrorDialog *dependency_error = nullptr;
418 HashMap<String, HashSet<String>> dependency_errors;
419 OrphanResourcesDialog *orphan_resources = nullptr;
420 ConfirmationDialog *open_imported = nullptr;
421 Button *new_inherited_button = nullptr;
422 String open_import_request;
423
424 EditorDockManager *editor_dock_manager = nullptr;
425 Timer *editor_layout_save_delay_timer = nullptr;
426 Timer *scan_changes_timer = nullptr;
427 Button *distraction_free = nullptr;
428 Callable palette_file_selected_callback;
429
430 EditorBottomPanel *bottom_panel = nullptr;
431
432 Tree *disk_changed_list = nullptr;
433 LocalVector<String> disk_changed_scenes;
434 bool disk_changed_project = false;
435 ConfirmationDialog *disk_changed = nullptr;
436 ConfirmationDialog *project_data_missing = nullptr;
437
438 bool scene_distraction_free = false;
439 bool script_distraction_free = false;
440
441 bool changing_scene = false;
442 bool cmdline_mode = false;
443 bool convert_old = false;
444 bool immediate_dialog_confirmed = false;
445 bool restoring_scenes = false;
446 bool settings_overrides_changed = false;
447 bool unsaved_cache = false;
448
449 bool requested_first_scan = false;
450 bool waiting_for_first_scan = true;
451 bool load_editor_layout_done = false;
452
453 bool select_current_scene_file_requested = false;
454
455 HashSet<Ref<Translation>> tracked_translations;
456 bool pending_translation_notification = false;
457
458 int current_menu_option = 0;
459
460 SubViewport *scene_root = nullptr; // Root of the scene being edited.
461
462 Ref<Resource> saving_resource;
463 HashSet<Ref<Resource>> saving_resources_in_path;
464 HashMap<Ref<Resource>, List<Node *>> resource_count; // Keeps track of linked Resources from a Scene.
465
466 uint64_t update_spinner_step_msec = 0;
467 uint64_t update_spinner_step_frame = 0;
468 int update_spinner_step = 0;
469
470 String saving_scene;
471 EditorProgress *save_scene_progress = nullptr;
472
473 DynamicFontImportSettingsDialog *fontdata_import_settings = nullptr;
474 SceneImportSettingsDialog *scene_import_settings = nullptr;
475 AudioStreamImportSettingsDialog *audio_stream_import_settings = nullptr;
476
477 HashSet<String> force_textfile_extensions;
478 HashSet<String> textfile_extensions;
479 HashSet<String> other_file_extensions;
480 HashSet<FileDialog *> file_dialogs;
481
482 Vector<Ref<EditorResourceConversionPlugin>> resource_conversion_plugins;
483 PrintHandlerList print_handler;
484
485 HashMap<String, Ref<Texture2D>> icon_type_cache;
486 HashMap<Pair<String, String>, Ref<Texture2D>> class_icon_cache;
487
488 ProjectUpgradeTool *project_upgrade_tool = nullptr;
489 bool run_project_upgrade_tool = false;
490
491 bool was_window_windowed_last = false;
492
493 bool unfocused_low_processor_usage_mode_enabled = true;
494
495 static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
496 static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
497 static int build_callback_count;
498 static int plugin_init_callback_count;
499 static Vector<EditorNodeInitCallback> _init_callbacks;
500
501 String _get_system_info() const;
502
503 bool _should_display_update_spinner() const;
504
505 static void _dependency_error_report(const String &p_path, const String &p_dep, const String &p_type) {
506 DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
507 if (!singleton->dependency_errors.has(p_path)) {
508 singleton->dependency_errors[p_path] = HashSet<String>();
509 }
510 singleton->dependency_errors[p_path].insert(p_dep + "::" + p_type);
511 }
512
513 static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
514 static Ref<Texture2D> _file_dialog_get_thumbnail(const String &p_path);
515 static void _file_dialog_thumbnail_callback(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, Ref<ImageTexture> p_texture);
516 Ref<ImageTexture> default_thumbnail;
517
518 static void _file_dialog_register(FileDialog *p_dialog);
519 static void _file_dialog_unregister(FileDialog *p_dialog);
520
521 static void _file_access_close_error_notify(const String &p_str);
522 static void _file_access_close_error_notify_impl(const String &p_str);
523
524 static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);
525 static void _print_handler_impl(const String &p_string, bool p_error, bool p_rich);
526 static void _resource_saved(Ref<Resource> p_resource, const String &p_path);
527 static void _resource_loaded(Ref<Resource> p_resource, const String &p_path);
528
529 void _update_theme(bool p_skip_creation = false);
530 void _build_icon_type_cache();
531 void _enable_pending_addons();
532
533 void _dialog_action(String p_file);
534
535 void _add_to_history(const Object *p_object, const String &p_property, bool p_inspector_only);
536 void _edit_current(bool p_skip_foreign = false, bool p_skip_inspector_update = false);
537 void _dialog_display_save_error(String p_file, Error p_error);
538 void _dialog_display_load_error(String p_file, Error p_error);
539
540 void _menu_option(int p_option);
541 void _menu_confirm_current();
542 void _menu_option_confirm(int p_option, bool p_confirmed);
543
544 void _android_build_source_selected(const String &p_file);
545 void _android_export_preset_selected(int p_index);
546 void _android_install_build_template();
547 void _android_explore_build_templates();
548
549 void _request_screenshot();
550 void _screenshot(bool p_use_utc = false);
551 void _save_screenshot(const String &p_path);
552 void _save_screenshot_with_embedded_process(int64_t p_w, int64_t p_h, const String &p_emb_path, const Rect2i &p_rect, const String &p_path);
553
554 void _check_system_theme_changed();
555
556 void _tool_menu_option(int p_idx);
557 void _export_as_menu_option(int p_idx);
558 void _update_file_menu_opened();
559 void _palette_quick_open_dialog();
560
561 void _remove_plugin_from_enabled(const String &p_name);
562 void _plugin_over_edit(EditorPlugin *p_plugin, Object *p_object);
563 void _plugin_over_self_own(EditorPlugin *p_plugin);
564
565 void _fs_changed();
566 void _resources_reimporting(const Vector<String> &p_resources);
567 void _resources_reimported(const Vector<String> &p_resources);
568 void _sources_changed(bool p_exist);
569 void _remove_lock_file();
570
571 void _node_renamed();
572 void _save_editor_states(const String &p_file, int p_idx = -1);
573 void _load_editor_plugin_states_from_config(const Ref<ConfigFile> &p_config_file);
574 void _update_title();
575 void _update_unsaved_cache();
576 void _version_control_menu_option(int p_idx);
577 void _close_messages();
578 void _show_messages();
579 void _vp_resized();
580 void _titlebar_resized();
581 void _viewport_resized();
582
583 void _update_undo_redo_allowed();
584
585 int _save_external_resources(bool p_also_save_external_data = false);
586 void _save_scene_silently();
587
588 void _set_current_scene(int p_idx);
589 void _set_current_scene_nocheck(int p_idx);
590 void _nav_to_selected_scene();
591 bool _validate_scene_recursive(const String &p_filename, Node *p_node);
592 void _save_scene(String p_file, int idx = -1);
593 void _save_all_scenes();
594 int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
595 void _discard_changes(const String &p_str = String());
596 void _scene_tab_closed(int p_tab);
597 void _cancel_close_scene_tab();
598 void _cancel_confirmation();
599
600 void _prepare_save_confirmation_popup();
601
602 void _inherit_request(String p_file);
603 void _instantiate_request(const Vector<String> &p_files);
604
605 void _quick_opened(const String &p_file_path);
606 void _open_command_palette();
607
608 void _project_run_started();
609 void _project_run_stopped();
610
611 void _update_prev_closed_scenes(const String &p_scene_path, bool p_add_scene);
612
613 void _add_to_recent_scenes(const String &p_scene);
614 void _update_recent_scenes();
615 void _open_recent_scene(int p_idx);
616
617 void _dropped_files(const Vector<String> &p_files);
618 void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path);
619
620 void _update_vsync_mode();
621 void _update_from_settings();
622 void _gdextensions_reloaded();
623 void _update_translations();
624 void _translation_resources_changed();
625 void _queue_translation_notification();
626 void _propagate_translation_notification();
627
628 void _renderer_selected(int p_index);
629 void _update_renderer_color();
630 String _to_rendering_method_display_name(const String &p_rendering_method) const;
631 void _set_renderer_name_save_and_restart(const String &p_rendering_method);
632
633 void _exit_editor(int p_exit_code);
634
635 virtual void input(const Ref<InputEvent> &p_event) override;
636 virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
637
638 bool has_main_screen() const { return true; }
639
640 void _remove_edited_scene(bool p_change_tab = true);
641 void _remove_scene(int index, bool p_change_tab = true);
642 bool _find_and_save_resource(Ref<Resource> p_res, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
643 bool _find_and_save_edited_subresources(Object *obj, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
644 void _save_edited_subresources(Node *scene, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
645 void _mark_unsaved_scenes();
646 bool _is_scene_unsaved(int p_idx);
647
648 void _find_node_types(Node *p_node, int &count_2d, int &count_3d);
649 void _save_scene_with_preview(String p_file, int p_idx = -1);
650 void _close_save_scene_progress();
651
652 bool _find_scene_in_use(Node *p_node, const String &p_path) const;
653
654 void _proceed_closing_scene_tabs();
655 void _proceed_save_asing_scene_tabs();
656 bool _is_closing_editor() const;
657 void _restart_editor(bool p_goto_project_manager = false);
658
659 Dictionary _get_main_scene_state();
660 void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
661
662 void _save_editor_layout();
663 void _load_editor_layout();
664
665 void _save_central_editor_layout_to_config(Ref<ConfigFile> p_config_file);
666 void _load_central_editor_layout_from_config(Ref<ConfigFile> p_config_file);
667
668 void _save_window_settings_to_config(Ref<ConfigFile> p_layout, const String &p_section);
669
670 void _save_open_scenes_to_config(Ref<ConfigFile> p_layout);
671 void _load_open_scenes_from_config(Ref<ConfigFile> p_layout);
672
673 void _update_layouts_menu();
674 void _layout_menu_option(int p_id);
675
676 void _update_addon_config();
677
678 void _toggle_distraction_free_mode();
679
680 void _inherit_imported(const String &p_action);
681 void _open_imported();
682
683 void _update_update_spinner();
684
685 void _resources_changed(const Vector<String> &p_resources);
686 void _scan_external_changes();
687 void _reload_modified_scenes();
688 void _reload_project_settings();
689 void _resave_externally_modified_scenes(String p_str);
690
691 void _feature_profile_changed();
692 bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
693
694 Ref<Texture2D> _get_class_or_script_icon(const String &p_class, const String &p_script_path, const String &p_fallback = "", bool p_fallback_script_to_theme = false, bool p_skip_fallback_virtual = false);
695
696 void _pick_main_scene_custom_action(const String &p_custom_action_name);
697
698 void _immediate_dialog_confirmed();
699
700 void _begin_first_scan();
701
702 void _notify_nodes_scene_reimported(Node *p_node, Array p_reimported_nodes);
703
704 void _remove_all_not_owned_children(Node *p_node, Node *p_owner);
705
706 void _progress_dialog_visibility_changed();
707 void _load_error_dialog_visibility_changed();
708
709 void _execute_upgrades();
710
711 bool _is_project_data_missing();
712
713 enum MenuType {
714 MENU_TYPE_NONE,
715 MENU_TYPE_GLOBAL,
716 MENU_TYPE_COMPACT,
717 MENU_TYPE_FULL,
718 };
719 MenuType menu_type = MENU_TYPE_NONE;
720 Vector<PopupMenu *> main_menu_items;
721
722 void _build_file_menu();
723 void _build_project_menu();
724 void _build_settings_menu();
725 void _build_help_menu();
726
727 void _update_main_menu_type();
728 void _add_to_main_menu(const String &p_name, PopupMenu *p_menu);
729
730 void _bottom_panel_resized();
731
732 protected:
733 friend class FileSystemDock;
734
735 static void _bind_methods();
736 void _notification(int p_what);
737
738 public:
739 // Public for use with callable_mp.
740 void init_plugins();
741 void _on_plugin_ready(Object *p_script, const String &p_activate_name);
742
743 bool call_build();
744 void call_run_scene(const String &p_scene, Vector<String> &r_args);
745
746 // This is a very naive estimation, but we need something now. Will be reworked later.
747 bool is_editor_ready() const { return is_inside_tree() && !waiting_for_first_scan; }
748
749 static EditorNode *get_singleton() { return singleton; }
750
751 static EditorLog *get_log() { return singleton->log; }
752 static EditorData &get_editor_data() { return singleton->editor_data; }
753 static EditorFolding &get_editor_folding() { return singleton->editor_folding; }
754
755 static EditorTitleBar *get_title_bar() { return singleton->title_bar; }
756 static VSplitContainer *get_top_split() { return singleton->top_split; }
757 static DockSplitContainer *get_center_split() { return singleton->center_split; }
758 static EditorBottomPanel *get_bottom_panel() { return singleton->bottom_panel; }
759 static EditorMainScreen *get_editor_main_screen() { return singleton->editor_main_screen; }
760
761 static Button *get_distraction_free_button() { return singleton->distraction_free; }
762
763 static String adjust_scene_name_casing(const String &p_root_name);
764 static String adjust_script_name_casing(const String &p_file_name, ScriptLanguage::ScriptNameCasing p_auto_casing);
765
766 static bool has_unsaved_changes() { return singleton->unsaved_cache; }
767 static void disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames);
768 static void add_io_error(const String &p_error);
769 static void add_io_warning(const String &p_warning);
770 static bool find_recursive_resources(const Variant &p_variant, HashSet<Resource *> &r_resources_found);
771
772 static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
773 static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
774 static void progress_end_task(const String &p_task);
775
776 static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
777 static void progress_task_step_bg(const String &p_task, int p_step = -1);
778 static void progress_end_task_bg(const String &p_task);
779
780 static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
781 static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
782
783 static void add_extension_editor_plugin(const StringName &p_class_name);
784 static void remove_extension_editor_plugin(const StringName &p_class_name);
785
786 static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
787 static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
788 static void add_build_callback(EditorBuildCallback p_callback);
789
790 static bool immediate_confirmation_dialog(const String &p_text, const String &p_ok_text = TTR("Ok"), const String &p_cancel_text = TTR("Cancel"), uint32_t p_wrap_width = 0);
791
792 static bool is_cmdline_mode();
793
794 static HashMap<String, Variant> get_initial_settings();
795
796 static void cleanup();
797
798 Ref<Texture2D> get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
799
800 EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
801 EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
802 EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
803 EditorSelection *get_editor_selection() { return editor_selection; }
804 EditorSelectionHistory *get_editor_selection_history() { return &editor_history; }
805
806 ProjectSettingsEditor *get_project_settings() { return project_settings_editor; }
807
808 void trigger_menu_option(int p_option, bool p_confirmed);
809 bool has_previous_closed_scenes() const;
810
811 void new_inherited_scene() { _menu_option_confirm(SCENE_NEW_INHERITED_SCENE, false); }
812
813 void update_distraction_free_mode();
814 void set_distraction_free_mode(bool p_enter);
815 bool is_distraction_free_mode_enabled() const;
816 void update_distraction_free_button_theme();
817
818 void set_center_split_offset(int p_offset);
819
820 void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
821 bool is_addon_plugin_enabled(const String &p_addon) const;
822
823 void edit_node(Node *p_node);
824 void edit_resource(const Ref<Resource> &p_resource);
825
826 void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
827 void save_resource(const Ref<Resource> &p_resource);
828 void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
829 bool is_resource_internal_to_scene(Ref<Resource> p_resource);
830 void gather_resources(const Variant &p_variant, List<Ref<Resource>> &r_list, HashSet<Object *> &r_scanned_objects, bool p_subresources = false, bool p_allow_external = false);
831 void update_resource_count(Node *p_node, bool p_remove = false);
832 void update_node_reference(const Variant &p_value, Node *p_node, bool p_remove = false);
833 void clear_node_reference(Ref<Resource> p_res);
834 int get_resource_count(Ref<Resource> p_res);
835 List<Node *> get_resource_node_list(Ref<Resource> p_res);
836
837 void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
838
839 void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
840 void push_item_no_inspector(Object *p_object);
841 void edit_previous_item();
842 void edit_item(Object *p_object, Object *p_editing_owner);
843 void push_node_item(Node *p_node);
844 void hide_unused_editors(const Object *p_editing_owner = nullptr);
845
846 void replace_resources_in_object(
847 Object *p_object,
848 const Vector<Ref<Resource>> &p_source_resources,
849 const Vector<Ref<Resource>> &p_target_resource);
850 void replace_resources_in_scenes(
851 const Vector<Ref<Resource>> &p_source_resources,
852 const Vector<Ref<Resource>> &p_target_resource);
853 void edit_foreign_resource(Ref<Resource> p_resource);
854
855 bool is_resource_read_only(Ref<Resource> p_resource, bool p_foreign_resources_are_writable = false);
856
857 String get_multiwindow_support_tooltip_text() const;
858
859 bool is_changing_scene() const;
860
861 SubViewport *get_scene_root() { return scene_root; } // Root of the scene being edited.
862
863 void set_edited_scene(Node *p_scene);
864 void set_edited_scene_root(Node *p_scene, bool p_auto_add);
865 Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
866
867 String get_preview_locale() const;
868 void set_preview_locale(const String &p_locale);
869
870 int new_scene();
871 Error load_scene(const String &p_scene, bool p_ignore_broken_deps = false, bool p_set_inherited = false, bool p_force_open_imported = false, bool p_silent_change_tab = false);
872 Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
873 Error load_scene_or_resource(const String &p_file, bool p_ignore_broken_deps = false, bool p_change_scene_tab_if_already_open = true);
874
875 HashMap<StringName, Variant> get_modified_properties_for_node(Node *p_node, bool p_node_references_only);
876 HashMap<StringName, Variant> get_modified_properties_reference_to_nodes(Node *p_node, List<Node *> &p_nodes_referenced_by);
877
878 void set_unfocused_low_processor_usage_mode_enabled(bool p_enabled);
879
880 struct AdditiveNodeEntry {
881 Node *node = nullptr;
882 NodePath parent;
883 Node *owner = nullptr;
884 int index = 0;
885 // Used if the original parent node is lost
886 Transform2D transform_2d;
887 Transform3D transform_3d;
888 };
889
890 struct ConnectionWithNodePath {
891 Connection connection;
892 NodePath node_path;
893 };
894
895 struct ModificationNodeEntry {
896 HashMap<StringName, Variant> property_table;
897 List<ConnectionWithNodePath> connections_to;
898 List<Connection> connections_from;
899 List<Node::GroupInfo> groups;
900 };
901
902 struct InstanceModificationsEntry {
903 Node *original_node;
904 String instance_path;
905 List<Node *> instance_list;
906 HashMap<NodePath, ModificationNodeEntry> modifications;
907 List<AdditiveNodeEntry> addition_list;
908 };
909
910 struct SceneModificationsEntry {
911 List<InstanceModificationsEntry> instance_list;
912 HashMap<NodePath, ModificationNodeEntry> other_instances_modifications;
913 };
914
915 struct SceneEditorDataEntry {
916 bool is_editable = false;
917 bool is_display_folded = false;
918 };
919
920 HashMap<int, SceneModificationsEntry> scenes_modification_table;
921 List<String> scenes_reimported;
922 List<String> resources_reimported;
923
924 void update_node_from_node_modification_entry(Node *p_node, ModificationNodeEntry &p_node_modification);
925
926 void get_scene_editor_data_for_node(Node *p_root, Node *p_node, HashMap<NodePath, SceneEditorDataEntry> &p_table);
927
928 void get_preload_scene_modification_table(
929 Node *p_edited_scene,
930 Node *p_reimported_root,
931 Node *p_node, InstanceModificationsEntry &p_instance_modifications);
932
933 void get_preload_modifications_reference_to_nodes(
934 Node *p_root,
935 Node *p_node,
936 HashSet<Node *> &p_excluded_nodes,
937 List<Node *> &p_instance_list_with_children,
938 HashMap<NodePath, ModificationNodeEntry> &p_modification_table);
939 void get_children_nodes(Node *p_node, List<Node *> &p_nodes);
940 bool is_additional_node_in_scene(Node *p_edited_scene, Node *p_reimported_root, Node *p_node);
941
942 void replace_history_reimported_nodes(Node *p_original_root_node, Node *p_new_root_node, Node *p_node);
943
944 bool is_scene_open(const String &p_path);
945 bool is_multi_window_enabled() const;
946
947 void setup_color_picker(ColorPicker *p_picker);
948
949 void request_instantiate_scene(const String &p_path);
950 void request_instantiate_scenes(const Vector<String> &p_files);
951
952 void set_convert_old_scene(bool p_old) { convert_old = p_old; }
953
954 void notify_all_debug_sessions_exited();
955
956 OS::ProcessID has_child_process(OS::ProcessID p_pid) const;
957 void stop_child_process(OS::ProcessID p_pid);
958
959 Ref<Theme> get_editor_theme() const { return theme; }
960 void update_preview_themes(int p_mode);
961
962 Ref<Script> get_object_custom_type_base(const Object *p_object) const;
963 StringName get_object_custom_type_name(const Object *p_object) const;
964 Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "");
965 Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "");
966
967 bool is_object_of_custom_type(const Object *p_object, const StringName &p_class);
968
969 void show_accept(const String &p_text, const String &p_title);
970 void show_save_accept(const String &p_text, const String &p_title);
971 void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));
972
973 void _copy_warning(const String &p_str);
974
975 Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template, bool p_patch, const Vector<String> &p_patches);
976 bool is_project_exporting() const;
977
978 Control *get_gui_base() { return gui_base; }
979
980 void save_scene_to_path(String p_file, bool p_with_preview = true) {
981 if (p_with_preview) {
982 _save_scene_with_preview(p_file);
983 } else {
984 _save_scene(p_file);
985 }
986 }
987
988 bool close_scene();
989
990 bool is_scene_in_use(const String &p_path);
991
992 void save_editor_layout_delayed();
993 void save_default_environment();
994
995 void open_export_template_manager();
996
997 void reload_scene(const String &p_path);
998
999 void find_all_instances_inheriting_path_in_node(Node *p_root, Node *p_node, const String &p_instance_path, HashSet<Node *> &p_instance_list);
1000 void preload_reimporting_with_path_in_edited_scenes(const List<String> &p_scenes);
1001 void reload_instances_with_path_in_edited_scenes();
1002
1003 bool is_exiting() const { return exiting; }
1004
1005 Dictionary drag_resource(const Ref<Resource> &p_res, Control *p_from);
1006 Dictionary drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
1007
1008 EditorQuickOpenDialog *get_quick_open_dialog() { return quick_open_dialog; }
1009
1010 void add_tool_menu_item(const String &p_name, const Callable &p_callback);
1011 void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
1012 void remove_tool_menu_item(const String &p_name);
1013
1014 PopupMenu *get_export_as_menu();
1015
1016 void save_all_scenes();
1017 void save_scene_if_open(const String &p_scene_path);
1018 void save_scene_list(const HashSet<String> &p_scene_paths);
1019 void save_before_run();
1020 void try_autosave();
1021 void restart_editor(bool p_goto_project_manager = false);
1022 void unload_editor_addons();
1023
1024 void open_setting_override(const String &p_property);
1025 void notify_settings_overrides_changed();
1026
1027 void dim_editor(bool p_dimming);
1028 bool is_editor_dimmed() const;
1029
1030 void edit_current() { _edit_current(); }
1031
1032 bool has_scenes_in_session();
1033
1034 void undo();
1035 void redo();
1036
1037 int execute_and_show_output(const String &p_title, const String &p_path, const List<String> &p_arguments, bool p_close_on_ok = true, bool p_close_on_errors = false, String *r_output = nullptr);
1038
1039 EditorNode();
1040 ~EditorNode();
1041
1042 void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
1043 void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
1044 Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_resource(const Ref<Resource> &p_for_resource);
1045 Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_type_name(const String &p_type);
1046
1047 bool ensure_main_scene(bool p_from_native);
1048 bool validate_custom_directory();
1049 void run_editor_script(const Ref<Script> &p_script);
1050 };
1051
1052 struct EditorProgressBG {
1053 String task;
1054 void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
1055 EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
1056 EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
1057 task = p_task;
1058 }
1059 ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
1060 };