1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

Browser: Have BookmarksBarWidget signal bookmark changes for Tab

This fixes an issue with a tab not updating its bookmark button when
we either edit or delete a bookmark and the tab happens to be on the
same page associated with the bookmark URL. `BookmarksBarWidget`
"signals" a `Tab` object of any bookmark changes, where it will
update the bookmark button depending on if the current URL is an
existing bookmark or not.
This commit is contained in:
Kemal Zebari 2023-03-29 19:36:57 -07:00 committed by Andrew Kaster
parent 86781f0c08
commit 0060b8c4e5
3 changed files with 19 additions and 12 deletions

View file

@ -292,10 +292,15 @@ bool BookmarksBarWidget::remove_bookmark(DeprecatedString const& url)
auto& json_model = *static_cast<GUI::JsonArrayModel*>(model()); auto& json_model = *static_cast<GUI::JsonArrayModel*>(model());
auto const item_removed = json_model.remove(item_index); auto const item_removed = json_model.remove(item_index);
if (item_removed) if (!item_removed)
json_model.store(); return false;
return item_removed; json_model.store();
if (on_bookmark_change)
on_bookmark_change();
return true;
} }
} }
@ -315,8 +320,8 @@ bool BookmarksBarWidget::add_bookmark(DeprecatedString const& url, DeprecatedStr
if (!was_bookmark_added) if (!was_bookmark_added)
return false; return false;
if (on_bookmark_add) if (on_bookmark_change)
on_bookmark_add(url); on_bookmark_change();
if (edit_bookmark(url, PerformEditOn::NewBookmark)) if (edit_bookmark(url, PerformEditOn::NewBookmark))
return true; return true;
@ -333,9 +338,14 @@ bool BookmarksBarWidget::edit_bookmark(DeprecatedString const& url, PerformEditO
if (item_url == url) { if (item_url == url) {
auto values = BookmarkEditor::edit_bookmark(window(), item_title, item_url, perform_edit_on); auto values = BookmarkEditor::edit_bookmark(window(), item_title, item_url, perform_edit_on);
return update_model(values, [item_index](auto& model, auto&& values) { auto was_bookmark_changed = update_model(values, [item_index](auto& model, auto&& values) {
return model.set(item_index, move(values)); return model.set(item_index, move(values));
}); });
if (was_bookmark_changed && on_bookmark_change)
on_bookmark_change();
return was_bookmark_changed;
} }
} }

View file

@ -34,7 +34,7 @@ public:
Function<void(DeprecatedString const& url, Open)> on_bookmark_click; Function<void(DeprecatedString const& url, Open)> on_bookmark_click;
Function<void(DeprecatedString const&, DeprecatedString const&)> on_bookmark_hover; Function<void(DeprecatedString const&, DeprecatedString const&)> on_bookmark_hover;
Function<void(DeprecatedString const& url)> on_bookmark_add; Function<void()> on_bookmark_change;
bool contains_bookmark(DeprecatedString const& url); bool contains_bookmark(DeprecatedString const& url);
bool remove_bookmark(DeprecatedString const& url); bool remove_bookmark(DeprecatedString const& url);

View file

@ -606,7 +606,6 @@ void Tab::bookmark_current_url()
} else { } else {
BookmarksBarWidget::the().add_bookmark(url, m_title); BookmarksBarWidget::the().add_bookmark(url, m_title);
} }
update_bookmark_button(url);
} }
void Tab::update_bookmark_button(DeprecatedString const& url) void Tab::update_bookmark_button(DeprecatedString const& url)
@ -635,10 +634,8 @@ void Tab::did_become_active()
m_statusbar->set_text(url); m_statusbar->set_text(url);
}; };
BookmarksBarWidget::the().on_bookmark_add = [this](auto& url) { BookmarksBarWidget::the().on_bookmark_change = [this]() {
auto current_url = this->url().to_deprecated_string(); update_bookmark_button(url().to_deprecated_string());
if (current_url == url)
update_bookmark_button(current_url);
}; };
BookmarksBarWidget::the().remove_from_parent(); BookmarksBarWidget::the().remove_from_parent();