From 8075db683bc685408f3650a47158c84c0d89fb29 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 18 Sep 2020 18:02:57 +0200 Subject: 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. --- Applications/FileManager/DirectoryView.cpp | 17 ++++++++++++++--- Applications/FileManager/DirectoryView.h | 3 ++- Applications/FileManager/main.cpp | 8 -------- 3 files changed, 16 insertions(+), 12 deletions(-) (limited to 'Applications') 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 #include #include +#include #include #include #include @@ -135,6 +136,9 @@ DirectoryView::DirectoryView(Mode mode) setup_actions(); + m_error_label = add(); + 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 on_context_menu_request; Function on_status_message; Function on_thumbnail_progress; - Function on_error; enum ViewMode { Invalid, @@ -174,6 +173,8 @@ private: Vector m_path_history; void add_path_to_history(const StringView& path); + RefPtr m_error_label; + RefPtr m_table_view; RefPtr m_icon_view; RefPtr 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 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); }; -- cgit v1.2.3