Menu: disable triggers when SetTriggerEnabled(false) is called

Triggers are a way to trigger menu items by ressing one of the letters
in their label. Normally that letter is underlined in the menu, but in
Haiku this is disabled by default and can't be enabled due to the lack
of a Menu preference (the code is there to draw the underline, still).

The trigger for each item is either assigned manually (using SetTrigger)
or automatically by the Interface Kit (picking a reasonable letter from
the label).

Triggers can be completly disabled at the menu level, however, in Haiku
this only disables drawing the underlines, and does not actually
disable the triggers, so items can still be invoked. This does not
match what is said in the Be Book. This commit actually disables the
triggers when SetTriggerEnabled(false) is called, making the keyboard
available for other uses if needed.

Possibly affected apps from a GitHub search on "SetTriggersEnabled":
- BeCJK
- 8dock
- Some of Tracker menus with lots of items, for example X-Ray menus

Change-Id: I1efa675b018fa524953c81e2dc2d456c28d6be8e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5971
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
PulkoMandy
2023-01-02 12:18:15 +00:00
committed by Adrien Destugues
parent 7a6e72c289
commit e9154f59e6
+10 -8
View File
@@ -589,16 +589,18 @@ BMenu::KeyDown(const char* bytes, int32 numBytes)
default:
{
uint32 trigger = BUnicodeChar::FromUTF8(&bytes);
if (AreTriggersEnabled()) {
uint32 trigger = BUnicodeChar::FromUTF8(&bytes);
for (uint32 i = CountItems(); i-- > 0;) {
BMenuItem* item = ItemAt(i);
if (item->fTriggerIndex < 0 || item->fTrigger != trigger)
continue;
for (uint32 i = CountItems(); i-- > 0;) {
BMenuItem* item = ItemAt(i);
if (item->fTriggerIndex < 0 || item->fTrigger != trigger)
continue;
_InvokeItem(item);
_QuitTracking(false);
break;
_InvokeItem(item);
_QuitTracking(false);
break;
}
}
break;
}