1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 07:37:44 +00:00

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.
This commit is contained in:
Andreas Kling 2021-05-20 20:42:09 +02:00
parent 3773e72752
commit 9b9966b63b

View file

@ -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);
}