From 8d407cb9593e1a805ee78a2cd92c88a9d125f9f3 Mon Sep 17 00:00:00 2001 From: michael starke Date: Sat, 16 Aug 2014 00:33:52 +0200 Subject: [PATCH] HotKey is not Updated correctly --- MacPass/Base.lproj/IntegrationSettings.xib | 2 +- MacPass/MPIntegrationSettingsController.m | 27 +++++++++++++--------- MacPass/MPSettingsHelper.h | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/MacPass/Base.lproj/IntegrationSettings.xib b/MacPass/Base.lproj/IntegrationSettings.xib index f0d77e1f..42ed8320 100644 --- a/MacPass/Base.lproj/IntegrationSettings.xib +++ b/MacPass/Base.lproj/IntegrationSettings.xib @@ -58,7 +58,7 @@ - + diff --git a/MacPass/MPIntegrationSettingsController.m b/MacPass/MPIntegrationSettingsController.m index 418f4d1f..9c0741ee 100644 --- a/MacPass/MPIntegrationSettingsController.m +++ b/MacPass/MPIntegrationSettingsController.m @@ -16,7 +16,7 @@ @interface MPIntegrationSettingsController () -@property (nonatomic, copy) NSData *globalAutotypeKeyData; +@property (nonatomic, strong) DDHotKey *hotKey; @end @@ -39,25 +39,30 @@ } - (void)awakeFromNib { + self.hotKey = [DDHotKey defaultHotKey]; NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController]; NSString *serverKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableHttpServer]; - NSString *globalAutotypeKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableGlobalAutotype]; + NSString *enableGlobalAutotypeKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableGlobalAutotype]; NSString *quicklookKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableQuicklookPreview]; - NSString *globalAutotypeDataKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey]; [self.enableServerCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:serverKeyPath options:nil]; [self.enableServerCheckbutton setEnabled:NO]; - [self.enableGlobalAutotypeCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:globalAutotypeKeyPath options:nil]; + [self.enableGlobalAutotypeCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:enableGlobalAutotypeKeyPath options:nil]; [self.enableQuicklookCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:quicklookKeyPath options:nil]; - [self.globalAutotypeKeyData bind:NSValueBinding toObject:defaultsController withKeyPath:globalAutotypeDataKeyPath options:nil]; + [self.hotKeyTextField bind:NSEnabledBinding toObject:defaultsController withKeyPath:enableGlobalAutotypeKeyPath options:nil]; + [self.hotKeyTextField bind:NSStringFromSelector(@selector(hotKey)) toObject:self withKeyPath:NSStringFromSelector(@selector(hotKey)) options:nil]; } -#pragma mark Properties -- (void)setGlobalAutotypeKeyData:(NSData *)globalAutotypeKeyData { - if(![_globalAutotypeKeyData isEqualToData:globalAutotypeKeyData]) { - _globalAutotypeKeyData = [globalAutotypeKeyData copy]; +- (void)setHotKey:(DDHotKey *)hotKey { + static NSData *defaultHotKeyData = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + defaultHotKeyData = [[DDHotKey defaultHotKey] keyData]; + }); + NSData *newData = [hotKey keyData]; + if(![newData isEqualToData:defaultHotKeyData]) { + [[NSUserDefaults standardUserDefaults] setObject:newData forKey:kMPSettingsKeyGlobalAutotypeKeyDataKey]; } - DDHotKey *hotKey = [[DDHotKey alloc] initWithKeyData:_globalAutotypeKeyData]; - self.hotKeyTextField.hotKey = hotKey; + _hotKey = hotKey; } diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index f90e0272..da94f14f 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -40,8 +40,8 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHideUsername; APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHidePassword; APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHideNotes; APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHideURL; - /* Document/Key Location store */ + APPKIT_EXTERN NSString *const kMPSettingsKeyLastDatabasePath; // Path to the last opened Database. Workaround if users have disabled the feautere in the OS APPKIT_EXTERN NSString *const kMPSettingsKeyRememeberdKeysForDatabases; // NSDictionary of all db file urls and the corresponding key file url APPKIT_EXTERN NSString *const kMPSettingsKeyRememberKeyFilesForDatabases; // YES if key files should be rememberd