gui: make accelerator keystrokes adapt to operating system

keystrokes with string 'command' will be translated to
'meta' on Mac OS X and 'ctrl' for everything else
This commit is contained in:
Jason Long 2015-01-25 10:46:32 -08:00
parent 23a569970a
commit 9f6ddb4b5f
2 changed files with 15 additions and 6 deletions

View file

@ -429,9 +429,18 @@ public class MainWindow extends JFrame
}
if (strings.containsKey(prefix+".shortcut")) {
String shortcut = strings.getString(prefix+".shortcut");
menuItem.setAccelerator(
KeyStroke.getKeyStroke(shortcut)
);
KeyStroke keyStroke;
if (shortcut.startsWith("command")) {
KeyStroke key = KeyStroke.getKeyStroke(shortcut.substring(8));
keyStroke = KeyStroke.getKeyStroke(key.getKeyCode(),
key.getModifiers() |
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
);
}
else {
keyStroke = KeyStroke.getKeyStroke(shortcut);
}
menuItem.setAccelerator(keyStroke);
}
}