aboutsummaryrefslogtreecommitdiffstats
path: root/Framework/MASShortcutBinderTests.m
diff options
context:
space:
mode:
authorTomáš Znamenáček2014-08-07 10:47:34 +0200
committerTomáš Znamenáček2015-01-07 15:42:21 +0100
commit942bbe849ed245d8b2e9afcb0a61d66b23beaef9 (patch)
tree2cc9e066d84355099d2334bceac6fa1fb7f5d1b8 /Framework/MASShortcutBinderTests.m
parent756601488fe195b0b14a8ac9c3c418140d5845f0 (diff)
downloadMASShortcut-942bbe849ed245d8b2e9afcb0a61d66b23beaef9.tar.bz2
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).
Diffstat (limited to 'Framework/MASShortcutBinderTests.m')
-rw-r--r--Framework/MASShortcutBinderTests.m13
1 files changed, 12 insertions, 1 deletions
diff --git a/Framework/MASShortcutBinderTests.m b/Framework/MASShortcutBinderTests.m
index 9259e9d..199eb2f 100644
--- a/Framework/MASShortcutBinderTests.m
+++ b/Framework/MASShortcutBinderTests.m
@@ -1,4 +1,4 @@
-#import "MASShortcutBinder.h"
+#import "Shortcut.h"
static NSString *const SampleDefaultsKey = @"sampleShortcut";
@@ -77,4 +77,15 @@ static NSString *const SampleDefaultsKey = @"sampleShortcut";
@"Bind after unbinding.");
}
+- (void) testTransformerDeserialization
+{
+ MASShortcut *shortcut = [MASShortcut shortcutWithKeyCode:5 modifierFlags:1048576];
+ NSDictionary *storedShortcut = @{@"keyCode": @5, @"modifierFlags": @1048576};
+ [_defaults setObject:storedShortcut forKey:SampleDefaultsKey];
+ [_binder setBindingOptions:@{NSValueTransformerBindingOption:[MASDictionaryTransformer new]}];
+ [_binder bindShortcutWithDefaultsKey:SampleDefaultsKey toAction:^{}];
+ XCTAssertTrue([_monitor isShortcutRegistered:shortcut],
+ @"Deserialize shortcut from user defaults using a custom transformer.");
+}
+
@end