fixed #161 settings to copy to clipboard on password creation are preserved. Default behaviour is to restore the last sate

This commit is contained in:
michael starke
2014-03-19 22:40:25 +01:00
parent 6ff00b7819
commit c460b2187a
5 changed files with 37 additions and 26 deletions

View File

@@ -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 -

View File

@@ -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,

View File

@@ -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,
};
}

View File

@@ -1,15 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13A603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5053" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment defaultVersion="1080" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPPasswordCreatorViewController">
<connections>
<outlet property="_cancel" destination="613" id="622"/>
<outlet property="_copyToPasswordCheckbutton" destination="500" id="562"/>
<outlet property="addPasswordToPasteboardButton" destination="500" id="599"/>
<outlet property="customButton" destination="468" id="598"/>
<outlet property="customCharactersTextField" destination="411" id="479"/>
<outlet property="entropyIndicator" destination="635" id="676"/>
@@ -20,6 +19,7 @@
<outlet property="passwordLengthTextFiedl" destination="182" id="473"/>
<outlet property="passwordLengthTextField" destination="182" id="481"/>
<outlet property="passwordTextField" destination="152" id="482"/>
<outlet property="shouldCopyPasswordToPasteboardButton" destination="500" id="n2M-pB-2ol"/>
<outlet property="symbolsButton" destination="464" id="596"/>
<outlet property="upperCaseButton" destination="452" id="592"/>
<outlet property="view" destination="1" id="2"/>
@@ -209,7 +209,7 @@
<action selector="_cancel:" target="-2" id="623"/>
</connections>
</button>
<levelIndicator verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="635">
<levelIndicator verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="635">
<rect key="frame" x="90" y="174" width="186" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<levelIndicatorCell key="cell" alignment="left" doubleValue="10" maxValue="90" warningValue="55" criticalValue="30" levelIndicatorStyle="continuousCapacity" id="636" customClass="HNHLevelIndicatorCell"/>
@@ -223,16 +223,11 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="652">
<textField verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="652">
<rect key="frame" x="282" y="174" width="46" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="25000" id="653">
<numberFormatter key="formatter" formatterBehavior="custom10_4" positiveFormat="# bit" negativeFormat="# bit" usesGroupingSeparator="NO" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="309" minimumFractionDigits="0" maximumFractionDigits="0" decimalSeparator="," groupingSeparator="." currencyDecimalSeparator="," positiveSuffix=" bit" negativeSuffix=" bit" id="681">
<real key="roundingIncrement" value="0.0"/>
<metadata>
<bool key="localizesFormat" value="YES"/>
</metadata>
</numberFormatter>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="25000 bit" id="653">
<numberFormatter key="formatter" formatterBehavior="custom10_4" positiveFormat="# bit" negativeFormat="# bit" usesGroupingSeparator="NO" paddingCharacter="*" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="309" decimalSeparator="," groupingSeparator="." currencyDecimalSeparator="," plusSign="+" minusSign="-" notANumberSymbol="NaN" perMillSymbol="‰" percentSymbol="%" exponentSymbol="E" positivePrefix="" positiveSuffix=" bit" negativePrefix="-" negativeSuffix=" bit" id="681"/>
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@@ -279,4 +274,4 @@
<resources>
<image name="NSRefreshTemplate" width="10" height="12"/>
</resources>
</document>
</document>

Binary file not shown.