From 478be2b9d98f5e0a0d75df1738d62f9fa671ac27 Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 26 Mar 2014 00:14:29 +0100 Subject: [PATCH] Preparations to save global hotkey for auto type in preferences --- MacPass.xcodeproj/project.pbxproj | 6 ++++++ MacPass/DDHotKey+Keydata.h | 16 ++++++++++++++++ MacPass/DDHotKey+Keydata.m | 30 ++++++++++++++++++++++++++++++ MacPass/MPSettingsHelper.h | 1 + MacPass/MPSettingsHelper.m | 1 + 5 files changed, 54 insertions(+) create mode 100644 MacPass/DDHotKey+Keydata.h create mode 100644 MacPass/DDHotKey+Keydata.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 25b8cf03..9cb97e6a 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -179,6 +179,7 @@ 4C7714AA176C998F00549F2A /* 43_TrashTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C7714A9176C998F00549F2A /* 43_TrashTemplate.pdf */; }; 4C7714AC176C9D4600549F2A /* 99_InfoTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C7714AB176C9D4600549F2A /* 99_InfoTemplate.pdf */; }; 4C77547516E55FE800970E02 /* MPInspectorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C77547416E55FE800970E02 /* MPInspectorViewController.m */; }; + 4C77C84118E240E000D1C42B /* DDHotKey+Keydata.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C77C84018E240E000D1C42B /* DDHotKey+Keydata.m */; }; 4C77E36715B84A240093A587 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C77E36615B84A240093A587 /* Cocoa.framework */; }; 4C77E37115B84A240093A587 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4C77E36F15B84A240093A587 /* InfoPlist.strings */; }; 4C77E37315B84A240093A587 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C77E37215B84A240093A587 /* main.m */; }; @@ -679,6 +680,8 @@ 4C7714AB176C9D4600549F2A /* 99_InfoTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = 99_InfoTemplate.pdf; path = Icons/99_InfoTemplate.pdf; sourceTree = ""; }; 4C77547316E55FE800970E02 /* MPInspectorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPInspectorViewController.h; sourceTree = ""; }; 4C77547416E55FE800970E02 /* MPInspectorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPInspectorViewController.m; sourceTree = ""; }; + 4C77C83F18E240E000D1C42B /* DDHotKey+Keydata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DDHotKey+Keydata.h"; sourceTree = ""; }; + 4C77C84018E240E000D1C42B /* DDHotKey+Keydata.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "DDHotKey+Keydata.m"; sourceTree = ""; }; 4C77E36215B84A240093A587 /* MacPass.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MacPass.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4C77E36615B84A240093A587 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 4C77E36915B84A240093A587 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; @@ -1044,6 +1047,8 @@ 4CC6DB7917D23719002C6091 /* KPKNode+IconImage.m */, 4CEED1C417D7BD0E007180F1 /* NSError+Messages.h */, 4CEED1C517D7BD0E007180F1 /* NSError+Messages.m */, + 4C77C83F18E240E000D1C42B /* DDHotKey+Keydata.h */, + 4C77C84018E240E000D1C42B /* DDHotKey+Keydata.m */, ); name = Categories; sourceTree = ""; @@ -2264,6 +2269,7 @@ 4C245B76176E1E3D0086100E /* DDData.m in Sources */, 4C245B77176E1E3D0086100E /* DDNumber.m in Sources */, 4C245B78176E1E3D0086100E /* DDRange.m in Sources */, + 4C77C84118E240E000D1C42B /* DDHotKey+Keydata.m in Sources */, 4C3C4EA618D6FEA100153127 /* TTTJSONTransformer.m in Sources */, 4C88C66918D9F8D600F43852 /* MPTemporaryFileStorageCenter.m in Sources */, 4C245B79176E1E3D0086100E /* HTTPAuthenticationRequest.m in Sources */, diff --git a/MacPass/DDHotKey+Keydata.h b/MacPass/DDHotKey+Keydata.h new file mode 100644 index 00000000..a5510a7d --- /dev/null +++ b/MacPass/DDHotKey+Keydata.h @@ -0,0 +1,16 @@ +// +// DDHotKey+Coding.h +// MacPass +// +// Created by Michael Starke on 25/03/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import "DDHotKeyCenter.h" + +@interface DDHotKey (Keydata) + +- (NSData *)keyData; +- (instancetype)initWithKeyData:(NSData *)data; + +@end diff --git a/MacPass/DDHotKey+Keydata.m b/MacPass/DDHotKey+Keydata.m new file mode 100644 index 00000000..db9497b5 --- /dev/null +++ b/MacPass/DDHotKey+Keydata.m @@ -0,0 +1,30 @@ +// +// DDHotKey+Coding.m +// MacPass +// +// Created by Michael Starke on 25/03/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import "DDHotKey+Keydata.h" + +@implementation DDHotKey (Keydata) + +- (instancetype)initWithKeyData:(NSData *)data { + NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; + unsigned short keyCode = [unarchiver decodeIntForKey:NSStringFromSelector(@selector(keyCode))]; + NSUInteger modiferFlags = [unarchiver decodeIntegerForKey:NSStringFromSelector(@selector(modifierFlags))]; + self = [DDHotKey hotKeyWithKeyCode:keyCode modifierFlags:modiferFlags task:nil]; + return self; +} + +- (NSData *)keyData { + NSMutableData *data = [[NSMutableData alloc] init]; + NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; + [archiver encodeInt:self.keyCode forKey:NSStringFromSelector(@selector(keyCode))]; + [archiver encodeInteger:self.modifierFlags forKey:NSStringFromSelector(@selector(modifierFlags))]; + [archiver finishEncoding]; + return [data copy]; +} + +@end diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index e6e8bd40..b973a021 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -49,6 +49,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyRememberKeyFilesForDatabases; /* Autotype */ APPKIT_EXTERN NSString *const kMPSettingsKeySendCommandForControlKey; APPKIT_EXTERN NSString *const kMPSettingsKeyEnableGlobalAutotype; +APPKIT_EXTERN NSString *const kMPSettingsKeyGlobalAutotypeKeyKey; /* Search */ APPKIT_EXTERN NSString *const kMPSettingsKeyEntrySearchFilterMode; diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index 42023968..06e2763b 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -34,6 +34,7 @@ NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"RememberKeyFiles NSString *const kMPSettingsKeySendCommandForControlKey = @"SendCommandKeyForControlKey"; NSString *const kMPSettingsKeyEnableGlobalAutotype = @"EnableGlobalAutotype"; +NSString *const kMPSettingsKeyGlobalAutotypeKeyKey = @"GlobalAutotypeKey"; NSString *const kMPSettingsKeyEntrySearchFilterMode = @"EntrySearchFilterMode";