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

Browser: Add Ctrl-D keyboard shortcut for bookmarking the current page

This commit is contained in:
Rob Ryan 2021-08-15 15:52:27 +10:00 committed by Andreas Kling
parent 34a64ed25b
commit dd0244a97d
2 changed files with 19 additions and 7 deletions

View file

@ -173,15 +173,15 @@ Tab::Tab(BrowserWindow& window, Type type)
m_bookmark_button->set_fixed_size(22, 22); m_bookmark_button->set_fixed_size(22, 22);
m_bookmark_button->on_click = [this](auto) { m_bookmark_button->on_click = [this](auto) {
auto url = this->url().to_string(); bookmark_current_url();
if (BookmarksBarWidget::the().contains_bookmark(url)) {
BookmarksBarWidget::the().remove_bookmark(url);
} else {
BookmarksBarWidget::the().add_bookmark(url, m_title);
}
update_bookmark_button(url);
}; };
auto bookmark_action = GUI::Action::create(
"Bookmark current URL", { Mod_Ctrl, Key_D }, [this](auto&) {
bookmark_current_url();
},
this);
hooks().on_load_start = [this](auto& url) { hooks().on_load_start = [this](auto& url) {
m_location_box->set_icon(nullptr); m_location_box->set_icon(nullptr);
m_location_box->set_text(url.to_string()); m_location_box->set_text(url.to_string());
@ -410,6 +410,17 @@ void Tab::update_actions()
window.go_forward_action().set_enabled(m_history.can_go_forward()); window.go_forward_action().set_enabled(m_history.can_go_forward());
} }
void Tab::bookmark_current_url()
{
auto url = this->url().to_string();
if (BookmarksBarWidget::the().contains_bookmark(url)) {
BookmarksBarWidget::the().remove_bookmark(url);
} else {
BookmarksBarWidget::the().add_bookmark(url, m_title);
}
update_bookmark_button(url);
}
void Tab::update_bookmark_button(const String& url) void Tab::update_bookmark_button(const String& url)
{ {
if (BookmarksBarWidget::the().contains_bookmark(url)) { if (BookmarksBarWidget::the().contains_bookmark(url)) {

View file

@ -77,6 +77,7 @@ private:
Web::WebViewHooks& hooks(); Web::WebViewHooks& hooks();
void update_actions(); void update_actions();
void bookmark_current_url();
void update_bookmark_button(const String& url); void update_bookmark_button(const String& url);
void start_download(const URL& url); void start_download(const URL& url);
void view_source(const URL& url, const String& source); void view_source(const URL& url, const String& source);