Make Accelerator a standalone JS type.

This makes menu and global-shortcut share the same code on accelerator.
This commit is contained in:
Cheng Zhao 2014-08-05 00:00:39 +08:00
parent 28b9df24a6
commit 6dc01945af
9 changed files with 114 additions and 65 deletions

41
docs/api/accelerator.md Normal file
View file

@ -0,0 +1,41 @@
# Accelerator
An accelerator is string that represents a keyboard shortcut, it can contain
multiple modifiers and key codes, combined by the `+` character.
Examples:
* `Command+A`
* `Ctrl+Shift+Z`
## Platform notice
On Linux and Windows, the `Command` key would not have any effect, you can
use `CommandOrControl` which represents `Command` on OS X and `Control` on
Linux and Windows to define some accelerators.
## Available modifiers
* `Command` (or `Cmd` for short)
* `Control` (or `Ctrl` for short)
* `CommandOrControl` (or `CmdOrCtrl` for short)
* `Alt`
* `Shift`
## Available key codes
* `0` to `9`
* `A` to `Z`
* `F1` to `F24`
* Punctuations like `~`, `!`, `@`, `#`, `$`, etc.
* `Space`
* `Backspace`
* `Delete`
* `Insert`
* `Return` (or `Enter` as alias)
* `Up`, `Down`, `Left` and `Right`
* `Home` and `End`
* `PageUp` and `PageDown`
* `Escape` (or `Esc` for short)
* `VolumeUp`, `VolumeDown` and `VolumeMute`
* `MediaNextTrack`, `MediaPreviousTrack`, `MediaStop` and `MediaPlayPause`

View file

@ -22,33 +22,23 @@ globalShortcut.unregister('ctrl+x');
globalShortcut.unregisterAll();
```
## globalShortcut.register(keycode, callback)
## globalShortcut.register(accelerator, callback)
* `keycode` String
* `accelerator` [Accelerator](accelerator.md)
* `callback` Function
Registers a global shortcut of `keycode`, the `callback` would be called when
Registers a global shortcut of `accelerator`, the `callback` would be called when
the registered shortcut is pressed by user.
`keycode` is a string to specify shortcut key, such as "ctrl+shift+a".
## globalShortcut.isRegistered(accelerator)
A `keycode` consists of modifier and key two parts:
* `accelerator` [Accelerator](accelerator.md)
__Modifiers__: control(ctrl), command(cmd), alt, shift, commandorcontrol(cmdorctrl).
Returns whether shortcut of `accelerator` is registered.
__Supported keys__: 0-9, a-z, up, down, left, right, home, end, pagedown, pageup,
insert, delete, esc, space, backspace, tab, f1-f12, volumeup, volumedown, media
keys(medianextrack, mediaprevioustrack, mediastop, mediaplaypause).
## globalShortcut.unregister(accelerator)
## globalShortcut.isRegistered(keycode)
* `keycode` String
Return whether the shortcut is registered.
## globalShortcut.unregister(keycode)
* `keycode` String
* `accelerator` [Accelerator](accelerator.md)
Unregisters the global shortcut of `keycode`.

View file

@ -12,17 +12,9 @@
`radio`
* `label` String
* `sublabel` String
* `accelerator` String - In the form of `Command+R`, `Ctrl+C`,
`Shift+Command+D`, `D`, etc.
* `accelerator` [Accelerator](accelerator.md)
* `enabled` Boolean
* `visible` Boolean
* `checked` Boolean
* `submenu` Menu - Should be specified for `submenu` type menu item, when
it's specified the `type: 'submenu'` can be omitted for the menu item
## Notes on accelerator
On Linux and Windows, the `Command` key would not have any effect, you can
use `CommandOrControl` which represents `Command` on OS X and `Control` on
Linux and Windows to define some accelerators, you can also use its short
alias `CmdOrCtrl`.