LibGUI: Don't mark "open" FilePicker as done if the file is not found

If you type in a filename that doesn't exist, show an error message
instead of closing the FilePicker "successfully."
This commit is contained in:
Andreas Kling 2021-05-20 20:53:32 +02:00
parent 9b9966b63b
commit 54f6ac1854
Notes: sideshowbarker 2024-07-18 17:42:13 +09:00

View file

@ -252,7 +252,14 @@ void FilePicker::on_file_return()
path = LexicalPath::join(m_model->root_path(), path).string();
}
if (Core::File::exists(path) && m_mode == Mode::Save) {
bool file_exists = Core::File::exists(path);
if (!file_exists && (m_mode == Mode::Open || m_mode == Mode::OpenFolder)) {
MessageBox::show(this, String::formatted("No such file or directory: {}", m_filename_textbox->text()), "File not found", MessageBox::Type::Error, MessageBox::InputType::OK);
return;
}
if (file_exists && m_mode == Mode::Save) {
auto result = MessageBox::show(this, "File already exists. Overwrite?", "Existing File", MessageBox::Type::Warning, MessageBox::InputType::OKCancel);
if (result == MessageBox::ExecCancel)
return;