summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorangel <angel@ttm.sh>2020-04-21 21:53:13 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-22 12:12:32 +0200
commitcc424b7b0f2cf982667f0dc0a0763d50a189efe7 (patch)
tree68861e64d896f17a4c2a28104fa7421e9d605d12
parent451b3fa73cc5befe3dd753a472b1d88a290aeb58 (diff)
downloadserenity-cc424b7b0f2cf982667f0dc0a0763d50a189efe7.zip
FileManager: Graceful handling of access errors
A neat error message is displayed when failing to open a directory!
-rw-r--r--Applications/FileManager/DirectoryView.cpp21
-rw-r--r--Applications/FileManager/DirectoryView.h1
-rw-r--r--Applications/FileManager/main.cpp8
3 files changed, 27 insertions, 3 deletions
diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp
index 88bdf5eda1..8e56335979 100644
--- a/Applications/FileManager/DirectoryView.cpp
+++ b/Applications/FileManager/DirectoryView.cpp
@@ -91,9 +91,23 @@ DirectoryView::DirectoryView()
m_item_view->set_model_column(GUI::FileSystemModel::Column::Name);
m_columns_view->set_model_column(GUI::FileSystemModel::Column::Name);
- m_model->on_root_path_change = [this] {
+ m_model->on_error = [this](int error, const char* error_string) {
+ 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);
+ };
+
+ m_model->on_complete = [this] {
m_table_view->selection().clear();
m_item_view->selection().clear();
+
+ add_path_to_history(model().root_path());
+
if (on_path_change)
on_path_change(model().root_path());
};
@@ -197,6 +211,9 @@ void DirectoryView::set_view_mode(ViewMode mode)
void DirectoryView::add_path_to_history(const StringView& path)
{
+ if (m_path_history.size() && m_path_history.at(m_path_history_position) == path)
+ return;
+
if (m_path_history_position < m_path_history.size())
m_path_history.resize(m_path_history_position + 1);
@@ -210,7 +227,6 @@ void DirectoryView::open(const StringView& path)
model().update();
return;
}
- add_path_to_history(path);
model().set_root_path(path);
}
@@ -223,7 +239,6 @@ void DirectoryView::set_status_message(const StringView& message)
void DirectoryView::open_parent_directory()
{
auto path = String::format("%s/..", model().root_path().characters());
- add_path_to_history(path);
model().set_root_path(path);
}
diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h
index 9d528141c3..ddbf0325ce 100644
--- a/Applications/FileManager/DirectoryView.h
+++ b/Applications/FileManager/DirectoryView.h
@@ -55,6 +55,7 @@ public:
Function<void(const GUI::AbstractView&, const GUI::ModelIndex&, const GUI::DropEvent&)> on_drop;
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,
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp
index d0c1044c14..0fa3dfd584 100644
--- a/Applications/FileManager/main.cpp
+++ b/Applications/FileManager/main.cpp
@@ -588,6 +588,14 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
go_back_action->set_enabled(directory_view.path_history_position() > 0);
};
+ 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(error_message, "File Manager", GUI::MessageBox::Type::Error);
+
+ if (quit)
+ exit(1);
+ };
+
directory_view.on_status_message = [&](const StringView& message) {
statusbar.set_text(message);
};