2929/* *************************************************************************/
3030
3131#include " popup_menu.h"
32+ #include " popup_menu.compat.inc"
3233
3334#include " core/config/project_settings.h"
3435#include " core/input/input.h"
@@ -1164,18 +1165,19 @@ void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int
11641165 _menu_changed ();
11651166}
11661167
1167- #define ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global ) \
1168+ #define ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global, p_allow_echo ) \
11681169 ERR_FAIL_COND_MSG (p_shortcut.is_null(), "Cannot add item with invalid Shortcut."); \
11691170 _ref_shortcut (p_shortcut); \
11701171 item.text = p_shortcut->get_name (); \
11711172 item.xl_text = atr(item.text); \
11721173 item.id = p_id == -1 ? items.size() : p_id; \
11731174 item.shortcut = p_shortcut; \
1174- item.shortcut_is_global = p_global;
1175+ item.shortcut_is_global = p_global; \
1176+ item.allow_echo = p_allow_echo;
11751177
1176- void PopupMenu::add_shortcut (const Ref<Shortcut> &p_shortcut, int p_id, bool p_global) {
1178+ void PopupMenu::add_shortcut (const Ref<Shortcut> &p_shortcut, int p_id, bool p_global, bool p_allow_echo ) {
11771179 Item item;
1178- ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global);
1180+ ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global, p_allow_echo );
11791181 items.push_back (item);
11801182
11811183 _shape_item (items.size () - 1 );
@@ -1185,9 +1187,9 @@ void PopupMenu::add_shortcut(const Ref<Shortcut> &p_shortcut, int p_id, bool p_g
11851187 _menu_changed ();
11861188}
11871189
1188- void PopupMenu::add_icon_shortcut (const Ref<Texture2D> &p_icon, const Ref<Shortcut> &p_shortcut, int p_id, bool p_global) {
1190+ void PopupMenu::add_icon_shortcut (const Ref<Texture2D> &p_icon, const Ref<Shortcut> &p_shortcut, int p_id, bool p_global, bool p_allow_echo ) {
11891191 Item item;
1190- ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global);
1192+ ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global, p_allow_echo );
11911193 item.icon = p_icon;
11921194 items.push_back (item);
11931195
@@ -1200,7 +1202,7 @@ void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<Shortc
12001202
12011203void PopupMenu::add_check_shortcut (const Ref<Shortcut> &p_shortcut, int p_id, bool p_global) {
12021204 Item item;
1203- ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global);
1205+ ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global, false ); // Echo for check shortcuts doesn't make sense.
12041206 item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX ;
12051207 items.push_back (item);
12061208
@@ -1213,7 +1215,7 @@ void PopupMenu::add_check_shortcut(const Ref<Shortcut> &p_shortcut, int p_id, bo
12131215
12141216void PopupMenu::add_icon_check_shortcut (const Ref<Texture2D> &p_icon, const Ref<Shortcut> &p_shortcut, int p_id, bool p_global) {
12151217 Item item;
1216- ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global);
1218+ ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global, false );
12171219 item.icon = p_icon;
12181220 item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX ;
12191221 items.push_back (item);
@@ -1227,7 +1229,7 @@ void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<
12271229
12281230void PopupMenu::add_radio_check_shortcut (const Ref<Shortcut> &p_shortcut, int p_id, bool p_global) {
12291231 Item item;
1230- ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global);
1232+ ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global, false );
12311233 item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON ;
12321234 items.push_back (item);
12331235
@@ -1240,7 +1242,7 @@ void PopupMenu::add_radio_check_shortcut(const Ref<Shortcut> &p_shortcut, int p_
12401242
12411243void PopupMenu::add_icon_radio_check_shortcut (const Ref<Texture2D> &p_icon, const Ref<Shortcut> &p_shortcut, int p_id, bool p_global) {
12421244 Item item;
1243- ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global);
1245+ ITEM_SETUP_WITH_SHORTCUT (p_shortcut, p_id, p_global, false );
12441246 item.icon = p_icon;
12451247 item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON ;
12461248 items.push_back (item);
@@ -1838,7 +1840,7 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo
18381840 }
18391841
18401842 for (int i = 0 ; i < items.size (); i++) {
1841- if (is_item_disabled (i) || items[i].shortcut_is_disabled ) {
1843+ if (is_item_disabled (i) || items[i].shortcut_is_disabled || (!items[i]. allow_echo && p_event-> is_echo ()) ) {
18421844 continue ;
18431845 }
18441846
@@ -2213,8 +2215,8 @@ void PopupMenu::_bind_methods() {
22132215
22142216 ClassDB::bind_method (D_METHOD (" add_multistate_item" , " label" , " max_states" , " default_state" , " id" , " accel" ), &PopupMenu::add_multistate_item, DEFVAL (0 ), DEFVAL (-1 ), DEFVAL (0 ));
22152217
2216- ClassDB::bind_method (D_METHOD (" add_shortcut" , " shortcut" , " id" , " global" ), &PopupMenu::add_shortcut, DEFVAL (-1 ), DEFVAL (false ));
2217- ClassDB::bind_method (D_METHOD (" add_icon_shortcut" , " texture" , " shortcut" , " id" , " global" ), &PopupMenu::add_icon_shortcut, DEFVAL (-1 ), DEFVAL (false ));
2218+ ClassDB::bind_method (D_METHOD (" add_shortcut" , " shortcut" , " id" , " global" , " allow_echo " ), &PopupMenu::add_shortcut, DEFVAL (-1 ), DEFVAL ( false ), DEFVAL (false ));
2219+ ClassDB::bind_method (D_METHOD (" add_icon_shortcut" , " texture" , " shortcut" , " id" , " global" , " allow_echo " ), &PopupMenu::add_icon_shortcut, DEFVAL (-1 ), DEFVAL ( false ), DEFVAL (false ));
22182220 ClassDB::bind_method (D_METHOD (" add_check_shortcut" , " shortcut" , " id" , " global" ), &PopupMenu::add_check_shortcut, DEFVAL (-1 ), DEFVAL (false ));
22192221 ClassDB::bind_method (D_METHOD (" add_icon_check_shortcut" , " texture" , " shortcut" , " id" , " global" ), &PopupMenu::add_icon_check_shortcut, DEFVAL (-1 ), DEFVAL (false ));
22202222 ClassDB::bind_method (D_METHOD (" add_radio_check_shortcut" , " shortcut" , " id" , " global" ), &PopupMenu::add_radio_check_shortcut, DEFVAL (-1 ), DEFVAL (false ));
0 commit comments