mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 23:28:12 +00:00
File Manager: Differentiate between navigation and rename errors
Adds a new on_rename_error handler and renames the old on_error handler to on_directory_change_error in FileSystemModel. The on_rename_error handler creates a MessageDialog with the error message.
This commit is contained in:
parent
35b930112f
commit
fe7bacc2df
3 changed files with 11 additions and 6 deletions
|
@ -214,7 +214,7 @@ const GUI::FileSystemModel::Node& DirectoryView::node(const GUI::ModelIndex& ind
|
||||||
|
|
||||||
void DirectoryView::setup_model()
|
void DirectoryView::setup_model()
|
||||||
{
|
{
|
||||||
m_model->on_error = [this](int, const char* error_string) {
|
m_model->on_directory_change_error = [this](int, const char* error_string) {
|
||||||
auto failed_path = m_model->root_path();
|
auto failed_path = m_model->root_path();
|
||||||
auto error_message = String::formatted("Could not read {}:\n{}", failed_path, error_string);
|
auto error_message = String::formatted("Could not read {}:\n{}", failed_path, error_string);
|
||||||
m_error_label->set_text(error_message);
|
m_error_label->set_text(error_message);
|
||||||
|
@ -229,6 +229,10 @@ void DirectoryView::setup_model()
|
||||||
on_path_change(failed_path, false, false);
|
on_path_change(failed_path, false, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
m_model->on_rename_error = [this](int, const char* error_string) {
|
||||||
|
GUI::MessageBox::show_error(window(), String::formatted("Unable to rename file: {}", error_string));
|
||||||
|
};
|
||||||
|
|
||||||
m_model->on_complete = [this] {
|
m_model->on_complete = [this] {
|
||||||
if (m_table_view)
|
if (m_table_view)
|
||||||
m_table_view->selection().clear();
|
m_table_view->selection().clear();
|
||||||
|
|
|
@ -367,8 +367,8 @@ void FileSystemModel::set_root_path(String root_path)
|
||||||
update();
|
update();
|
||||||
|
|
||||||
if (m_root->has_error()) {
|
if (m_root->has_error()) {
|
||||||
if (on_error)
|
if (on_directory_change_error)
|
||||||
on_error(m_root->error(), m_root->error_string());
|
on_directory_change_error(m_root->error(), m_root->error_string());
|
||||||
} else if (on_complete) {
|
} else if (on_complete) {
|
||||||
on_complete();
|
on_complete();
|
||||||
}
|
}
|
||||||
|
@ -676,8 +676,8 @@ void FileSystemModel::set_data(const ModelIndex& index, const Variant& data)
|
||||||
auto new_full_path = String::formatted("{}/{}", dirname, data.to_string());
|
auto new_full_path = String::formatted("{}/{}", dirname, data.to_string());
|
||||||
int rc = rename(node.full_path().characters(), new_full_path.characters());
|
int rc = rename(node.full_path().characters(), new_full_path.characters());
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
if (on_error)
|
if (on_rename_error)
|
||||||
on_error(errno, strerror(errno));
|
on_rename_error(errno, strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,8 @@ public:
|
||||||
|
|
||||||
Function<void(int done, int total)> on_thumbnail_progress;
|
Function<void(int done, int total)> on_thumbnail_progress;
|
||||||
Function<void()> on_complete;
|
Function<void()> on_complete;
|
||||||
Function<void(int error, const char* error_string)> on_error;
|
Function<void(int error, const char* error_string)> on_directory_change_error;
|
||||||
|
Function<void(int error, const char* error_string)> on_rename_error;
|
||||||
|
|
||||||
virtual int tree_column() const override { return Column::Name; }
|
virtual int tree_column() const override { return Column::Name; }
|
||||||
virtual int row_count(const ModelIndex& = ModelIndex()) const override;
|
virtual int row_count(const ModelIndex& = ModelIndex()) const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue