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:
parent
23a569970a
commit
9f6ddb4b5f
2 changed files with 15 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,13 +88,13 @@ menu.game = Game
|
|||
menu.game.key = G
|
||||
menu.game.new = New City...
|
||||
menu.game.new.key = N
|
||||
menu.game.new.shortcut = ctrl N
|
||||
menu.game.new.shortcut = command N
|
||||
menu.game.load = Load City...
|
||||
menu.game.load.key = L
|
||||
menu.game.load.shortcut = ctrl O
|
||||
menu.game.load.shortcut = command O
|
||||
menu.game.save = Save City
|
||||
menu.game.save.key = S
|
||||
menu.game.save.shortcut = ctrl S
|
||||
menu.game.save.shortcut = command S
|
||||
menu.game.save_as = Save City as...
|
||||
menu.game.save_as.key = A
|
||||
menu.game.exit = Exit
|
||||
|
|
Reference in a new issue