1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +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:
Tom 2020-07-11 06:47:26 -06:00 committed by Andreas Kling
parent 0e10a92ebc
commit b778804d20
13 changed files with 144 additions and 60 deletions

View file

@ -88,16 +88,18 @@ BookmarksBarWidget::BookmarksBarWidget(const String& bookmarks_file, bool enable
BookmarksBarWidget::~BookmarksBarWidget()
{
if (m_model)
m_model->unregister_client(*this);
}
void BookmarksBarWidget::set_model(RefPtr<GUI::Model> model)
{
if (model == m_model)
return;
if (m_model)
m_model->unregister_client(*this);
m_model = move(model);
m_model->on_update = [&]() {
did_update_model();
};
m_model->register_client(*this);
}
void BookmarksBarWidget::resize_event(GUI::ResizeEvent& event)
@ -106,7 +108,7 @@ void BookmarksBarWidget::resize_event(GUI::ResizeEvent& event)
update_content_size();
}
void BookmarksBarWidget::did_update_model()
void BookmarksBarWidget::on_model_update(unsigned)
{
for (auto* child : child_widgets()) {
child->remove_from_parent();