Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Alt+Hotkey in menus work #194

Merged
merged 1 commit into from
May 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion Terminal.Gui/Views/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,36 @@ internal void NextMenu ()
OpenMenu (selected);
}

public override bool ProcessHotKey (KeyEvent kb)
internal bool FindAndOpenMenuByHotkey(KeyEvent kb)
{
int pos = 0;
var c = ((uint)kb.Key & (uint)Key.CharMask);
for (int i = 0; i < Menus.Length; i++)
{
// TODO: this code is duplicated, hotkey should be part of the MenuBarItem
var mi = Menus[i];
int p = mi.Title.IndexOf('_');
if (p != -1 && p + 1 < mi.Title.Length) {
if (mi.Title[p + 1] == c) {
OpenMenu(i);
return true;
}
}
}
return false;
}

public override bool ProcessHotKey (KeyEvent kb)
{
if (kb.Key == Key.F9) {
StartMenu ();
return true;
}

if (kb.IsAlt)
{
if (FindAndOpenMenuByHotkey(kb)) return true;
}
var kc = kb.KeyValue;

return base.ProcessHotKey (kb);
Expand Down