aboutsummaryrefslogtreecommitdiffstats
path: root/Framework/MASShortcutBinder.h
diff options
context:
space:
mode:
authorTomáš Znamenáček2015-01-08 12:00:53 +0100
committerTomáš Znamenáček2015-01-08 12:00:53 +0100
commit9b919cba51e4cd11b0c4424930d6c18a1baec73c (patch)
treea8107774609d5f4263f7b79749d93e6c6ff2642d /Framework/MASShortcutBinder.h
parenta3a459b4e4e47bf18dccd5dc7f315389346e3d6c (diff)
parentea69d5939511f61a7082ba1e8ff46d247862a3fa (diff)
downloadMASShortcut-9b919cba51e4cd11b0c4424930d6c18a1baec73c.tar.bz2
Merge pull request #53 from zoul/2.0-candidate
Thank you very much!
Diffstat (limited to 'Framework/MASShortcutBinder.h')
-rw-r--r--Framework/MASShortcutBinder.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/Framework/MASShortcutBinder.h b/Framework/MASShortcutBinder.h
new file mode 100644
index 0000000..1592e90
--- /dev/null
+++ b/Framework/MASShortcutBinder.h
@@ -0,0 +1,67 @@
+#import "MASShortcutMonitor.h"
+
+/**
+ @brief Binds actions to user defaults keys.
+
+ If you store shortcuts in user defaults (for example by binding
+ a @p 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 @p MASShortcutMonitor. It
+ watches the changes in user defaults and updates the shortcut monitor
+ accordingly with the new shortcuts.
+*/
+@interface MASShortcutBinder : NSObject
+
+/**
+ @brief 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.
+*/
++ (instancetype) sharedBinder;
+
+/**
+ @brief The underlying shortcut monitor.
+*/
+@property(strong) MASShortcutMonitor *shortcutMonitor;
+
+/**
+ @brief Binding options customizing the access to user defaults.
+
+ As an example, you can use @p NSValueTransformerNameBindingOption to customize
+ the storage format used for the shortcuts. By default the shortcuts are converted
+ from @p NSData (@p NSKeyedUnarchiveFromDataTransformerName). Note that if the
+ binder is to work with @p MASShortcutView, both object have to use the same storage
+ format.
+*/
+@property(copy) NSDictionary *bindingOptions;
+
+/**
+ @brief 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.
+*/
+- (void) bindShortcutWithDefaultsKey: (NSString*) defaultsKeyName toAction: (dispatch_block_t) action;
+
+/**
+ @brief Disconnect the binding between user defaults and action.
+
+ In other words, the shortcut stored under the given key will no longer trigger an action.
+*/
+- (void) breakBindingWithDefaultsKey: (NSString*) defaultsKeyName;
+
+/**
+ @brief 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
+ @p bindingOptions and registered using @p registerDefaults.
+*/
+- (void) registerDefaultShortcuts: (NSDictionary*) defaultShortcuts;
+
+@end