mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 03:08:11 +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:
parent
451b3fa73c
commit
cc424b7b0f
3 changed files with 27 additions and 3 deletions
|
@ -91,9 +91,23 @@ DirectoryView::DirectoryView()
|
||||||
m_item_view->set_model_column(GUI::FileSystemModel::Column::Name);
|
m_item_view->set_model_column(GUI::FileSystemModel::Column::Name);
|
||||||
m_columns_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_table_view->selection().clear();
|
||||||
m_item_view->selection().clear();
|
m_item_view->selection().clear();
|
||||||
|
|
||||||
|
add_path_to_history(model().root_path());
|
||||||
|
|
||||||
if (on_path_change)
|
if (on_path_change)
|
||||||
on_path_change(model().root_path());
|
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)
|
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())
|
if (m_path_history_position < m_path_history.size())
|
||||||
m_path_history.resize(m_path_history_position + 1);
|
m_path_history.resize(m_path_history_position + 1);
|
||||||
|
|
||||||
|
@ -210,7 +227,6 @@ void DirectoryView::open(const StringView& path)
|
||||||
model().update();
|
model().update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
add_path_to_history(path);
|
|
||||||
model().set_root_path(path);
|
model().set_root_path(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +239,6 @@ void DirectoryView::set_status_message(const StringView& message)
|
||||||
void DirectoryView::open_parent_directory()
|
void DirectoryView::open_parent_directory()
|
||||||
{
|
{
|
||||||
auto path = String::format("%s/..", model().root_path().characters());
|
auto path = String::format("%s/..", model().root_path().characters());
|
||||||
add_path_to_history(path);
|
|
||||||
model().set_root_path(path);
|
model().set_root_path(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ public:
|
||||||
Function<void(const GUI::AbstractView&, const GUI::ModelIndex&, const GUI::DropEvent&)> on_drop;
|
Function<void(const GUI::AbstractView&, const GUI::ModelIndex&, const GUI::DropEvent&)> on_drop;
|
||||||
Function<void(const StringView&)> on_status_message;
|
Function<void(const StringView&)> on_status_message;
|
||||||
Function<void(int done, int total)> on_thumbnail_progress;
|
Function<void(int done, int total)> on_thumbnail_progress;
|
||||||
|
Function<void(int error, const char* error_string, bool quit)> on_error;
|
||||||
|
|
||||||
enum ViewMode {
|
enum ViewMode {
|
||||||
Invalid,
|
Invalid,
|
||||||
|
|
|
@ -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);
|
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) {
|
directory_view.on_status_message = [&](const StringView& message) {
|
||||||
statusbar.set_text(message);
|
statusbar.set_text(message);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue