From 76fad10978985467ed5c6c46aab9160eca8c3511 Mon Sep 17 00:00:00 2001 From: PrecisionRender Date: Wed, 13 Sep 2023 13:10:09 -0500 Subject: [PATCH] Expose `PopupMenu` `activate_item_by_event` method --- doc/classes/PopupMenu.xml | 10 ++++++++++ scene/gui/popup_menu.cpp | 2 ++ 2 files changed, 12 insertions(+) diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml index b72e65e63ab2..c31416b82371 100644 --- a/doc/classes/PopupMenu.xml +++ b/doc/classes/PopupMenu.xml @@ -13,6 +13,16 @@ + + + + + + Checks the provided [param event] against the [PopupMenu]'s shortcuts and accelerators, and activates the first item with matching events. If [param for_global_only] is [code]true[/code], only shortcuts and accelerators with [code]global[/code] set to [code]true[/code] will be called. + Returns [code]true[/code] if an item was successfully activated. + [b]Note:[/b] Certain [Control]s, such as [MenuButton], will call this method automatically. + + diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 1fac301f9a52..d64136a682d9 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -2161,6 +2161,8 @@ void PopupMenu::_get_property_list(List *p_list) const { } void PopupMenu::_bind_methods() { + ClassDB::bind_method(D_METHOD("activate_item_by_event", "event", "for_global_only"), &PopupMenu::activate_item_by_event, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("add_item", "label", "id", "accel"), &PopupMenu::add_item, DEFVAL(-1), DEFVAL(0)); ClassDB::bind_method(D_METHOD("add_icon_item", "texture", "label", "id", "accel"), &PopupMenu::add_icon_item, DEFVAL(-1), DEFVAL(0)); ClassDB::bind_method(D_METHOD("add_check_item", "label", "id", "accel"), &PopupMenu::add_check_item, DEFVAL(-1), DEFVAL(0));