mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 15:05:07 +00:00
LibGUI: Add ModelClient abstract class and allow registering clients
This solves a problem where the SortingProxyModel doesn't receive the on_update call because other code overwrote the handler later on.
This commit is contained in:
parent
0e10a92ebc
commit
b778804d20
13 changed files with 144 additions and 60 deletions
|
@ -95,16 +95,7 @@ DirectoryView::DirectoryView()
|
|||
on_path_change(model().root_path());
|
||||
};
|
||||
|
||||
// NOTE: We're using the on_update hook on the GUI::SortingProxyModel here instead of
|
||||
// the GUI::FileSystemModel's hook. This is because GUI::SortingProxyModel has already
|
||||
// installed an on_update hook on the GUI::FileSystemModel internally.
|
||||
// FIXME: This is an unfortunate design. We should come up with something better.
|
||||
m_table_view->model()->on_update = [this] {
|
||||
for_each_view_implementation([](auto& view) {
|
||||
view.selection().clear();
|
||||
});
|
||||
update_statusbar();
|
||||
};
|
||||
m_model->register_client(*this);
|
||||
|
||||
m_model->on_thumbnail_progress = [this](int done, int total) {
|
||||
if (on_thumbnail_progress)
|
||||
|
@ -169,6 +160,17 @@ DirectoryView::DirectoryView()
|
|||
|
||||
DirectoryView::~DirectoryView()
|
||||
{
|
||||
m_model->unregister_client(*this);
|
||||
}
|
||||
|
||||
void DirectoryView::on_model_update(unsigned flags)
|
||||
{
|
||||
if (flags & GUI::Model::UpdateFlag::InvalidateAllIndexes) {
|
||||
for_each_view_implementation([](auto& view) {
|
||||
view.selection().clear();
|
||||
});
|
||||
}
|
||||
update_statusbar();
|
||||
}
|
||||
|
||||
void DirectoryView::set_view_mode(ViewMode mode)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue