diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-11-16 10:19:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 10:19:07 +0100 |
commit | 31f8616e6c54657eb71bac02b2af9c08a0a9f7f0 (patch) | |
tree | 45f616125fce0ddd60ca5323f1586cfc9153a387 | |
parent | dc06ee15b750b9c887f83ffc1b9d4a39806af947 (diff) | |
parent | 46fdca4faecc5d32f1c7f7a0b2e873c5a0148ba9 (diff) |
Merge pull request #42526 from aaronfranke/project-in-non-empty
Allow creating projects in non-empty folders with a confirmation popup
-rw-r--r-- | editor/project_manager.cpp | 36 | ||||
-rw-r--r-- | editor/project_manager.h | 1 |
2 files changed, 28 insertions, 9 deletions
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index e3c2ba83f2..b67a134549 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -61,6 +61,7 @@ class ProjectDialog : public ConfirmationDialog { GDCLASS(ProjectDialog, ConfirmationDialog); public: + bool is_folder_empty = true; enum Mode { MODE_NEW, MODE_IMPORT, @@ -218,7 +219,7 @@ private: // check if the specified install folder is empty, even though this is not an error, it is good to check here d->list_dir_begin(); - bool is_empty = true; + is_folder_empty = true; String n = d->get_next(); while (n != String()) { if (!n.begins_with(".")) { @@ -226,14 +227,14 @@ private: // and hidden files/folders to be present. // For instance, this lets users initialize a Git repository // and still be able to create a project in the directory afterwards. - is_empty = false; + is_folder_empty = false; break; } n = d->get_next(); } d->list_dir_end(); - if (!is_empty) { + if (!is_folder_empty) { set_message(TTR("Please choose an empty folder."), MESSAGE_WARNING, INSTALL_PATH); memdelete(d); get_ok()->set_disabled(true); @@ -258,7 +259,7 @@ private: } else { // check if the specified folder is empty, even though this is not an error, it is good to check here d->list_dir_begin(); - bool is_empty = true; + is_folder_empty = true; String n = d->get_next(); while (n != String()) { if (!n.begins_with(".")) { @@ -266,18 +267,18 @@ private: // and hidden files/folders to be present. // For instance, this lets users initialize a Git repository // and still be able to create a project in the directory afterwards. - is_empty = false; + is_folder_empty = false; break; } n = d->get_next(); } d->list_dir_end(); - if (!is_empty) { - set_message(TTR("Please choose an empty folder."), MESSAGE_ERROR); + if (!is_folder_empty) { + set_message(TTR("The selected path is not empty. Choosing an empty folder is highly recommended."), MESSAGE_WARNING); memdelete(d); - get_ok()->set_disabled(true); - return ""; + get_ok()->set_disabled(false); + return valid_path; } } @@ -416,6 +417,11 @@ private: } } + void _nonempty_confirmation_ok_pressed() { + is_folder_empty = true; + ok_pressed(); + } + void ok_pressed() override { String dir = project_path->get_text(); @@ -454,6 +460,18 @@ private: } else { if (mode == MODE_NEW) { + // Before we create a project, check that the target folder is empty. + // If not, we need to ask the user if they're sure they want to do this. + if (!is_folder_empty) { + ConfirmationDialog *cd = memnew(ConfirmationDialog); + cd->set_title(TTR("Warning: This folder is not empty")); + cd->set_text(TTR("You are about to create a Godot project in a non-empty folder.\nThe entire contents of this folder will be imported as project resources!\n\nAre you sure you wish to continue?")); + cd->get_ok()->connect("pressed", callable_mp(this, &ProjectDialog::_nonempty_confirmation_ok_pressed)); + get_parent()->add_child(cd); + cd->popup_centered(); + cd->grab_focus(); + return; + } ProjectSettings::CustomMap initial_settings; if (rasterizer_button_group->get_pressed_button()->get_meta("driver_name") == "Vulkan") { initial_settings["rendering/quality/driver/driver_name"] = "Vulkan"; diff --git a/editor/project_manager.h b/editor/project_manager.h index 407dba0c94..212d693f1d 100644 --- a/editor/project_manager.h +++ b/editor/project_manager.h @@ -98,6 +98,7 @@ class ProjectManager : public Control { void _restart_confirm(); void _exit_dialog(); void _confirm_update_settings(); + void _nonempty_confirmation_ok_pressed(); void _load_recent_projects(); void _on_project_created(const String &dir); |