diff options
author | Karol Kosek <krkk@krkk.ct8.pl> | 2021-09-01 21:12:59 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-01 23:01:18 +0200 |
commit | 848c4fc43dd7588ed666f4891d90716bbd7f7417 (patch) | |
tree | ff2d6f2aea4db4bceada8d00e778e416235c7713 | |
parent | 14c30af7d839cd9561cf5273ca6d5aa14595c3c6 (diff) | |
download | serenity-848c4fc43dd7588ed666f4891d90716bbd7f7417.zip |
LibGUI: Show an error message box in the FilePicker on no permissions
The first attempt in #9037 used a special label as a view, if it wanted
to communicate any kind of error, but that sure did look a bit ugly.
Here, we are just showing a message box right before setting the new
path as:
- the contents of the previous directory will be visible in background,
which I find pretty nice, and
- I don't have to deal with adding a path history vector to reopen
the previous directory (which might not even exist then). :^)
-rw-r--r-- | Userland/Libraries/LibGUI/FilePicker.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index 8fa5f74d81..8b696e1954 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -27,6 +27,7 @@ #include <LibGfx/FontDatabase.h> #include <LibGfx/Palette.h> #include <string.h> +#include <unistd.h> namespace GUI { @@ -291,6 +292,13 @@ void FilePicker::on_file_return() void FilePicker::set_path(const String& path) { + if (access(path.characters(), R_OK | X_OK) == -1) { + GUI::MessageBox::show(this, String::formatted("Could not open '{}':\n{}", path, strerror(errno)), "Error", GUI::MessageBox::Type::Error); + for (auto location_button : m_common_location_buttons) + location_button.button.set_checked(m_model->root_path() == location_button.path); + return; + } + auto new_path = LexicalPath(path).string(); m_location_textbox->set_icon(FileIconProvider::icon_for_path(new_path).bitmap_for_size(16)); m_model->set_root_path(new_path); |