summaryrefslogtreecommitdiff
path: root/Applications/FileManager/DirectoryView.cpp
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 /Applications/FileManager/DirectoryView.cpp
parent451b3fa73cc5befe3dd753a472b1d88a290aeb58 (diff)
downloadserenity-cc424b7b0f2cf982667f0dc0a0763d50a189efe7.zip
FileManager: Graceful handling of access errors
A neat error message is displayed when failing to open a directory!
Diffstat (limited to 'Applications/FileManager/DirectoryView.cpp')
-rw-r--r--Applications/FileManager/DirectoryView.cpp21
1 files changed, 18 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);
}