Skip to content

Commit 00d8f5f

Browse files
committed
Ask before restarting project from settings
1 parent f42e612 commit 00d8f5f

File tree

2 files changed

+48
-43
lines changed

2 files changed

+48
-43
lines changed

editor/editor_node.cpp

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,45 +2057,7 @@ void EditorNode::try_autosave() {
20572057
}
20582058

20592059
void EditorNode::restart_editor(bool p_goto_project_manager) {
2060-
exiting = true;
2061-
2062-
if (project_run_bar->is_playing()) {
2063-
project_run_bar->stop_playing();
2064-
}
2065-
2066-
String to_reopen;
2067-
if (!p_goto_project_manager && get_tree()->get_edited_scene_root()) {
2068-
to_reopen = get_tree()->get_edited_scene_root()->get_scene_file_path();
2069-
}
2070-
2071-
_exit_editor(EXIT_SUCCESS);
2072-
2073-
List<String> args;
2074-
for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL)) {
2075-
args.push_back(a);
2076-
}
2077-
2078-
if (p_goto_project_manager) {
2079-
args.push_back("--project-manager");
2080-
2081-
// Setup working directory.
2082-
const String exec_dir = OS::get_singleton()->get_executable_path().get_base_dir();
2083-
if (!exec_dir.is_empty()) {
2084-
args.push_back("--path");
2085-
args.push_back(exec_dir);
2086-
}
2087-
} else {
2088-
args.push_back("--path");
2089-
args.push_back(ProjectSettings::get_singleton()->get_resource_path());
2090-
2091-
args.push_back("-e");
2092-
}
2093-
2094-
if (!to_reopen.is_empty()) {
2095-
args.push_back(to_reopen);
2096-
}
2097-
2098-
OS::get_singleton()->set_restart_on_exit(true, args);
2060+
_menu_option_confirm(p_goto_project_manager ? PROJECT_QUIT_TO_PROJECT_MANAGER : PROJECT_RELOAD_CURRENT_PROJECT, false);
20992061
}
21002062

21012063
void EditorNode::_save_all_scenes() {
@@ -3480,10 +3442,10 @@ void EditorNode::_discard_changes(const String &p_str) {
34803442

34813443
} break;
34823444
case PROJECT_QUIT_TO_PROJECT_MANAGER: {
3483-
restart_editor(true);
3445+
_restart_editor(true);
34843446
} break;
34853447
case PROJECT_RELOAD_CURRENT_PROJECT: {
3486-
restart_editor();
3448+
_restart_editor();
34873449
} break;
34883450
}
34893451
}
@@ -5508,11 +5470,11 @@ bool EditorNode::has_scenes_in_session() {
55085470
}
55095471

55105472
void EditorNode::undo() {
5511-
trigger_menu_option(FILE_UNDO, true);
5473+
_menu_option_confirm(FILE_UNDO, true);
55125474
}
55135475

55145476
void EditorNode::redo() {
5515-
trigger_menu_option(FILE_REDO, true);
5477+
_menu_option_confirm(FILE_REDO, true);
55165478
}
55175479

55185480
bool EditorNode::ensure_main_scene(bool p_from_native) {
@@ -5680,6 +5642,48 @@ bool EditorNode::_is_closing_editor() const {
56805642
return tab_closing_menu_option == FILE_QUIT || tab_closing_menu_option == PROJECT_QUIT_TO_PROJECT_MANAGER || tab_closing_menu_option == PROJECT_RELOAD_CURRENT_PROJECT;
56815643
}
56825644

5645+
void EditorNode::_restart_editor(bool p_goto_project_manager) {
5646+
exiting = true;
5647+
5648+
if (project_run_bar->is_playing()) {
5649+
project_run_bar->stop_playing();
5650+
}
5651+
5652+
String to_reopen;
5653+
if (!p_goto_project_manager && get_tree()->get_edited_scene_root()) {
5654+
to_reopen = get_tree()->get_edited_scene_root()->get_scene_file_path();
5655+
}
5656+
5657+
_exit_editor(EXIT_SUCCESS);
5658+
5659+
List<String> args;
5660+
for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL)) {
5661+
args.push_back(a);
5662+
}
5663+
5664+
if (p_goto_project_manager) {
5665+
args.push_back("--project-manager");
5666+
5667+
// Setup working directory.
5668+
const String exec_dir = OS::get_singleton()->get_executable_path().get_base_dir();
5669+
if (!exec_dir.is_empty()) {
5670+
args.push_back("--path");
5671+
args.push_back(exec_dir);
5672+
}
5673+
} else {
5674+
args.push_back("--path");
5675+
args.push_back(ProjectSettings::get_singleton()->get_resource_path());
5676+
5677+
args.push_back("-e");
5678+
}
5679+
5680+
if (!to_reopen.is_empty()) {
5681+
args.push_back(to_reopen);
5682+
}
5683+
5684+
OS::get_singleton()->set_restart_on_exit(true, args);
5685+
}
5686+
56835687
void EditorNode::_scene_tab_closed(int p_tab) {
56845688
current_menu_option = SCENE_TAB_CLOSE;
56855689
tab_closing_idx = p_tab;

editor/editor_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ class EditorNode : public Node {
624624

625625
void _proceed_closing_scene_tabs();
626626
bool _is_closing_editor() const;
627+
void _restart_editor(bool p_goto_project_manager = false);
627628

628629
Dictionary _get_main_scene_state();
629630
void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);

0 commit comments

Comments
 (0)