From cc1b2b95f742bfc4b314168cedfd4a8f601dc6c2 Mon Sep 17 00:00:00 2001 From: Conor Byrne <71222289+cbyrneee@users.noreply.github.com> Date: Mon, 27 Dec 2021 19:36:40 +0000 Subject: [PATCH] HackStudio: Ask to create a non-existent directory when making a project Previously, if the parent directory didn't exist when making a project, it would say that the creation directory was 'invalid' which isn't necessarily true. This patch prompts the user to ask if they would like to create the parent directory when creating a project, instead of treating it as an 'invalid' directory. --- .../HackStudio/Dialogs/NewProjectDialog.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp b/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp index 212aaf81aa..24af69e911 100644 --- a/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp +++ b/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp @@ -154,9 +154,6 @@ Optional NewProjectDialog::get_available_project_name() if (!s_project_name_validity_regex.has_match(chosen_name)) return {}; - if (!Core::File::exists(create_in) || !Core::File::is_directory(create_in)) - return {}; - // Check for up-to 999 variations of the project name, in case it's already taken for (int i = 0; i < 1000; i++) { auto candidate = (i == 0) @@ -200,6 +197,19 @@ void NewProjectDialog::do_create_project() return; } + auto create_in = m_create_in_input->text(); + if (!Core::File::exists(create_in) || !Core::File::is_directory(create_in)) { + auto result = GUI::MessageBox::show(this, String::formatted("The directory {} does not exist yet, would you like to create it?", create_in), "New project", GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo); + if (result != GUI::MessageBox::ExecResult::ExecYes) + return; + + auto created = Core::File::ensure_parent_directories(maybe_project_full_path.value()); + if (!created) { + GUI::MessageBox::show_error(this, String::formatted("Could not create directory {}", create_in)); + return; + } + } + auto creation_result = project_template->create_project(maybe_project_name.value(), maybe_project_full_path.value()); if (!creation_result.is_error()) { // Successfully created, attempt to open the new project