From c460b2187a04dd734d9c2d61ce7797dbf44116c4 Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 19 Mar 2014 22:40:25 +0100 Subject: [PATCH] fixed #161 settings to copy to clipboard on password creation are preserved. Default behaviour is to restore the last sate --- MacPass/MPPasswordCreatorViewController.m | 30 ++++++++++++---------- MacPass/MPSettingsHelper.h | 6 +++++ MacPass/MPSettingsHelper.m | 6 +++++ MacPass/PasswordCreatorView.xib | 21 ++++++--------- MacPass/en.lproj/Localizable.strings | Bin 9030 -> 9076 bytes 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/MacPass/MPPasswordCreatorViewController.m b/MacPass/MPPasswordCreatorViewController.m index eefab323..af5cb939 100644 --- a/MacPass/MPPasswordCreatorViewController.m +++ b/MacPass/MPPasswordCreatorViewController.m @@ -10,6 +10,7 @@ #import "MPPasteBoardController.h" #import "NSString+MPPasswordCreation.h" #import "MPUniqueCharactersFormatter.h" +#import "MPSettingsHelper.h" typedef NS_ENUM(NSUInteger, MPPasswordRating) { MPPasswordTerrible = 10, @@ -19,7 +20,6 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { MPPasswordStrong = 60 }; - /* 0 - 20 Terrible @@ -43,7 +43,7 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { @property (weak) IBOutlet NSTextField *passwordLengthTextField; @property (weak) IBOutlet NSTextField *customCharactersTextField; @property (weak) IBOutlet NSSlider *passwordLengthSlider; -@property (weak) IBOutlet NSButton *addPasswordToPasteboardButton; +@property (weak) IBOutlet NSButton *shouldCopyPasswordToPasteboardButton; @property (weak) IBOutlet NSButton *upperCaseButton; @property (weak) IBOutlet NSButton *lowerCaseButton; @property (weak) IBOutlet NSButton *numbersButton; @@ -79,8 +79,7 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { return self; } - -- (void)didLoadView { +- (void)awakeFromNib { [self.passwordLengthSlider setMinValue:MIN_PASSWORD_LENGTH]; [self.passwordLengthSlider setMaxValue:MAX_PASSWORD_LENGTH]; [self.passwordLengthSlider setContinuous:YES]; @@ -95,14 +94,18 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { [self.entropyIndicator bind:NSValueBinding toObject:self withKeyPath:@"entropy" options:nil]; [self.entropyTextField bind:NSValueBinding toObject:self withKeyPath:@"entropy" options:nil]; - + [self.customCharactersTextField setDelegate:self]; - [_customButton bind:NSValueBinding toObject:self withKeyPath:@"useCustomString" options:nil]; - - [_numbersButton setTag:MPPasswordCharactersNumbers]; - [_upperCaseButton setTag:MPPasswordCharactersUpperCase]; - [_lowerCaseButton setTag:MPPasswordCharactersLowerCase]; - [_symbolsButton setTag:MPPasswordCharactersSymbols]; + [self.customButton bind:NSValueBinding toObject:self withKeyPath:@"useCustomString" options:nil]; + + NSString *copyToPasteBoardKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyCopyGeneratedPasswordToClipboard]; + NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController]; + [self.shouldCopyPasswordToPasteboardButton bind:NSValueBinding toObject:defaultsController withKeyPath:copyToPasteBoardKeyPath options:nil]; + + [self.numbersButton setTag:MPPasswordCharactersNumbers]; + [self.upperCaseButton setTag:MPPasswordCharactersUpperCase]; + [self.lowerCaseButton setTag:MPPasswordCharactersLowerCase]; + [self.symbolsButton setTag:MPPasswordCharactersSymbols]; [self _resetCharacters]; [self _generatePassword:nil]; @@ -131,17 +134,18 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { - (IBAction)_usePassword:(id)sender { self.generatedPassword = _password; - if([self.addPasswordToPasteboardButton state] == NSOnState) { + if([self.shouldCopyPasswordToPasteboardButton state] == NSOnState) { [[MPPasteBoardController defaultController] copyObjects:@[_password]]; } + /* Since we might be displayed inside a NSPopup or a NSWindow, search for the target */ id target = [NSApp targetForAction:@selector(performClose:)]; [target performClose:nil]; } - (IBAction)_cancel:(id)sender { + /* Since we might be displayed inside a NSPopup or a NSWindow, search for the target */ id target = [NSApp targetForAction:@selector(performClose:)]; [target performClose:nil]; - } #pragma mark - diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index 960e599a..e6e8bd40 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -53,6 +53,12 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyEnableGlobalAutotype; /* Search */ APPKIT_EXTERN NSString *const kMPSettingsKeyEntrySearchFilterMode; +/* Quicklook */ +APPKIT_EXTERN NSString *const kMPSettingsKeyEnableQuicklookPreview; + +/* Password Generation */ +APPKIT_EXTERN NSString *const kMPSettingsKeyCopyGeneratedPasswordToClipboard; + typedef NS_ENUM(NSUInteger, MPPasswordEncoding) { MPPasswordEncodingUTF8, MPPasswordEncodingASCII, diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index 59b91348..42023968 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -37,6 +37,10 @@ NSString *const kMPSettingsKeyEnableGlobalAutotype = @"EnableGlobalAuto NSString *const kMPSettingsKeyEntrySearchFilterMode = @"EntrySearchFilterMode"; +NSString *const kMPSettingsKeyEnableQuicklookPreview = @"EnableQuicklookPreview"; + +NSString *const kMPSettingsKeyCopyGeneratedPasswordToClipboard = @"CopyGeneratedPasswordToClipboard"; + @implementation MPSettingsHelper + (void)setupDefaults { @@ -73,6 +77,8 @@ NSString *const kMPSettingsKeyEntrySearchFilterMode = @"EntrySearchFilte kMPSettingsKeySendCommandForControlKey: @YES, kMPSettingsKeyEntrySearchFilterMode: @0, kMPSettingsKeyEnableGlobalAutotype: @NO, + kMPSettingsKeyEnableQuicklookPreview: @NO, + kMPSettingsKeyCopyGeneratedPasswordToClipboard: @NO, }; } diff --git a/MacPass/PasswordCreatorView.xib b/MacPass/PasswordCreatorView.xib index a50ce3bd..04fd546e 100644 --- a/MacPass/PasswordCreatorView.xib +++ b/MacPass/PasswordCreatorView.xib @@ -1,15 +1,14 @@ - + - + - @@ -20,6 +19,7 @@ + @@ -209,7 +209,7 @@ - + @@ -223,16 +223,11 @@ - + - - - - - - - + + @@ -279,4 +274,4 @@ - \ No newline at end of file + diff --git a/MacPass/en.lproj/Localizable.strings b/MacPass/en.lproj/Localizable.strings index f1373a7edd1ea6fa4a4cd1f395ab3bab5885a19a..fc9513f2bdfcccd8aea2d8bfc0cbef57440527c2 100644 GIT binary patch delta 50 zcmX@+_Qh>O3WsU{LlA>2Ll}c6kPK%~Vo+eP1!5(J0EQxlRE9E!OdwglIhy0O6aX)0 B3upiU delta 12 Tcmez3cFb)<3diP29FL>`DA@(9