mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
Browser: Pop up a context menu when requested on a bookmark button
This right click context menu currently allows for the removal of bookmarks as well as opening them in a new tab.
This commit is contained in:
parent
28f74df2e6
commit
5431e81bc3
3 changed files with 20 additions and 3 deletions
|
@ -70,6 +70,15 @@ BookmarksBarWidget::BookmarksBarWidget(const String& bookmarks_file, bool enable
|
||||||
|
|
||||||
m_separator = GUI::Widget::construct();
|
m_separator = GUI::Widget::construct();
|
||||||
|
|
||||||
|
m_context_menu = GUI::Menu::construct();
|
||||||
|
m_context_menu->add_action(GUI::Action::create("Delete", [this](auto&) {
|
||||||
|
remove_bookmark(m_context_menu_url);
|
||||||
|
}));
|
||||||
|
m_context_menu->add_action(GUI::Action::create("Open in new tab", [this](auto&) {
|
||||||
|
if (on_bookmark_click)
|
||||||
|
on_bookmark_click(m_context_menu_url, Mod_Ctrl);
|
||||||
|
}));
|
||||||
|
|
||||||
Vector<GUI::JsonArrayModel::FieldSpec> fields;
|
Vector<GUI::JsonArrayModel::FieldSpec> fields;
|
||||||
fields.empend("title", "Title", Gfx::TextAlignment::CenterLeft);
|
fields.empend("title", "Title", Gfx::TextAlignment::CenterLeft);
|
||||||
fields.empend("url", "Url", Gfx::TextAlignment::CenterRight);
|
fields.empend("url", "Url", Gfx::TextAlignment::CenterRight);
|
||||||
|
@ -125,7 +134,12 @@ void BookmarksBarWidget::did_update_model()
|
||||||
|
|
||||||
button.on_click = [title, url, this](auto modifiers) {
|
button.on_click = [title, url, this](auto modifiers) {
|
||||||
if (on_bookmark_click)
|
if (on_bookmark_click)
|
||||||
on_bookmark_click(title, url, modifiers);
|
on_bookmark_click(url, modifiers);
|
||||||
|
};
|
||||||
|
|
||||||
|
button.on_context_menu_request = [this, url](auto& context_menu_event) {
|
||||||
|
m_context_menu_url = url;
|
||||||
|
m_context_menu->popup(context_menu_event.screen_position());
|
||||||
};
|
};
|
||||||
|
|
||||||
width += rect.width();
|
width += rect.width();
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
GUI::Model* model() { return m_model.ptr(); }
|
GUI::Model* model() { return m_model.ptr(); }
|
||||||
const GUI::Model* model() const { return m_model.ptr(); }
|
const GUI::Model* model() const { return m_model.ptr(); }
|
||||||
|
|
||||||
Function<void(const String&, const String&, unsigned modifiers)> on_bookmark_click;
|
Function<void(const String& url, unsigned modifiers)> on_bookmark_click;
|
||||||
Function<void(const String&, const String&)> on_bookmark_hover;
|
Function<void(const String&, const String&)> on_bookmark_hover;
|
||||||
|
|
||||||
bool contains_bookmark(const String& url);
|
bool contains_bookmark(const String& url);
|
||||||
|
@ -62,6 +62,9 @@ private:
|
||||||
RefPtr<GUI::Widget> m_separator;
|
RefPtr<GUI::Widget> m_separator;
|
||||||
RefPtr<GUI::Menu> m_additional_menu;
|
RefPtr<GUI::Menu> m_additional_menu;
|
||||||
|
|
||||||
|
RefPtr<GUI::Menu> m_context_menu;
|
||||||
|
String m_context_menu_url;
|
||||||
|
|
||||||
NonnullRefPtrVector<GUI::Button> m_bookmarks;
|
NonnullRefPtrVector<GUI::Button> m_bookmarks;
|
||||||
|
|
||||||
int m_last_visible_index { -1 };
|
int m_last_visible_index { -1 };
|
||||||
|
|
|
@ -356,7 +356,7 @@ void Tab::did_become_active()
|
||||||
m_statusbar->set_text(String::format("Loading (%d pending resources...)", Web::ResourceLoader::the().pending_loads()));
|
m_statusbar->set_text(String::format("Loading (%d pending resources...)", Web::ResourceLoader::the().pending_loads()));
|
||||||
};
|
};
|
||||||
|
|
||||||
BookmarksBarWidget::the().on_bookmark_click = [this](auto&, auto& url, unsigned modifiers) {
|
BookmarksBarWidget::the().on_bookmark_click = [this](auto& url, unsigned modifiers) {
|
||||||
if (modifiers & Mod_Ctrl)
|
if (modifiers & Mod_Ctrl)
|
||||||
on_tab_open_request(url);
|
on_tab_open_request(url);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue