diff --git a/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp b/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp index 212aaf81aa6..24af69e9114 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