mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +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:
parent
86781f0c08
commit
0060b8c4e5
Notes:
sideshowbarker
2024-07-16 21:51:02 +09:00
Author: https://github.com/kemzeb Commit: https://github.com/SerenityOS/serenity/commit/0060b8c4e5 Pull-request: https://github.com/SerenityOS/serenity/pull/18096 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/MacDue
3 changed files with 19 additions and 12 deletions
|
@ -292,10 +292,15 @@ bool BookmarksBarWidget::remove_bookmark(DeprecatedString const& url)
|
|||
auto& json_model = *static_cast<GUI::JsonArrayModel*>(model());
|
||||
|
||||
auto const item_removed = json_model.remove(item_index);
|
||||
if (item_removed)
|
||||
json_model.store();
|
||||
if (!item_removed)
|
||||
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)
|
||||
return false;
|
||||
|
||||
if (on_bookmark_add)
|
||||
on_bookmark_add(url);
|
||||
if (on_bookmark_change)
|
||||
on_bookmark_change();
|
||||
|
||||
if (edit_bookmark(url, PerformEditOn::NewBookmark))
|
||||
return true;
|
||||
|
@ -333,9 +338,14 @@ bool BookmarksBarWidget::edit_bookmark(DeprecatedString const& url, PerformEditO
|
|||
|
||||
if (item_url == url) {
|
||||
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));
|
||||
});
|
||||
|
||||
if (was_bookmark_changed && on_bookmark_change)
|
||||
on_bookmark_change();
|
||||
|
||||
return was_bookmark_changed;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
|
||||
Function<void(DeprecatedString const& url, Open)> on_bookmark_click;
|
||||
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 remove_bookmark(DeprecatedString const& url);
|
||||
|
|
|
@ -606,7 +606,6 @@ void Tab::bookmark_current_url()
|
|||
} else {
|
||||
BookmarksBarWidget::the().add_bookmark(url, m_title);
|
||||
}
|
||||
update_bookmark_button(url);
|
||||
}
|
||||
|
||||
void Tab::update_bookmark_button(DeprecatedString const& url)
|
||||
|
@ -635,10 +634,8 @@ void Tab::did_become_active()
|
|||
m_statusbar->set_text(url);
|
||||
};
|
||||
|
||||
BookmarksBarWidget::the().on_bookmark_add = [this](auto& url) {
|
||||
auto current_url = this->url().to_deprecated_string();
|
||||
if (current_url == url)
|
||||
update_bookmark_button(current_url);
|
||||
BookmarksBarWidget::the().on_bookmark_change = [this]() {
|
||||
update_bookmark_button(url().to_deprecated_string());
|
||||
};
|
||||
|
||||
BookmarksBarWidget::the().remove_from_parent();
|
||||
|
|
Loading…
Reference in a new issue