mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:57:34 +00:00
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!
This commit is contained in:
parent
bf2e6325a4
commit
9241c3a957
3 changed files with 21 additions and 0 deletions
|
@ -310,6 +310,14 @@ Tab::Tab()
|
||||||
|
|
||||||
auto& help_menu = m_menubar->add_menu("Help");
|
auto& help_menu = m_menubar->add_menu("Help");
|
||||||
help_menu.add_action(WindowActions::the().about_action());
|
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()
|
Tab::~Tab()
|
||||||
|
@ -369,4 +377,9 @@ void Tab::did_become_active()
|
||||||
GUI::Application::the().set_menubar(m_menubar);
|
GUI::Application::the().set_menubar(m_menubar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tab::context_menu_requested(const Gfx::Point& screen_position)
|
||||||
|
{
|
||||||
|
m_tab_context_menu->popup(screen_position);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
void load(const URL&);
|
void load(const URL&);
|
||||||
|
|
||||||
void did_become_active();
|
void did_become_active();
|
||||||
|
void context_menu_requested(const Gfx::Point& screen_position);
|
||||||
|
|
||||||
Function<void(String)> on_title_change;
|
Function<void(String)> on_title_change;
|
||||||
Function<void(const URL&)> on_tab_open_request;
|
Function<void(const URL&)> on_tab_open_request;
|
||||||
|
@ -73,6 +74,8 @@ private:
|
||||||
RefPtr<GUI::Menu> m_link_context_menu;
|
RefPtr<GUI::Menu> m_link_context_menu;
|
||||||
String m_link_context_menu_href;
|
String m_link_context_menu_href;
|
||||||
|
|
||||||
|
RefPtr<GUI::Menu> m_tab_context_menu;
|
||||||
|
|
||||||
String m_title;
|
String m_title;
|
||||||
RefPtr<const Gfx::Bitmap> m_icon;
|
RefPtr<const Gfx::Bitmap> m_icon;
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,11 @@ int main(int argc, char** argv)
|
||||||
tab.on_tab_close_request(tab);
|
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<Browser::Tab&>(clicked_widget);
|
||||||
|
tab.context_menu_requested(context_menu_event.screen_position());
|
||||||
|
};
|
||||||
|
|
||||||
Browser::WindowActions window_actions(*window);
|
Browser::WindowActions window_actions(*window);
|
||||||
|
|
||||||
Function<void(URL url, bool activate)> create_new_tab;
|
Function<void(URL url, bool activate)> create_new_tab;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue