mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 17:28:48 +00:00
Plumb menu item activation events from WindowServer to clients.
GMenu now has an "on_item_activation" callback that fires whenever one of its items are activated. The menu item identifier is used to distinguish between items. Use this to implement font switching in Terminal. :^)
This commit is contained in:
parent
9c1c885483
commit
db98327bdc
Notes:
sideshowbarker
2024-07-19 15:46:45 +09:00
Author: https://github.com/awesomekling
Commit: db98327bdc
10 changed files with 93 additions and 3 deletions
|
@ -1,5 +1,22 @@
|
|||
#include <LibGUI/GMenu.h>
|
||||
#include <LibC/gui.h>
|
||||
#include <AK/HashMap.h>
|
||||
|
||||
static HashMap<int, GMenu*>& all_menus()
|
||||
{
|
||||
static HashMap<int, GMenu*>* map;
|
||||
if (!map)
|
||||
map = new HashMap<int, GMenu*>();
|
||||
return *map;
|
||||
}
|
||||
|
||||
GMenu* GMenu::from_menu_id(int menu_id)
|
||||
{
|
||||
auto it = all_menus().find(menu_id);
|
||||
if (it == all_menus().end())
|
||||
return nullptr;
|
||||
return (*it).value;
|
||||
}
|
||||
|
||||
GMenu::GMenu(const String& name)
|
||||
: m_name(name)
|
||||
|
@ -9,6 +26,7 @@ GMenu::GMenu(const String& name)
|
|||
GMenu::~GMenu()
|
||||
{
|
||||
if (m_menu_id) {
|
||||
all_menus().remove(m_menu_id);
|
||||
gui_menu_destroy(m_menu_id);
|
||||
m_menu_id = 0;
|
||||
}
|
||||
|
@ -34,5 +52,6 @@ int GMenu::realize_menu()
|
|||
else if (item.type() == GMenuItem::Text)
|
||||
gui_menu_add_item(m_menu_id, item.identifier(), item.text().characters());
|
||||
}
|
||||
all_menus().set(m_menu_id, this);
|
||||
return m_menu_id;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue