mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
WindowServer/LibGUI: Add default menu items and allow default action for context menu
By specifying an optional Action for Menu::popup an application can specify what item should be displayed as a default item.
This commit is contained in:
parent
fc4e01a3c9
commit
1c1ab71692
6 changed files with 44 additions and 20 deletions
|
@ -27,7 +27,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/NonnullOwnPtrVector.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Forward.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
|
||||
|
@ -39,11 +41,7 @@ public:
|
|||
explicit Menu(const StringView& name = "");
|
||||
virtual ~Menu() override;
|
||||
|
||||
void realize_menu_if_needed()
|
||||
{
|
||||
if (menu_id() == -1)
|
||||
realize_menu();
|
||||
}
|
||||
void realize_menu_if_needed();
|
||||
|
||||
static Menu* from_menu_id(int);
|
||||
int menu_id() const { return m_menu_id; }
|
||||
|
@ -56,19 +54,20 @@ public:
|
|||
void add_separator();
|
||||
Menu& add_submenu(const String& name);
|
||||
|
||||
void popup(const Gfx::IntPoint& screen_position);
|
||||
void popup(const Gfx::IntPoint& screen_position, const RefPtr<Action>& default_action = nullptr);
|
||||
void dismiss();
|
||||
|
||||
private:
|
||||
friend class MenuBar;
|
||||
|
||||
int realize_menu();
|
||||
int realize_menu(RefPtr<Action> default_action = nullptr);
|
||||
void unrealize_menu();
|
||||
void realize_if_needed();
|
||||
void realize_if_needed(const RefPtr<Action>& default_action);
|
||||
|
||||
int m_menu_id { -1 };
|
||||
String m_name;
|
||||
NonnullOwnPtrVector<MenuItem> m_items;
|
||||
WeakPtr<Action> m_last_default_action;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue