diff options
author | Andreas Kling <kling@serenityos.org> | 2020-09-18 18:02:57 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-18 21:29:01 +0200 |
commit | 8075db683bc685408f3650a47158c84c0d89fb29 (patch) | |
tree | caa1ca70bf19f908edd68ac4592de3705d4eecec /Applications | |
parent | 9b893037670e16bd0b51b8cb7f4e0d30bb710413 (diff) | |
download | serenity-8075db683bc685408f3650a47158c84c0d89fb29.zip |
FileManager: Show an inline error message for inaccessible directories
Instead of popping up a message box whenever we can't read an opened
directory, show the error message inside the DirectoryView (as a label)
instead.
This fixes a visual inconsistency where an inaccessible directory would
be selected in the left-side treeview while the previous directory's
contents were still showing on the right.
This also makes keyboard navigation a bit more pleasant since you're
not suddenly interrupted by a message box.
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/FileManager/DirectoryView.cpp | 17 | ||||
-rw-r--r-- | Applications/FileManager/DirectoryView.h | 3 | ||||
-rw-r--r-- | Applications/FileManager/main.cpp | 8 |
3 files changed, 16 insertions, 12 deletions
diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp index 836851e70d..fcce7c178a 100644 --- a/Applications/FileManager/DirectoryView.cpp +++ b/Applications/FileManager/DirectoryView.cpp @@ -32,6 +32,7 @@ #include <LibCore/MimeData.h> #include <LibCore/StandardPaths.h> #include <LibGUI/InputBox.h> +#include <LibGUI/Label.h> #include <LibGUI/MessageBox.h> #include <LibGUI/SortingProxyModel.h> #include <serenity.h> @@ -135,6 +136,9 @@ DirectoryView::DirectoryView(Mode mode) setup_actions(); + m_error_label = add<GUI::Label>(); + m_error_label->set_font(m_error_label->font().bold_family_font()); + setup_model(); setup_icon_view(); @@ -155,15 +159,20 @@ void DirectoryView::setup_model() { m_model->set_root_path(Core::StandardPaths::desktop_directory()); - m_model->on_error = [this](int error, const char* error_string) { + m_model->on_error = [this](int, const char* error_string) { + auto failed_path = m_model->root_path(); bool quit = false; if (m_path_history.size()) open(m_path_history.at(m_path_history_position)); else quit = true; - if (on_error) - on_error(error, error_string, quit); + if (quit) + exit(1); + + auto error_message = String::format("Could not read %s:\n%s", failed_path.characters(), error_string); + m_error_label->set_text(error_message); + set_active_widget(m_error_label); }; m_model->on_complete = [this] { @@ -321,6 +330,8 @@ void DirectoryView::open(const StringView& path) model().update(); return; } + + set_active_widget(¤t_view()); model().set_root_path(path); } diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h index 4470e1bb52..e66a1f5fab 100644 --- a/Applications/FileManager/DirectoryView.h +++ b/Applications/FileManager/DirectoryView.h @@ -86,7 +86,6 @@ public: Function<void(const GUI::ModelIndex&, const GUI::ContextMenuEvent&)> on_context_menu_request; Function<void(const StringView&)> on_status_message; Function<void(int done, int total)> on_thumbnail_progress; - Function<void(int error, const char* error_string, bool quit)> on_error; enum ViewMode { Invalid, @@ -174,6 +173,8 @@ private: Vector<String> m_path_history; void add_path_to_history(const StringView& path); + RefPtr<GUI::Label> m_error_label; + RefPtr<GUI::TableView> m_table_view; RefPtr<GUI::IconView> m_icon_view; RefPtr<GUI::ColumnsView> m_columns_view; diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 66f6093434..7f09d0cb00 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -540,14 +540,6 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio open_parent_directory_action->set_enabled(new_path != "/"); }; - directory_view.on_error = [&](int, const char* error_string, bool quit) { - auto error_message = String::format("Could not read directory: %s", error_string); - GUI::MessageBox::show(window, error_message, "File Manager", GUI::MessageBox::Type::Error); - - if (quit) - exit(1); - }; - directory_view.on_status_message = [&](const StringView& message) { statusbar.set_text(message); }; |