From 9241c3a957c0d04fb3ded503b2509c7242847ca4 Mon Sep 17 00:00:00 2001 From: FalseHonesty Date: Mon, 18 May 2020 18:37:12 -0400 Subject: Browser: Pop up a context menu when one is requested on a tab Currently, the tab's context menu only has options to reload and close, but this patch allows for those options to be quickly expanded! --- Applications/Browser/Tab.cpp | 13 +++++++++++++ Applications/Browser/Tab.h | 3 +++ Applications/Browser/main.cpp | 5 +++++ 3 files changed, 21 insertions(+) (limited to 'Applications/Browser') diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp index d5e402196e..c5ba32f83d 100644 --- a/Applications/Browser/Tab.cpp +++ b/Applications/Browser/Tab.cpp @@ -310,6 +310,14 @@ Tab::Tab() auto& help_menu = m_menubar->add_menu("Help"); help_menu.add_action(WindowActions::the().about_action()); + + m_tab_context_menu = GUI::Menu::construct(); + m_tab_context_menu->add_action(GUI::Action::create("Reload Tab", [this](auto&) { + m_reload_action->activate(); + })); + m_tab_context_menu->add_action(GUI::Action::create("Close Tab", [this](auto&) { + on_tab_close_request(*this); + })); } Tab::~Tab() @@ -369,4 +377,9 @@ void Tab::did_become_active() GUI::Application::the().set_menubar(m_menubar); } +void Tab::context_menu_requested(const Gfx::Point& screen_position) +{ + m_tab_context_menu->popup(screen_position); +} + } diff --git a/Applications/Browser/Tab.h b/Applications/Browser/Tab.h index 4f26e55a98..78abe4ddc8 100644 --- a/Applications/Browser/Tab.h +++ b/Applications/Browser/Tab.h @@ -43,6 +43,7 @@ public: void load(const URL&); void did_become_active(); + void context_menu_requested(const Gfx::Point& screen_position); Function on_title_change; Function on_tab_open_request; @@ -73,6 +74,8 @@ private: RefPtr m_link_context_menu; String m_link_context_menu_href; + RefPtr m_tab_context_menu; + String m_title; RefPtr m_icon; diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp index 0f5872fab2..ab93e88c9a 100644 --- a/Applications/Browser/main.cpp +++ b/Applications/Browser/main.cpp @@ -121,6 +121,11 @@ int main(int argc, char** argv) tab.on_tab_close_request(tab); }; + tab_widget.on_context_menu_request = [&](auto& clicked_widget, const GUI::ContextMenuEvent& context_menu_event) { + auto& tab = static_cast(clicked_widget); + tab.context_menu_requested(context_menu_event.screen_position()); + }; + Browser::WindowActions window_actions(*window); Function create_new_tab; -- cgit v1.2.3