From 86a32313986fb9da606df40bc937298b2abeed35 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Fri, 9 Jan 2015 12:54:50 +0100 Subject: Added support for older OS X releases back to 10.6 included. Apart from turning off Auto Layout for the Demo project, the only thing remaining was several __weak qualifiers to prevent retain cycles in blocks. I have replaced them with __unsafe_unretained since __weak is not supported on 10.6. There should be no safety concerns here, since we are certain the pointers will remain valid. --- CHANGES | 3 +++ Demo/MainMenu.xib | 23 +++++++++++++++-------- Framework/MASShortcutView.m | 4 ++-- MASShortcut.xcodeproj/project.pbxproj | 4 ++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGES b/CHANGES index 8237ae6..115c78f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +Unreleased yet + - Added support for older OS X versions down to 10.6 included. + 2.0.1 2015/1/9 - Trivial Podspec fix. diff --git a/Demo/MainMenu.xib b/Demo/MainMenu.xib index a04814d..a4bf180 100644 --- a/Demo/MainMenu.xib +++ b/Demo/MainMenu.xib @@ -1,5 +1,5 @@ - + @@ -655,19 +655,22 @@ - + + - + + - - + + - - + + - + + diff --git a/Framework/MASShortcutView.m b/Framework/MASShortcutView.m index aace67e..74e14de 100644 --- a/Framework/MASShortcutView.m +++ b/Framework/MASShortcutView.m @@ -369,7 +369,7 @@ void *kUserDataHint = &kUserDataHint; static id eventMonitor = nil; if (shouldActivate) { - __weak MASShortcutView *weakSelf = self; + __unsafe_unretained MASShortcutView *weakSelf = self; NSEventMask eventMask = (NSKeyDownMask | NSFlagsChangedMask); eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^(NSEvent *event) { @@ -450,7 +450,7 @@ void *kUserDataHint = &kUserDataHint; static id observer = nil; NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; if (shouldActivate) { - __weak MASShortcutView *weakSelf = self; + __unsafe_unretained MASShortcutView *weakSelf = self; observer = [notificationCenter addObserverForName:NSWindowDidResignKeyNotification object:self.window queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) { weakSelf.recording = NO; diff --git a/MASShortcut.xcodeproj/project.pbxproj b/MASShortcut.xcodeproj/project.pbxproj index 2ab08a8..41b78d1 100644 --- a/MASShortcut.xcodeproj/project.pbxproj +++ b/MASShortcut.xcodeproj/project.pbxproj @@ -516,6 +516,7 @@ GCC_PREFIX_HEADER = Framework/Prefix.pch; INFOPLIST_FILE = Framework/Info.plist; INSTALL_PATH = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.6; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; WRAPPER_EXTENSION = framework; @@ -533,6 +534,7 @@ GCC_PREFIX_HEADER = Framework/Prefix.pch; INFOPLIST_FILE = Framework/Info.plist; INSTALL_PATH = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.6; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; WRAPPER_EXTENSION = framework; @@ -551,6 +553,7 @@ "$(inherited)", ); INFOPLIST_FILE = Demo/Info.plist; + MACOSX_DEPLOYMENT_TARGET = 10.6; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -564,6 +567,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = Demo/Prefix.pch; INFOPLIST_FILE = Demo/Info.plist; + MACOSX_DEPLOYMENT_TARGET = 10.6; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; -- cgit v1.2.3 From 5208c981afc49f4621dd70f1d193af1342846aeb Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Fri, 9 Jan 2015 13:12:03 +0100 Subject: Updated Deployment Target setting in podspec. --- MASShortcut.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MASShortcut.podspec b/MASShortcut.podspec index 8cf824f..ea0304e 100644 --- a/MASShortcut.podspec +++ b/MASShortcut.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| 'Tomáš Znamenáček' => 'tomas.znamenacek@gmail.com' } s.platform = :osx - s.osx.deployment_target = "10.7" + s.osx.deployment_target = "10.6" s.source = { :git => 'https://github.com/shpakovski/MASShortcut.git', :tag => '2.0.1' } s.source_files = 'Framework/*.{h,m}' s.exclude_files = 'Framework/*Tests.m' -- cgit v1.2.3 From b9b1964b3f5e8a7cf6ef76fbf2d019cdad9a9063 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Mon, 12 Jan 2015 16:34:18 +0100 Subject: Non-exclusive hotkey registration (#56). --- Framework/MASHotKey.m | 2 +- Framework/MASShortcutMonitor.h | 2 +- Framework/MASShortcutMonitor.m | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Framework/MASHotKey.m b/Framework/MASHotKey.m index 7886440..c5ab744 100644 --- a/Framework/MASHotKey.m +++ b/Framework/MASHotKey.m @@ -19,7 +19,7 @@ FourCharCode const MASHotKeySignature = 'MASS'; EventHotKeyID hotKeyID = { .signature = MASHotKeySignature, .id = _carbonID }; OSStatus status = RegisterEventHotKey([shortcut carbonKeyCode], [shortcut carbonFlags], - hotKeyID, GetEventDispatcherTarget(), kEventHotKeyExclusive, &_hotKeyRef); + hotKeyID, GetEventDispatcherTarget(), 0, &_hotKeyRef); if (status != noErr) { return nil; diff --git a/Framework/MASShortcutMonitor.h b/Framework/MASShortcutMonitor.h index 609686a..6d7fe82 100644 --- a/Framework/MASShortcutMonitor.h +++ b/Framework/MASShortcutMonitor.h @@ -18,7 +18,7 @@ Attempting to insert an already registered shortcut probably won’t work. It may burn your house or cut your fingers. You have been warned. */ -- (void) registerShortcut: (MASShortcut*) shortcut withAction: (dispatch_block_t) action; +- (BOOL) registerShortcut: (MASShortcut*) shortcut withAction: (dispatch_block_t) action; - (BOOL) isShortcutRegistered: (MASShortcut*) shortcut; - (void) unregisterShortcut: (MASShortcut*) shortcut; diff --git a/Framework/MASShortcutMonitor.m b/Framework/MASShortcutMonitor.m index 099f4b1..fce8022 100644 --- a/Framework/MASShortcutMonitor.m +++ b/Framework/MASShortcutMonitor.m @@ -45,11 +45,16 @@ static OSStatus MASCarbonEventCallback(EventHandlerCallRef, EventRef, void*); #pragma mark Registration -- (void) registerShortcut: (MASShortcut*) shortcut withAction: (dispatch_block_t) action +- (BOOL) registerShortcut: (MASShortcut*) shortcut withAction: (dispatch_block_t) action { MASHotKey *hotKey = [MASHotKey registeredHotKeyWithShortcut:shortcut]; - [hotKey setAction:action]; - [_hotKeys setObject:hotKey forKey:shortcut]; + if (hotKey) { + [hotKey setAction:action]; + [_hotKeys setObject:hotKey forKey:shortcut]; + return YES; + } else { + return NO; + } } - (void) unregisterShortcut: (MASShortcut*) shortcut -- cgit v1.2.3 From 8dc86c9b62f1f2a4649bf9e09b9afe0a92de00c1 Mon Sep 17 00:00:00 2001 From: Aral Balkan Date: Tue, 13 Jan 2015 17:21:27 +0000 Subject: Added explicit instructions for use in Swift The explicit Cocoa import had tripped me up. Would be good to save someone the same hassle.--- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 9a98ddb..17815c5 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,14 @@ _observableKeyPath = [@"values." stringByAppendingString:kPreferenceGlobalShortc context:kGlobalShortcutContext]; ``` +# Using in Swift projects + + 1. Install as a Pod using the latest CocoaPods with Swift support. + 2. Create a bridging header file [using the instructions here](http://swiftalicio.us/2014/11/using-cocoapods-from-swift/) + 3. Your bridging header file should contain the following [two](https://github.com/shpakovski/MASShortcut/issues/36) imports: + #import + #import + # Non-ARC Version If you like retain/release, please check out these forks: [heardrwt/MASShortcut](https://github.com/heardrwt/MASShortcut) and [chendo/MASShortcut](https://github.com/chendo/MASShortcut). However, the preferred way is to enable the `-fobjc-arc` in Xcode source options. -- cgit v1.2.3 From 988fcee20835f2df48bc4d29d351a797eba34a30 Mon Sep 17 00:00:00 2001 From: Vadim Shpakovski Date: Tue, 13 Jan 2015 20:45:29 +0300 Subject: Fix README. --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 17815c5..f4978ff 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,11 @@ _observableKeyPath = [@"values." stringByAppendingString:kPreferenceGlobalShortc 1. Install as a Pod using the latest CocoaPods with Swift support. 2. Create a bridging header file [using the instructions here](http://swiftalicio.us/2014/11/using-cocoapods-from-swift/) 3. Your bridging header file should contain the following [two](https://github.com/shpakovski/MASShortcut/issues/36) imports: - #import - #import + +```objective-c +#import +#import +``` # Non-ARC Version -- cgit v1.2.3 From cfc4bd64d0f5d784633b7ae5d9faf8a6a657f239 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 14 Jan 2015 09:59:28 +0100 Subject: Updated headerdoc markup for MASShortcutView+Bindings. --- Framework/MASShortcutView+Bindings.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Framework/MASShortcutView+Bindings.h b/Framework/MASShortcutView+Bindings.h index b0148e7..8cc84df 100644 --- a/Framework/MASShortcutView+Bindings.h +++ b/Framework/MASShortcutView+Bindings.h @@ -1,19 +1,19 @@ #import "MASShortcutView.h" /** - @brief 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 @p shortcutValue to user defaults using the standard - @p bind:toObject:withKeyPath:options: call, but since that’s a lot to type + 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 @p associatedUserDefaultsKey binds the view’s shortcut value + 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 @p MASShortcut. If you don’t supply - a transformer, the @p NSUnarchiveFromDataTransformerName will be used + values between user defaults and `MASShortcut`. If you don’t supply + a transformer, the `NSUnarchiveFromDataTransformerName` will be used automatically. - Set @p associatedUserDefaultsKey to @p nil to disconnect the binding. + Set `associatedUserDefaultsKey` to `nil` to disconnect the binding. */ @interface MASShortcutView (Bindings) -- cgit v1.2.3 From bdb64f0177a9bac79002ac929d0328b32f10143c Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 14 Jan 2015 10:03:31 +0100 Subject: Use the clear glyph instead of backspace for clearing a shortcut. The recording control used to display the backspace glyph (U+232B) on the button that clears the shortcut. That’s a bit confusing, since the same backspace glyph can also appear inside the control, representing the recorded shortcut. The clear glyph (U+2715, diagonal cross) seems like a better fit – it’s already used in similar context throughout the Apple UIs like search bars. --- Framework/MASShortcutView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Framework/MASShortcutView.m b/Framework/MASShortcutView.m index aace67e..9f26e07 100644 --- a/Framework/MASShortcutView.m +++ b/Framework/MASShortcutView.m @@ -188,7 +188,7 @@ NSString *const MASShortcutBinding = @"shortcutValue"; - (void)drawRect:(CGRect)dirtyRect { if (self.shortcutValue) { - [self drawInRect:self.bounds withTitle:NSStringFromMASKeyCode(self.recording ? kMASShortcutGlyphEscape : kMASShortcutGlyphDeleteLeft) + [self drawInRect:self.bounds withTitle:NSStringFromMASKeyCode(self.recording ? kMASShortcutGlyphEscape : kMASShortcutGlyphClear) alignment:NSRightTextAlignment state:NSOffState]; CGRect shortcutRect; -- cgit v1.2.3 From 27eace979e202116e44db3dc6acc9a8427ecaa0a Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 14 Jan 2015 12:54:49 +0100 Subject: Added test for hotkeys and shortcut monitor. --- Framework/MASHotKeyTests.m | 15 +++++++++++++++ Framework/MASShortcutMonitorTests.m | 23 +++++++++++++++++++++++ MASShortcut.xcodeproj/project.pbxproj | 8 ++++++++ 3 files changed, 46 insertions(+) create mode 100644 Framework/MASHotKeyTests.m create mode 100644 Framework/MASShortcutMonitorTests.m diff --git a/Framework/MASHotKeyTests.m b/Framework/MASHotKeyTests.m new file mode 100644 index 0000000..65361ab --- /dev/null +++ b/Framework/MASHotKeyTests.m @@ -0,0 +1,15 @@ +#import "MASHotKey.h" + +@interface MASHotKeyTests : XCTestCase +@end + +@implementation MASHotKeyTests + +- (void) testBasicFunctionality +{ + MASHotKey *hotKey = [MASHotKey registeredHotKeyWithShortcut: + [MASShortcut shortcutWithKeyCode:kVK_ANSI_H modifierFlags:NSCommandKeyMask|NSAlternateKeyMask]]; + XCTAssertNotNil(hotKey, @"Register a simple Cmd-Alt-H hotkey."); +} + +@end diff --git a/Framework/MASShortcutMonitorTests.m b/Framework/MASShortcutMonitorTests.m new file mode 100644 index 0000000..ccdcaef --- /dev/null +++ b/Framework/MASShortcutMonitorTests.m @@ -0,0 +1,23 @@ +#import "MASShortcutMonitor.h" + +@interface MASShortcutMonitorTests : XCTestCase +@end + +@implementation MASShortcutMonitorTests + +- (void) testMonitorCreation +{ + XCTAssertNotNil([MASShortcutMonitor sharedMonitor], @"Create a shared shortcut monitor."); +} + +- (void) testShortcutRegistration +{ + MASShortcutMonitor *monitor = [MASShortcutMonitor sharedMonitor]; + MASShortcut *shortcut = [MASShortcut shortcutWithKeyCode:kVK_ANSI_H modifierFlags:NSCommandKeyMask|NSAlternateKeyMask]; + XCTAssertTrue([monitor registerShortcut:shortcut withAction:NULL], @"Register a shortcut."); + XCTAssertTrue([monitor isShortcutRegistered:shortcut], @"Remember a previously registered shortcut."); + [monitor unregisterShortcut:shortcut]; + XCTAssertFalse([monitor isShortcutRegistered:shortcut], @"Forget shortcut after unregistering."); +} + +@end diff --git a/MASShortcut.xcodeproj/project.pbxproj b/MASShortcut.xcodeproj/project.pbxproj index 41b78d1..ea5125c 100644 --- a/MASShortcut.xcodeproj/project.pbxproj +++ b/MASShortcut.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 0D39DCA21A668A4400639145 /* MASHotKeyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D39DCA11A668A4400639145 /* MASHotKeyTests.m */; }; + 0D39DCA41A668E5500639145 /* MASShortcutMonitorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D39DCA31A668E5500639145 /* MASShortcutMonitorTests.m */; }; 0D827CD71990D4420010B8EF /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D827CD61990D4420010B8EF /* Cocoa.framework */; }; 0D827D251990D55E0010B8EF /* MASShortcut.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D827D1B1990D55E0010B8EF /* MASShortcut.h */; settings = {ATTRIBUTES = (Public, ); }; }; 0D827D261990D55E0010B8EF /* MASShortcut.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D827D1C1990D55E0010B8EF /* MASShortcut.m */; }; @@ -64,6 +66,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0D39DCA11A668A4400639145 /* MASHotKeyTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MASHotKeyTests.m; path = Framework/MASHotKeyTests.m; sourceTree = ""; }; + 0D39DCA31A668E5500639145 /* MASShortcutMonitorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MASShortcutMonitorTests.m; path = Framework/MASShortcutMonitorTests.m; sourceTree = ""; }; 0D827CD31990D4420010B8EF /* MASShortcut.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MASShortcut.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 0D827CD61990D4420010B8EF /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 0D827CD91990D4420010B8EF /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -231,8 +235,10 @@ children = ( 0DC2F17419922798003A0131 /* MASHotKey.h */, 0DC2F17519922798003A0131 /* MASHotKey.m */, + 0D39DCA11A668A4400639145 /* MASHotKeyTests.m */, 0D827DA319912D240010B8EF /* MASShortcutMonitor.h */, 0D827DA419912D240010B8EF /* MASShortcutMonitor.m */, + 0D39DCA31A668E5500639145 /* MASShortcutMonitorTests.m */, ); name = Monitoring; sourceTree = ""; @@ -419,6 +425,8 @@ 0DC2F190199372B4003A0131 /* MASDictionaryTransformerTests.m in Sources */, 0D827D9419910B740010B8EF /* MASShortcutTests.m in Sources */, 0DC2F18919925F8F003A0131 /* MASShortcutBinderTests.m in Sources */, + 0D39DCA21A668A4400639145 /* MASHotKeyTests.m in Sources */, + 0D39DCA41A668E5500639145 /* MASShortcutMonitorTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; -- cgit v1.2.3 From 1baa2bae9d63093d64239992dc702b10d149b7c5 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Fri, 16 Jan 2015 09:42:37 +0100 Subject: Removed section about ARC support from README. There are now two officially supported ways to use MASShortcut: through including the Xcode project in your app’s workspace and linking against MASShortcut.framework, and through CocoaPods. Both options work well in both ARC and MRC projects with no additional settings needed. (I use MASShortcut in a MRC project myself.) --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index f4978ff..c79dbee 100644 --- a/README.md +++ b/README.md @@ -106,10 +106,6 @@ _observableKeyPath = [@"values." stringByAppendingString:kPreferenceGlobalShortc #import ``` -# Non-ARC Version - -If you like retain/release, please check out these forks: [heardrwt/MASShortcut](https://github.com/heardrwt/MASShortcut) and [chendo/MASShortcut](https://github.com/chendo/MASShortcut). However, the preferred way is to enable the `-fobjc-arc` in Xcode source options. - # Copyright MASShortcut is licensed under the 2-clause BSD license. -- cgit v1.2.3 From 3ebbb7efde52d97abf9d215e5446e10a30223057 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Fri, 16 Jan 2015 11:53:19 +0100 Subject: Version bump to 2.1.0. --- CHANGES | 2 +- Framework/Info.plist | 4 ++-- MASShortcut.podspec | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 22c4962..bf4c0fc 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -Unreleased yet +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. diff --git a/Framework/Info.plist b/Framework/Info.plist index 91a62a8..2ba5f73 100644 --- a/Framework/Info.plist +++ b/Framework/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.0.0 + 2.1.0 CFBundleVersion - 2.0.0 + 2.1.0 NSHumanReadableCopyright Copyright © 2014–2015 Vadim Shpakovski. All rights reserved. diff --git a/MASShortcut.podspec b/MASShortcut.podspec index ea0304e..80447da 100644 --- a/MASShortcut.podspec +++ b/MASShortcut.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MASShortcut' - s.version = '2.0.1' + s.version = '2.1.0' 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.0.1' } + s.source = { :git => 'https://github.com/shpakovski/MASShortcut.git', :tag => '2.1.0' } s.source_files = 'Framework/*.{h,m}' s.exclude_files = 'Framework/*Tests.m' s.osx.frameworks = 'Carbon', 'AppKit' -- cgit v1.2.3 From bf3a032c4b9205437003a7decca66bd6533fc8bb Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Fri, 16 Jan 2015 12:57:08 +0100 Subject: Decrease headerdoc indenting to appease appledoc (see #55). I think I have finally found out the reason for CocoaDocs ignoring our markup: I have indented the documentation by four spaces, which was interpreted as “code” by appledoc. Trying now without the indent, that should finally help. --- Framework/MASDictionaryTransformer.h | 22 +++++++------- Framework/MASShortcut.h | 44 +++++++++++++-------------- Framework/MASShortcutBinder.h | 58 ++++++++++++++++++------------------ Framework/MASShortcutMonitor.h | 14 ++++----- Framework/MASShortcutView+Bindings.h | 20 ++++++------- 5 files changed, 79 insertions(+), 79 deletions(-) diff --git a/Framework/MASDictionaryTransformer.h b/Framework/MASDictionaryTransformer.h index 8f8e084..6e53fd8 100644 --- a/Framework/MASDictionaryTransformer.h +++ b/Framework/MASDictionaryTransformer.h @@ -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 diff --git a/Framework/MASShortcut.h b/Framework/MASShortcut.h index 8ba1b53..e175317 100644 --- a/Framework/MASShortcut.h +++ b/Framework/MASShortcut.h @@ -1,59 +1,59 @@ #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 /** - 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`. */ @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`. */ @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 +61,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; diff --git a/Framework/MASShortcutBinder.h b/Framework/MASShortcutBinder.h index 1e65e0d..e7406de 100644 --- a/Framework/MASShortcutBinder.h +++ b/Framework/MASShortcutBinder.h @@ -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; diff --git a/Framework/MASShortcutMonitor.h b/Framework/MASShortcutMonitor.h index a1aaaa8..dc3d458 100644 --- a/Framework/MASShortcutMonitor.h +++ b/Framework/MASShortcutMonitor.h @@ -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; diff --git a/Framework/MASShortcutView+Bindings.h b/Framework/MASShortcutView+Bindings.h index 8cc84df..01b2246 100644 --- a/Framework/MASShortcutView+Bindings.h +++ b/Framework/MASShortcutView+Bindings.h @@ -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) -- cgit v1.2.3 From 04987a7bd512ef55425e552233fa5440531ee80f Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Fri, 16 Jan 2015 12:59:29 +0100 Subject: Version bump to 2.1.1. --- CHANGES | 3 +++ Framework/Info.plist | 4 ++-- MASShortcut.podspec | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index bf4c0fc..2031116 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +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. diff --git a/Framework/Info.plist b/Framework/Info.plist index 2ba5f73..8aafeae 100644 --- a/Framework/Info.plist +++ b/Framework/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.1.0 + 2.1.1 CFBundleVersion - 2.1.0 + 2.1.1 NSHumanReadableCopyright Copyright © 2014–2015 Vadim Shpakovski. All rights reserved. diff --git a/MASShortcut.podspec b/MASShortcut.podspec index 80447da..bf87a7b 100644 --- a/MASShortcut.podspec +++ b/MASShortcut.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MASShortcut' - s.version = '2.1.0' + s.version = '2.1.1' 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.1' } s.source_files = 'Framework/*.{h,m}' s.exclude_files = 'Framework/*Tests.m' s.osx.frameworks = 'Carbon', 'AppKit' -- cgit v1.2.3 From 15dda682e4887e31db4179679b30126c2e0f04d1 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Mon, 19 Jan 2015 15:27:36 +0100 Subject: Added a list of features and a screenshot of the demo project. --- Demo/screenshot.png | Bin 0 -> 89585 bytes README.md | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Demo/screenshot.png diff --git a/Demo/screenshot.png b/Demo/screenshot.png new file mode 100644 index 0000000..96172e4 Binary files /dev/null and b/Demo/screenshot.png differ diff --git a/README.md b/README.md index c79dbee..48b991d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,26 @@ 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. + +![Screenshot of the demo project](/Demo/screenshot.png?raw=true "This is how the demo looks like") + +Features: + +* Record and display keyboard shortcuts +* Watch for shortcuts and execute actions, system-wide +* 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 -- cgit v1.2.3 From bd0510c74da08075a81a5f2ae054dd9d073ee77e Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Mon, 19 Jan 2015 15:28:31 +0100 Subject: Smaller screenshot. --- Demo/screenshot.png | Bin 89585 -> 71408 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Demo/screenshot.png b/Demo/screenshot.png index 96172e4..a6022f8 100644 Binary files a/Demo/screenshot.png and b/Demo/screenshot.png differ -- cgit v1.2.3 From fc1ec3eb418df2a2f9b998344c28ce96975763e6 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Mon, 19 Jan 2015 15:32:23 +0100 Subject: Linked to the API documentation. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 48b991d..37697c6 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ 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 -- cgit v1.2.3 From 35e15f495028726ec0c39e36678b928f8f499a9c Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Mon, 19 Jan 2015 15:37:14 +0100 Subject: Mentioned installation via Git submodules. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 37697c6..fccf923 100644 --- a/README.md +++ b/README.md @@ -36,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: -- cgit v1.2.3 From fd6885abdb15a8306f0130c42cca421df3b19bee Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Mon, 19 Jan 2015 15:47:35 +0100 Subject: Improved screenshot quality. --- Demo/screenshot.png | Bin 71408 -> 53006 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Demo/screenshot.png b/Demo/screenshot.png index a6022f8..926f4ca 100644 Binary files a/Demo/screenshot.png and b/Demo/screenshot.png differ -- cgit v1.2.3 From 345da61b0d2b111d6184532c4e37891bdc3de411 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Mon, 26 Jan 2015 09:43:47 +0100 Subject: Added a short release guide. --- CONTRIBUTING.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9f53769 --- /dev/null +++ b/CONTRIBUTING.md @@ -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. \ No newline at end of file -- cgit v1.2.3 From 72598e01af7ca932597206e95d03ce043f4bc783 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 28 Jan 2015 10:13:53 +0100 Subject: Added a note about shortcut rendering in the spec. --- Spec.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Spec.md b/Spec.md index 9a8663a..3f4b3ba 100644 --- a/Spec.md +++ b/Spec.md @@ -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.) \ No newline at end of file +* All other shortcuts must be accepted. (Examples: Ctrl-Esc, Cmd-Delete, F16.) + +# Rendering Shortcuts + +On different keyboard layouts (such as US and Czech), a single shortcut (a combination of physical keys) can have different “names”. + +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 `^2`, but on the Czech layout it’s `^ě`. (I stress that this is the same combination of hardware keys.) + +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. \ No newline at end of file -- cgit v1.2.3 From 097288236819dd5ded2e9479fc1bce9509e30047 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 28 Jan 2015 10:16:15 +0100 Subject: Clarified the spec part about rendering shortcuts. --- Spec.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Spec.md b/Spec.md index 3f4b3ba..16bb46f 100644 --- a/Spec.md +++ b/Spec.md @@ -18,8 +18,8 @@ Please stay high-level when writing the spec, do not document particular classes On different keyboard layouts (such as US and Czech), a single shortcut (a combination of physical keys) can have different “names”. -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 `^2`, but on the Czech layout it’s `^ě`. (I stress that this is the same combination of hardware keys.) +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. \ No newline at end of file +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. -- cgit v1.2.3 From 0db346d02be95bd66af52c1b9cd88439084bf295 Mon Sep 17 00:00:00 2001 From: Dmitry Obukhov Date: Tue, 27 Jan 2015 21:53:35 +0300 Subject: Better key equivalent handling on non-ASCII keyboard layouts. See #60 for a discussion. In short, keyCodeStringForKeyEquivalent should be now correct even with non-ASCII keyboard layouts such as Russian. --- CHANGES | 4 ++++ Framework/MASShortcut.m | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 2031116..5231f01 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +Not released yet: + - 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. diff --git a/Framework/MASShortcut.m b/Framework/MASShortcut.m index e6fa63d..ef3385d 100644 --- a/Framework/MASShortcut.m +++ b/Framework/MASShortcut.m @@ -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) { -- cgit v1.2.3 From de647cf8251faa14239bdbbc8027116f6e5627c6 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 28 Jan 2015 15:19:46 +0100 Subject: Talk about shortcut “formatting” instead of “rendering”. --- Spec.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Spec.md b/Spec.md index 16bb46f..e13576c 100644 --- a/Spec.md +++ b/Spec.md @@ -14,12 +14,12 @@ Please stay high-level when writing the spec, do not document particular classes * TBD: Option-key handling. * All other shortcuts must be accepted. (Examples: Ctrl-Esc, Cmd-Delete, F16.) -# Rendering Shortcuts +# Formatting Shortcuts -On different keyboard layouts (such as US and Czech), a single shortcut (a combination of physical keys) can have different “names”. +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. +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. -- cgit v1.2.3 From 38fe428b192dc4d18faeadc8585db7580fb99420 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 28 Jan 2015 15:32:20 +0100 Subject: Documented that keyCodeString depends on active keyboard layout. --- Framework/MASShortcut.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Framework/MASShortcut.h b/Framework/MASShortcut.h index e175317..8f420e4 100644 --- a/Framework/MASShortcut.h +++ b/Framework/MASShortcut.h @@ -39,6 +39,11 @@ /** 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; @@ -49,6 +54,12 @@ 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; -- cgit v1.2.3 From ef399290e4a9b8e575688807be301e975c6a543e Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 28 Jan 2015 16:11:36 +0100 Subject: Version bump to 2.1.2. --- CHANGES | 2 +- Framework/Info.plist | 4 ++-- MASShortcut.podspec | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 5231f01..1cf1502 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -Not released yet: +2.1.2 2015/1/28 - Better key equivalent handling for non-ASCII layouts. [Dmitry Obukhov] diff --git a/Framework/Info.plist b/Framework/Info.plist index 8aafeae..679ef34 100644 --- a/Framework/Info.plist +++ b/Framework/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.1.1 + 2.1.2 CFBundleVersion - 2.1.1 + 2.1.2 NSHumanReadableCopyright Copyright © 2014–2015 Vadim Shpakovski. All rights reserved. diff --git a/MASShortcut.podspec b/MASShortcut.podspec index bf87a7b..fb89e5a 100644 --- a/MASShortcut.podspec +++ b/MASShortcut.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'MASShortcut' - s.version = '2.1.1' + 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.1' } + 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' -- cgit v1.2.3 From aeaad2986f322ce7fcdde2ef7fb8049a62f5a0d6 Mon Sep 17 00:00:00 2001 From: shinya takahashi Date: Mon, 19 Jan 2015 18:03:33 +0900 Subject: Added options to show button that delete hot key. --- Framework/MASShortcutView.m | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Framework/MASShortcutView.m b/Framework/MASShortcutView.m index d521880..cb6f3d9 100644 --- a/Framework/MASShortcutView.m +++ b/Framework/MASShortcutView.m @@ -13,6 +13,7 @@ NSString *const MASShortcutBinding = @"shortcutValue"; @property (nonatomic, getter = isHinting) BOOL hinting; @property (nonatomic, copy) NSString *shortcutPlaceholder; +@property (nonatomic, assign) BOOL showsDeleteButton; @end @@ -57,6 +58,7 @@ NSString *const MASShortcutBinding = @"shortcutValue"; _shortcutCell.font = [[NSFontManager sharedFontManager] convertFont:_shortcutCell.font toSize:BUTTON_FONT_SIZE]; _shortcutValidator = [MASShortcutValidator sharedValidator]; _enabled = YES; + _showsDeleteButton = YES; [self resetShortcutCellStyle]; } @@ -188,9 +190,15 @@ NSString *const MASShortcutBinding = @"shortcutValue"; - (void)drawRect:(CGRect)dirtyRect { if (self.shortcutValue) { - [self drawInRect:self.bounds withTitle:NSStringFromMASKeyCode(self.recording ? kMASShortcutGlyphEscape : kMASShortcutGlyphClear) - alignment:NSRightTextAlignment state:NSOffState]; - + NSString *buttonTitle; + if (self.recording) { + buttonTitle = NSStringFromMASKeyCode(kMASShortcutGlyphEscape); + } else if (self.showsDeleteButton) { + buttonTitle = NSStringFromMASKeyCode(kMASShortcutGlyphClear); + } + if (buttonTitle != nil) { + [self drawInRect:self.bounds withTitle:buttonTitle alignment:NSRightTextAlignment state:NSOffState]; + } CGRect shortcutRect; [self getShortcutRect:&shortcutRect hintRect:NULL]; NSString *title = (self.recording -- cgit v1.2.3