minor code improvements

This commit is contained in:
michael starke
2017-05-22 16:19:46 +02:00
parent 6eea1ed48e
commit e8185480f1
3 changed files with 25 additions and 25 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12120"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<objects> <objects>
@@ -32,10 +32,10 @@ DQ
</string> </string>
</buttonCell> </buttonCell>
<connections> <connections>
<action selector="_decrypt:" target="-2" id="295"/> <action selector="_submit:" target="-2" id="KZN-ap-nDc"/>
</connections> </connections>
</button> </button>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="17"> <textField verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="17">
<rect key="frame" x="116" y="112" width="45" height="17"/> <rect key="frame" x="116" y="112" width="45" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Keyfile" id="18"> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Keyfile" id="18">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@@ -57,7 +57,7 @@ DQ
</constraints> </constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="02_MessageBoxWarningTemplate" id="263"/> <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="02_MessageBoxWarningTemplate" id="263"/>
</imageView> </imageView>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="268"> <textField verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="268">
<rect key="frame" x="207" y="172" width="110" height="17"/> <rect key="frame" x="207" y="172" width="110" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Wrong password!" id="269"> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Wrong password!" id="269">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@@ -65,7 +65,7 @@ DQ
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell> </textFieldCell>
</textField> </textField>
<secureTextField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="338" customClass="HNHUIRoundedSecureTextField"> <secureTextField verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="338" customClass="HNHUIRoundedSecureTextField">
<rect key="frame" x="167" y="140" width="191" height="24"/> <rect key="frame" x="167" y="140" width="191" height="24"/>
<constraints> <constraints>
<constraint firstAttribute="width" constant="191" id="389"/> <constraint firstAttribute="width" constant="191" id="389"/>

View File

@@ -283,6 +283,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
/* Set the flag in this call! */ /* Set the flag in this call! */
self.lockedForFileChange = YES; self.lockedForFileChange = YES;
/* TODO read file to check if changes took place! */
/* Dispatch the alert to the main queue */ /* Dispatch the alert to the main queue */
__weak MPDocument *welf = self; __weak MPDocument *welf = self;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{

View File

@@ -52,8 +52,8 @@
} }
- (void)didLoadView { - (void)didLoadView {
[self.keyPathControl setDelegate:self.pathControlDelegate]; self.keyPathControl.delegate = self.pathControlDelegate;
[self.errorImageView setImage:[NSImage imageNamed:NSImageNameCaution]]; self.errorImageView.image = [NSImage imageNamed:NSImageNameCaution];
[self.passwordTextField bind:NSStringFromSelector(@selector(showPassword)) toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil]; [self.passwordTextField bind:NSStringFromSelector(@selector(showPassword)) toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil];
[self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil]; [self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil];
[self.enablePasswordCheckBox bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil]; [self.enablePasswordCheckBox bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(enablePassword)) options:nil];
@@ -76,22 +76,21 @@
if(_enablePassword != enablePassword) { if(_enablePassword != enablePassword) {
_enablePassword = enablePassword; _enablePassword = enablePassword;
if(!_enablePassword) { if(!_enablePassword) {
[self.passwordTextField setStringValue:@""]; self.passwordTextField.stringValue = @"";
} }
} }
NSString *placeHolderString = _enablePassword ? NSLocalizedString(@"PASSWORD_INPUT_ENTER_PASSWORD", "") : NSLocalizedString(@"PASSWORD_INPUT_NO_PASSWORD", ""); NSString *placeHolderString = _enablePassword ? NSLocalizedString(@"PASSWORD_INPUT_ENTER_PASSWORD", "") : NSLocalizedString(@"PASSWORD_INPUT_NO_PASSWORD", "");
[self.passwordTextField.cell setPlaceholderString:placeHolderString]; ((NSTextFieldCell *)self.passwordTextField.cell).placeholderString = placeHolderString;
} }
#pragma mark - #pragma mark -
#pragma mark Private #pragma mark Private
- (IBAction)_decrypt:(id)sender { - (IBAction)_submit:(id)sender {
NSError *error = nil;
/* No password is different than an empty password */
NSString *password = self.enablePassword ? self.passwordTextField.stringValue : nil;
if(self.completionHandler) { if(self.completionHandler) {
/* No password is different than an empty password */
NSError *error = nil;
NSString *password = self.enablePassword ? self.passwordTextField.stringValue : nil;
if(!self.completionHandler(password, self.keyPathControl.URL, &error)) { if(!self.completionHandler(password, self.keyPathControl.URL, &error)) {
[self _showError:error]; [self _showError:error];
[self.view.window shakeWindow:nil]; [self.view.window shakeWindow:nil];
@@ -105,31 +104,30 @@
[self _selectKeyURL]; [self _selectKeyURL];
} }
else { else {
[self.keyPathControl setURL:nil]; self.keyPathControl.URL = nil;
} }
} }
- (void)_reset { - (void)_reset {
self.showPassword = NO; self.showPassword = NO;
self.enablePassword = YES; self.enablePassword = YES;
[self.passwordTextField setStringValue:@""]; self.passwordTextField.stringValue = @"";
[self.errorInfoTextField setHidden:YES]; self.errorInfoTextField.hidden = YES;
[self.errorImageView setHidden:YES]; self.errorImageView.hidden = YES;
[self resetKeyFile:self]; [self resetKeyFile:self];
} }
- (void)_selectKeyURL { - (void)_selectKeyURL {
MPDocument *document = [[self windowController] document]; MPDocument *document = self.windowController.document;
[self.keyPathControl setURL:document.suggestedKeyURL]; self.keyPathControl.URL = document.suggestedKeyURL;
} }
- (void)_showError:(NSError *)error { - (void)_showError:(NSError *)error {
if(error) { if(error) {
NSString *errorMessage = [error descriptionForErrorCode]; self.errorInfoTextField.stringValue = error.descriptionForErrorCode;
[self.errorInfoTextField setStringValue:errorMessage];
} }
[self.errorImageView setHidden:NO]; self.errorImageView.hidden = NO;
[self.errorInfoTextField setHidden:NO]; self.errorInfoTextField.hidden = NO;
} }
@end @end