From 0b08de641530f6537e4a3b7dbf26601fc927e1ad Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Tue, 5 Aug 2014 13:34:21 +0200 Subject: Created an umbrella header. Now you can just `#import `. --- Framework/Shortcut.h | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Framework/Shortcut.h (limited to 'Framework/Shortcut.h') diff --git a/Framework/Shortcut.h b/Framework/Shortcut.h new file mode 100644 index 0000000..3087a51 --- /dev/null +++ b/Framework/Shortcut.h @@ -0,0 +1,4 @@ +#import "MASShortcut.h" +#import "MASShortcutView+UserDefaults.h" +#import "MASShortcut+UserDefaults.h" +#import "MASShortcut+Monitoring.h" \ No newline at end of file -- cgit v1.2.3 From 444d1bccb9770738fa4ea40383c23f44a55089c2 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 6 Aug 2014 18:05:43 +0200 Subject: Refactored the shortcut dispatcher and bindings to user defaults. This is a big change that was hard to split into smaller commits. There’s now a new class to bind shortcuts to actions, a new class to bind user defaults’ keys to actions, and a new way to associate user defaults with the recorder control (MASShortcutView). I have also updated the demo app to go with the changes. The new class to associate shortcuts with actions is called MASShortcutMonitor. It wraps the Carbon hotkey magic and offers a simple interface to add a shortcut along with a block that should be run when the shortcut is pressed. It’s the lowest-level interface. Since the usual requirement is to store the shortcuts into user defaults, there’s also a higher-level interface offered by the MASShortcutBinder class. That takes a defaults key and associates it with a block. When the shortcut stored under the defaults key changes, the binder automatically switches to the new shortcut. The class is a wrapper built atop of the previous one, the MASShortcutMonitor – it simply adds, updates and removes shortcuts as the user defaults change. I have removed the special user defaults integration code from the recorder control (MASShortcutView) and replaced it with a small Cocoa Bindings shim. This means that in order to keep the recorder control in sync with the defaults you just have to call the usual bind:toObject:withKeyPath:options: method, like this: [_shortcutView bind:MASShortcutBinding toObject:[NSUserDefaultsController sharedUserDefaultsController] withKeyPath[@"values.ExampleDefaultsKey" options:@{NSValueTransformerNameBindingOption:NSKeyedUnarchiveFromDataTransformerName}]; That’s more verbose than the previous solution, but it’s much cleaner and can be swept under a convenience call if needed. I might also add a dictionaryValue property later that would make it possible to bind the value to user defaults directly, without a transformer, and would enable backward compatibility with Shortcut Recorder. --- Framework/Shortcut.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Framework/Shortcut.h') diff --git a/Framework/Shortcut.h b/Framework/Shortcut.h index 3087a51..dce07a5 100644 --- a/Framework/Shortcut.h +++ b/Framework/Shortcut.h @@ -1,4 +1,5 @@ #import "MASShortcut.h" -#import "MASShortcutView+UserDefaults.h" -#import "MASShortcut+UserDefaults.h" -#import "MASShortcut+Monitoring.h" \ No newline at end of file +#import "MASShortcutValidator.h" +#import "MASShortcutMonitor.h" +#import "MASShortcutBinder.h" +#import "MASShortcutView.h" -- cgit v1.2.3 From 942bbe849ed245d8b2e9afcb0a61d66b23beaef9 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Thu, 7 Aug 2014 10:47:34 +0200 Subject: Added a custom transformer to store shortcuts as dictionaries. The MASDictionaryTransformer class is used to save shortcuts to user defaults (and load them back) using a simple dictionary. The value stored in the user defaults looks like this: $ defaults read com.shpakovski.mac.Demo { MASDemoShortcut = { keyCode = 15; modifierFlags = 1048576; }; … } This storage format has got the distinct advantage of being compatible with the format used by Shortcut Recorder. In order to use it, you have to set proper binding options for MASShortcutBinder and the recorder control (MASShortcutView). --- Framework/Shortcut.h | 1 + 1 file changed, 1 insertion(+) (limited to 'Framework/Shortcut.h') diff --git a/Framework/Shortcut.h b/Framework/Shortcut.h index dce07a5..df33f17 100644 --- a/Framework/Shortcut.h +++ b/Framework/Shortcut.h @@ -2,4 +2,5 @@ #import "MASShortcutValidator.h" #import "MASShortcutMonitor.h" #import "MASShortcutBinder.h" +#import "MASDictionaryTransformer.h" #import "MASShortcutView.h" -- cgit v1.2.3 From 46aa323115c2ebe7128aba39c0296634d232bbf6 Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Thu, 7 Aug 2014 12:55:59 +0200 Subject: Added a simplified binding API for MASShortcutView. This returns the associatedUserDefaultsKey property used in previous code versions, only the implementation uses less magic. --- Framework/Shortcut.h | 1 + 1 file changed, 1 insertion(+) (limited to 'Framework/Shortcut.h') diff --git a/Framework/Shortcut.h b/Framework/Shortcut.h index df33f17..e131395 100644 --- a/Framework/Shortcut.h +++ b/Framework/Shortcut.h @@ -4,3 +4,4 @@ #import "MASShortcutBinder.h" #import "MASDictionaryTransformer.h" #import "MASShortcutView.h" +#import "MASShortcutView+Bindings.h" \ No newline at end of file -- cgit v1.2.3