1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

Browser: Let the user add/remove bookmarks to the bookmarks bar

This patchset adds a Button to the toolbar (right next to the location field)
with a star icon. The star is white if the currently visited url is not yet
bookmarked and yellow if a bookmark for the url exists.

After adding or removing a bookmark, the bookmark json file is synced to disk.
Therefore, some new pledge/unveil's have been added.
This commit is contained in:
Emanuel Sprung 2020-03-26 20:06:23 +01:00 committed by Andreas Kling
parent 4d50398f02
commit c9059c12dc
5 changed files with 90 additions and 2 deletions

View file

@ -162,3 +162,45 @@ void BookmarksBarWidget::update_content_size()
}
}
}
bool BookmarksBarWidget::contains_bookmark(const String& url)
{
for (int item_index = 0; item_index < model()->row_count(); ++item_index) {
auto item_title = model()->data(model()->index(item_index, 0)).to_string();
auto item_url = model()->data(model()->index(item_index, 1)).to_string();
if (item_url == url) {
return true;
}
}
return false;
}
bool BookmarksBarWidget::remove_bookmark(const String& url)
{
for (int item_index = 0; item_index < model()->row_count(); ++item_index) {
auto item_title = model()->data(model()->index(item_index, 0)).to_string();
auto item_url = model()->data(model()->index(item_index, 1)).to_string();
if (item_url == url) {
auto& json_model = *static_cast<GUI::JsonArrayModel*>(model());
json_model.remove(item_index);
return true;
}
}
return false;
}
bool BookmarksBarWidget::add_bookmark(const String& url, const String& title)
{
Vector<JsonValue> values;
values.append(title);
values.append(url);
auto& json_model = *static_cast<GUI::JsonArrayModel*>(model());
if (json_model.add(move(values))) {
json_model.store();
return true;
}
return false;
}