From dd0244a97dd71501ede69ec1ed1ff2eaee320f28 Mon Sep 17 00:00:00 2001 From: Rob Ryan Date: Sun, 15 Aug 2021 15:52:27 +1000 Subject: [PATCH] Browser: Add Ctrl-D keyboard shortcut for bookmarking the current page --- Userland/Applications/Browser/Tab.cpp | 25 ++++++++++++++++++------- Userland/Applications/Browser/Tab.h | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index ee548706f1..5bd66626f4 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -173,15 +173,15 @@ Tab::Tab(BrowserWindow& window, Type type) m_bookmark_button->set_fixed_size(22, 22); m_bookmark_button->on_click = [this](auto) { - 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); + bookmark_current_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) { m_location_box->set_icon(nullptr); 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()); } +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) { if (BookmarksBarWidget::the().contains_bookmark(url)) { diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index 49c4a9ecf9..80052b168c 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -77,6 +77,7 @@ private: Web::WebViewHooks& hooks(); void update_actions(); + void bookmark_current_url(); void update_bookmark_button(const String& url); void start_download(const URL& url); void view_source(const URL& url, const String& source);