From 9b9966b63bcf0d22dae3044bea30d9640038b9a1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 20 May 2021 20:42:09 +0200 Subject: [PATCH] LibGUI: Make GUI::FilePicker handle absolute paths better Some people apparently like to type in full absolute paths into the filename box of GUI::FilePicker. So let's handle that as you'd expect by using the full path as the selected path. --- Userland/Libraries/LibGUI/FilePicker.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index 4276f5a84b..77912d47d1 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -247,15 +247,18 @@ void FilePicker::model_did_update(unsigned) void FilePicker::on_file_return() { - LexicalPath path(String::formatted("{}/{}", m_model->root_path(), m_filename_textbox->text())); + auto path = m_filename_textbox->text(); + if (!path.starts_with('/')) { + path = LexicalPath::join(m_model->root_path(), path).string(); + } - if (Core::File::exists(path.string()) && m_mode == Mode::Save) { + if (Core::File::exists(path) && 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; } - m_selected_file = path.string(); + m_selected_file = path; done(ExecOK); }