From 54f6ac1854f33053565ba3eb246f08e4d54fcd13 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 20 May 2021 20:53:32 +0200 Subject: [PATCH] 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." --- Userland/Libraries/LibGUI/FilePicker.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index 77912d47d1..f914c97d35 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -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;