Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef399290e4 | |||
| 38fe428b19 | |||
| de647cf825 | |||
| 0db346d02b | |||
| 0972882368 | |||
| 72598e01af | |||
| 345da61b0d | |||
| fd6885abdb | |||
| 35e15f4950 | |||
| fc1ec3eb41 | |||
| bd0510c74d | |||
| 15dda682e4 | |||
| 04987a7bd5 | |||
| bf3a032c4b |
@@ -1,3 +1,10 @@
|
||||
2.1.2 2015/1/28
|
||||
- Better key equivalent handling for non-ASCII layouts.
|
||||
[Dmitry Obukhov]
|
||||
|
||||
2.1.1 2015/1/16
|
||||
- Another headerdoc fix for CocoaDocs, hopefully the last one.
|
||||
|
||||
2.1.0 2015/1/16
|
||||
- Added support for older OS X versions down to 10.6 included.
|
||||
- Headerdoc markup that plays better with CocoaDocs.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# How to Release a New Version
|
||||
|
||||
First, update the version numbers. (MASShortcut uses [Semantic Versioning](http://semver.org/), so please read the docs if you’re not sure what the deal is.) The version number is stored in `Framework/Info.plist` and `MASShortcut.podspec` (twice in both files).
|
||||
|
||||
Then update the `CHANGES` file. Add information about the new version (see the previous versions for an example) and add the release date.
|
||||
|
||||
Now commit the changes:
|
||||
|
||||
$ git commit -a -m "Version bump to x.y.z."
|
||||
|
||||
And tag the last commit:
|
||||
|
||||
$ git tag -a x.y.z
|
||||
|
||||
Now push both the commits and tags (`--tags`) to GitHub and push the new podspec to CocoaPods:
|
||||
|
||||
$ pod trunk push MASShortcut.podspec
|
||||
|
||||
This will run sanity checks on the podspec and fail if the spec does not validate.
|
||||
|
||||
That’s it. Go have a beer or a cup of tea to celebrate.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
@@ -15,9 +15,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.1.0</string>
|
||||
<string>2.1.2</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2.1.0</string>
|
||||
<string>2.1.2</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2014–2015 Vadim Shpakovski. All rights reserved.</string>
|
||||
</dict>
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
extern NSString *const MASDictionaryTransformerName;
|
||||
|
||||
/**
|
||||
Converts shortcuts for storage in user defaults.
|
||||
Converts shortcuts for storage in user defaults.
|
||||
|
||||
User defaults can’t stored custom types directly, they have to
|
||||
be serialized to `NSData` or some other supported type like an
|
||||
`NSDictionary`. In Cocoa Bindings, the conversion can be done
|
||||
using value transformers like this one.
|
||||
User defaults can’t stored custom types directly, they have to
|
||||
be serialized to `NSData` or some other supported type like an
|
||||
`NSDictionary`. In Cocoa Bindings, the conversion can be done
|
||||
using value transformers like this one.
|
||||
|
||||
There’s a built-in transformer (`NSKeyedUnarchiveFromDataTransformerName`)
|
||||
that converts any `NSCoding` types to `NSData`, but with shortcuts
|
||||
it makes sense to use a dictionary instead – the defaults look better
|
||||
when inspected with the `defaults` command-line utility and the
|
||||
format is compatible with an older sortcut library called Shortcut
|
||||
Recorder.
|
||||
There’s a built-in transformer (`NSKeyedUnarchiveFromDataTransformerName`)
|
||||
that converts any `NSCoding` types to `NSData`, but with shortcuts
|
||||
it makes sense to use a dictionary instead – the defaults look better
|
||||
when inspected with the `defaults` command-line utility and the
|
||||
format is compatible with an older sortcut library called Shortcut
|
||||
Recorder.
|
||||
*/
|
||||
@interface MASDictionaryTransformer : NSValueTransformer
|
||||
@end
|
||||
|
||||
+33
-22
@@ -1,59 +1,70 @@
|
||||
#import "MASKeyCodes.h"
|
||||
|
||||
/**
|
||||
A model class to hold a key combination.
|
||||
A model class to hold a key combination.
|
||||
|
||||
This class just represents a combination of keys. It does not care if
|
||||
the combination is valid or can be used as a hotkey, it doesn’t watch
|
||||
the input system for the shortcut appearance, nor it does access user
|
||||
defaults.
|
||||
This class just represents a combination of keys. It does not care if
|
||||
the combination is valid or can be used as a hotkey, it doesn’t watch
|
||||
the input system for the shortcut appearance, nor it does access user
|
||||
defaults.
|
||||
*/
|
||||
@interface MASShortcut : NSObject <NSSecureCoding, NSCopying>
|
||||
|
||||
/**
|
||||
The virtual key code for the keyboard key.
|
||||
The virtual key code for the keyboard key.
|
||||
|
||||
Hardware independent, same as in `NSEvent`. See `Events.h` in the HIToolbox
|
||||
framework for a complete list, or Command-click this symbol: `kVK_ANSI_A`.
|
||||
Hardware independent, same as in `NSEvent`. See `Events.h` in the HIToolbox
|
||||
framework for a complete list, or Command-click this symbol: `kVK_ANSI_A`.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSUInteger keyCode;
|
||||
|
||||
/**
|
||||
Cocoa keyboard modifier flags.
|
||||
Cocoa keyboard modifier flags.
|
||||
|
||||
Same as in `NSEvent`: `NSCommandKeyMask`, `NSAlternateKeyMask`, etc.
|
||||
Same as in `NSEvent`: `NSCommandKeyMask`, `NSAlternateKeyMask`, etc.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSUInteger modifierFlags;
|
||||
|
||||
/**
|
||||
Same as `keyCode`, just a different type.
|
||||
Same as `keyCode`, just a different type.
|
||||
*/
|
||||
@property (nonatomic, readonly) UInt32 carbonKeyCode;
|
||||
|
||||
/**
|
||||
Carbon modifier flags.
|
||||
Carbon modifier flags.
|
||||
|
||||
A bit sum of `cmdKey`, `optionKey`, etc.
|
||||
A bit sum of `cmdKey`, `optionKey`, etc.
|
||||
*/
|
||||
@property (nonatomic, readonly) UInt32 carbonFlags;
|
||||
|
||||
/**
|
||||
A string representing the “key” part of a shortcut, like the `5` in `⌘5`.
|
||||
A string representing the “key” part of a shortcut, like the `5` in `⌘5`.
|
||||
|
||||
@warning The value may change depending on the active keyboard layout.
|
||||
For example for the `^2` keyboard shortcut (`kVK_ANSI_2+NSControlKeyMask`
|
||||
to be precise) the `keyCodeString` is `2` on the US keyboard, but `ě` when
|
||||
the Czech keyboard layout is active. See the spec for details.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSString *keyCodeString;
|
||||
|
||||
/**
|
||||
A key-code string used in key equivalent matching.
|
||||
A key-code string used in key equivalent matching.
|
||||
|
||||
For precise meaning of “key equivalents” see the `keyEquivalent`
|
||||
property of `NSMenuItem`. Here the string is used to support shortcut
|
||||
validation (“is the shortcut already taken in this menu?”) and
|
||||
for display in `NSMenu`.
|
||||
For precise meaning of “key equivalents” see the `keyEquivalent`
|
||||
property of `NSMenuItem`. Here the string is used to support shortcut
|
||||
validation (“is the shortcut already taken in this menu?”) and
|
||||
for display in `NSMenu`.
|
||||
|
||||
The value of this property may differ from `keyCodeString`. For example
|
||||
the Russian keyboard has a `Г` (Ge) Cyrillic character in place of the
|
||||
latin `U` key. This means you can create a `^Г` shortcut, but in menus
|
||||
that’s always displayed as `^U`. So the `keyCodeString` returns `Г`
|
||||
and `keyCodeStringForKeyEquivalent` returns `U`.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSString *keyCodeStringForKeyEquivalent;
|
||||
|
||||
/**
|
||||
A string representing the shortcut modifiers, like the `⌘` in `⌘5`.
|
||||
A string representing the shortcut modifiers, like the `⌘` in `⌘5`.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSString *modifierFlagsString;
|
||||
|
||||
@@ -61,9 +72,9 @@
|
||||
+ (instancetype)shortcutWithKeyCode:(NSUInteger)code modifierFlags:(NSUInteger)flags;
|
||||
|
||||
/**
|
||||
Creates a new shortcut from an `NSEvent` object.
|
||||
Creates a new shortcut from an `NSEvent` object.
|
||||
|
||||
This is just a convenience initializer that reads the key code and modifiers from an `NSEvent`.
|
||||
This is just a convenience initializer that reads the key code and modifiers from an `NSEvent`.
|
||||
*/
|
||||
+ (instancetype)shortcutWithEvent:(NSEvent *)anEvent;
|
||||
|
||||
|
||||
@@ -139,10 +139,10 @@ static NSString *const MASShortcutModifierFlags = @"ModifierFlags";
|
||||
case 115: return NSStringFromMASKeyCode(kMASShortcutGlyphNorthwestArrow);
|
||||
}
|
||||
|
||||
// Everything else should be printable so look it up in the current keyboard
|
||||
// Everything else should be printable so look it up in the current ASCII capable keyboard layout
|
||||
OSStatus error = noErr;
|
||||
NSString *keystroke = nil;
|
||||
TISInputSourceRef inputSource = TISCopyCurrentKeyboardLayoutInputSource();
|
||||
TISInputSourceRef inputSource = TISCopyCurrentASCIICapableKeyboardLayoutInputSource();
|
||||
if (inputSource) {
|
||||
CFDataRef layoutDataRef = TISGetInputSourceProperty(inputSource, kTISPropertyUnicodeKeyLayoutData);
|
||||
if (layoutDataRef) {
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
#import "MASShortcutMonitor.h"
|
||||
|
||||
/**
|
||||
Binds actions to user defaults keys.
|
||||
Binds actions to user defaults keys.
|
||||
|
||||
If you store shortcuts in user defaults (for example by binding
|
||||
a `MASShortcutView` to user defaults), you can use this class to
|
||||
connect an action directly to a user defaults key. If the shortcut
|
||||
stored under the key changes, the action will get automatically
|
||||
updated to the new one.
|
||||
If you store shortcuts in user defaults (for example by binding
|
||||
a `MASShortcutView` to user defaults), you can use this class to
|
||||
connect an action directly to a user defaults key. If the shortcut
|
||||
stored under the key changes, the action will get automatically
|
||||
updated to the new one.
|
||||
|
||||
This class is mostly a wrapper around a `MASShortcutMonitor`. It
|
||||
watches the changes in user defaults and updates the shortcut monitor
|
||||
accordingly with the new shortcuts.
|
||||
This class is mostly a wrapper around a `MASShortcutMonitor`. It
|
||||
watches the changes in user defaults and updates the shortcut monitor
|
||||
accordingly with the new shortcuts.
|
||||
*/
|
||||
@interface MASShortcutBinder : NSObject
|
||||
|
||||
/**
|
||||
A convenience shared instance.
|
||||
A convenience shared instance.
|
||||
|
||||
You may use it so that you don’t have to manage an instance by hand,
|
||||
but it’s perfectly fine to allocate and use a separate instance instead.
|
||||
You may use it so that you don’t have to manage an instance by hand,
|
||||
but it’s perfectly fine to allocate and use a separate instance instead.
|
||||
*/
|
||||
+ (instancetype) sharedBinder;
|
||||
|
||||
/**
|
||||
The underlying shortcut monitor.
|
||||
The underlying shortcut monitor.
|
||||
*/
|
||||
@property(strong) MASShortcutMonitor *shortcutMonitor;
|
||||
|
||||
/**
|
||||
Binding options customizing the access to user defaults.
|
||||
Binding options customizing the access to user defaults.
|
||||
|
||||
As an example, you can use `NSValueTransformerNameBindingOption` to customize
|
||||
the storage format used for the shortcuts. By default the shortcuts are converted
|
||||
from `NSData` (`NSKeyedUnarchiveFromDataTransformerName`). Note that if the
|
||||
binder is to work with `MASShortcutView`, both object have to use the same storage
|
||||
format.
|
||||
As an example, you can use `NSValueTransformerNameBindingOption` to customize
|
||||
the storage format used for the shortcuts. By default the shortcuts are converted
|
||||
from `NSData` (`NSKeyedUnarchiveFromDataTransformerName`). Note that if the
|
||||
binder is to work with `MASShortcutView`, both object have to use the same storage
|
||||
format.
|
||||
*/
|
||||
@property(copy) NSDictionary *bindingOptions;
|
||||
|
||||
/**
|
||||
Binds given action to a shortcut stored under the given defaults key.
|
||||
Binds given action to a shortcut stored under the given defaults key.
|
||||
|
||||
In other words, no matter what shortcut you store under the given key,
|
||||
pressing it will always trigger the given action.
|
||||
In other words, no matter what shortcut you store under the given key,
|
||||
pressing it will always trigger the given action.
|
||||
*/
|
||||
- (void) bindShortcutWithDefaultsKey: (NSString*) defaultsKeyName toAction: (dispatch_block_t) action;
|
||||
|
||||
/**
|
||||
Disconnect the binding between user defaults and action.
|
||||
Disconnect the binding between user defaults and action.
|
||||
|
||||
In other words, the shortcut stored under the given key will no longer trigger an action.
|
||||
In other words, the shortcut stored under the given key will no longer trigger an action.
|
||||
*/
|
||||
- (void) breakBindingWithDefaultsKey: (NSString*) defaultsKeyName;
|
||||
|
||||
/**
|
||||
Register default shortcuts in user defaults.
|
||||
Register default shortcuts in user defaults.
|
||||
|
||||
This is a convenience frontent to `[NSUserDefaults registerDefaults]`.
|
||||
The dictionary should contain a map of user defaults’ keys to appropriate
|
||||
keyboard shortcuts. The shortcuts will be transformed according to
|
||||
`bindingOptions` and registered using `registerDefaults`.
|
||||
This is a convenience frontent to `[NSUserDefaults registerDefaults]`.
|
||||
The dictionary should contain a map of user defaults’ keys to appropriate
|
||||
keyboard shortcuts. The shortcuts will be transformed according to
|
||||
`bindingOptions` and registered using `registerDefaults`.
|
||||
*/
|
||||
- (void) registerDefaultShortcuts: (NSDictionary*) defaultShortcuts;
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#import "MASShortcut.h"
|
||||
|
||||
/**
|
||||
Executes action when a shortcut is pressed.
|
||||
Executes action when a shortcut is pressed.
|
||||
|
||||
There can only be one instance of this class, otherwise things
|
||||
will probably not work. (There’s a Carbon event handler inside
|
||||
and there can only be one Carbon event handler of a given type.)
|
||||
There can only be one instance of this class, otherwise things
|
||||
will probably not work. (There’s a Carbon event handler inside
|
||||
and there can only be one Carbon event handler of a given type.)
|
||||
*/
|
||||
@interface MASShortcutMonitor : NSObject
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
+ (instancetype) sharedMonitor;
|
||||
|
||||
/**
|
||||
Register a shortcut along with an action.
|
||||
Register a shortcut along with an action.
|
||||
|
||||
Attempting to insert an already registered shortcut probably won’t work.
|
||||
It may burn your house or cut your fingers. You have been warned.
|
||||
Attempting to insert an already registered shortcut probably won’t work.
|
||||
It may burn your house or cut your fingers. You have been warned.
|
||||
*/
|
||||
- (BOOL) registerShortcut: (MASShortcut*) shortcut withAction: (dispatch_block_t) action;
|
||||
- (BOOL) isShortcutRegistered: (MASShortcut*) shortcut;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#import "MASShortcutView.h"
|
||||
|
||||
/**
|
||||
A simplified interface to bind the recorder value to user defaults.
|
||||
A simplified interface to bind the recorder value to user defaults.
|
||||
|
||||
You can bind the `shortcutValue` to user defaults using the standard
|
||||
`bind:toObject:withKeyPath:options:` call, but since that’s a lot to type
|
||||
and read, here’s a simpler option.
|
||||
You can bind the `shortcutValue` to user defaults using the standard
|
||||
`bind:toObject:withKeyPath:options:` call, but since that’s a lot to type
|
||||
and read, here’s a simpler option.
|
||||
|
||||
Setting the `associatedUserDefaultsKey` binds the view’s shortcut value
|
||||
to the given user defaults key. You can supply a value transformer to convert
|
||||
values between user defaults and `MASShortcut`. If you don’t supply
|
||||
a transformer, the `NSUnarchiveFromDataTransformerName` will be used
|
||||
automatically.
|
||||
Setting the `associatedUserDefaultsKey` binds the view’s shortcut value
|
||||
to the given user defaults key. You can supply a value transformer to convert
|
||||
values between user defaults and `MASShortcut`. If you don’t supply
|
||||
a transformer, the `NSUnarchiveFromDataTransformerName` will be used
|
||||
automatically.
|
||||
|
||||
Set `associatedUserDefaultsKey` to `nil` to disconnect the binding.
|
||||
Set `associatedUserDefaultsKey` to `nil` to disconnect the binding.
|
||||
*/
|
||||
@interface MASShortcutView (Bindings)
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'MASShortcut'
|
||||
s.version = '2.1.0'
|
||||
s.version = '2.1.2'
|
||||
s.summary = 'Modern framework for managing global keyboard shortcuts compatible with Mac App Store'
|
||||
s.homepage = 'https://github.com/shpakovski/MASShortcut'
|
||||
s.license = 'BSD 2-clause'
|
||||
@@ -9,7 +9,7 @@ Pod::Spec.new do |s|
|
||||
|
||||
s.platform = :osx
|
||||
s.osx.deployment_target = "10.6"
|
||||
s.source = { :git => 'https://github.com/shpakovski/MASShortcut.git', :tag => '2.1.0' }
|
||||
s.source = { :git => 'https://github.com/shpakovski/MASShortcut.git', :tag => '2.1.2' }
|
||||
s.source_files = 'Framework/*.{h,m}'
|
||||
s.exclude_files = 'Framework/*Tests.m'
|
||||
s.osx.frameworks = 'Carbon', 'AppKit'
|
||||
|
||||
@@ -4,7 +4,27 @@
|
||||
|
||||
Some time ago Cocoa developers used a brilliant framework [ShortcutRecorder](http://wafflesoftware.net/shortcut/) for managing keyboard shortcuts in application preferences. However, it became incompatible with the new plugin architecture of Xcode 4.
|
||||
|
||||
The MASShortcut project introduces a modern API and user interface for recording, storing and using system-wide keyboard shortcuts. All code is compatible with recent Xcode & OS X versions and the sandboxed environment.
|
||||
The MASShortcut project introduces a modern API and user interface for recording, storing and using system-wide keyboard shortcuts.
|
||||
|
||||

|
||||
|
||||
Features:
|
||||
|
||||
* Record and display keyboard shortcuts
|
||||
* Watch for shortcuts and execute actions, system-wide
|
||||
* A nice, [documented API](http://cocoadocs.org/docsets/MASShortcut/)
|
||||
* Can be configured to be compatible with Shortcut Recorder
|
||||
* Can be installed both through CocoaPods and as a Git submodule
|
||||
* Mac App Store friendly
|
||||
* Works on OS X 10.6 and up
|
||||
* Hacking-friendly codebase covered with tests
|
||||
|
||||
Important features currently missing:
|
||||
|
||||
* Localisation
|
||||
* Accessibility
|
||||
|
||||
Pull requests welcome :)
|
||||
|
||||
# Installation
|
||||
|
||||
@@ -16,6 +36,8 @@ If you want to stick to the 1.x branch, you can use the version smart match oper
|
||||
|
||||
pod 'MASShortcut', '~> 1'
|
||||
|
||||
Or can use Git submodules and link against the MASShortcut framework.
|
||||
|
||||
# Usage
|
||||
|
||||
I hope, it is really easy:
|
||||
|
||||
@@ -12,4 +12,14 @@ Please stay high-level when writing the spec, do not document particular classes
|
||||
* If the shortcut is Cmd-W or Cmd-Q, the recording must be cancelled and the keypress passed through to the system, closing the window or quitting the app.
|
||||
* If a shortcut is already taken by system and is enabled, it must be rejected. (Examples: Cmd-S, Cmd-N. TBD: What exactly does it mean that the shortcut is “enabled”?)
|
||||
* TBD: Option-key handling.
|
||||
* All other shortcuts must be accepted. (Examples: Ctrl-Esc, Cmd-Delete, F16.)
|
||||
* All other shortcuts must be accepted. (Examples: Ctrl-Esc, Cmd-Delete, F16.)
|
||||
|
||||
# Formatting Shortcuts
|
||||
|
||||
On different keyboard layouts (such as US and Czech), a single shortcut (a combination of physical keys) may be formatted into different strings.
|
||||
|
||||
For example, the default system shortcut for toggling directly to Space #2 is Control–2. But when you switch to the Czech keyboard layout, the physical key with the `2` label now inserts the `ě` character. Thus, on most keyboard layouts the shortcut for toggling to Space #2 is called `^2`, but on the Czech layout it’s called `^ě`. (I stress that this is the same combination of hardware keys and the same `MASShortcut` instance.)
|
||||
|
||||
This is reflected by the system: When you open the System Preferences → Keyboard → Shortcuts pane, the shortcuts displayed depend on the currently selected keyboard layout (try switching between the US and Czech keyboard layouts and reopening the preference pane).
|
||||
|
||||
This means that the identity of a shortcut is given by its key code and modifiers (such as `kVK_ANSI_2` and `NSControlKeyMask`), not the `keyCodeString` returned by the `MASShortcut` class. This string may change depending on the current keyboard layout: `^2` with the US keyboard active, but `^ě` with the Czech keyboard active.
|
||||
|
||||
Reference in New Issue
Block a user