1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 12:55:09 +00:00

FileManager: Graceful handling of access errors

A neat error message is displayed when failing to open a directory!
This commit is contained in:
angel 2020-04-21 21:53:13 +02:00 committed by Andreas Kling
parent 451b3fa73c
commit cc424b7b0f
3 changed files with 27 additions and 3 deletions

View file

@ -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);
}