dropped 10.8 support. Moved old sheet API to new block based API

This commit is contained in:
michael starke
2016-08-31 18:06:37 +02:00
parent 5533bc572d
commit a79f815f99
11 changed files with 117 additions and 156 deletions

View File

@@ -1,3 +1,3 @@
github "sparkle-project/Sparkle" ~> 1.13.1 github "sparkle-project/Sparkle" ~> 1.13.1
github "mstarke/KeePassKit" "bf47781a618fc514288315995a966b5f630f6918" github "mstarke/KeePassKit" "bf47781a618fc514288315995a966b5f630f6918"
github "mstarke/HNHUi" ~> 1.0 github "mstarke/HNHUi" ~> 1.1

View File

@@ -1,3 +1,3 @@
github "mstarke/HNHUi" "1.0.1" github "mstarke/HNHUi" "1.1"
github "mstarke/KeePassKit" "bf47781a618fc514288315995a966b5f630f6918" github "mstarke/KeePassKit" "bf47781a618fc514288315995a966b5f630f6918"
github "sparkle-project/Sparkle" "1.14.0" github "sparkle-project/Sparkle" "1.14.0"

View File

@@ -2187,7 +2187,7 @@
GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2/**"; HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2/**";
MACOSX_DEPLOYMENT_TARGET = 10.8; MACOSX_DEPLOYMENT_TARGET = 10.9;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "-lxml2"; OTHER_LDFLAGS = "-lxml2";
SDKROOT = macosx; SDKROOT = macosx;
@@ -2221,7 +2221,7 @@
GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2/**"; HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2/**";
MACOSX_DEPLOYMENT_TARGET = 10.8; MACOSX_DEPLOYMENT_TARGET = 10.9;
OTHER_LDFLAGS = "-lxml2"; OTHER_LDFLAGS = "-lxml2";
SDKROOT = macosx; SDKROOT = macosx;
}; };

View File

@@ -32,6 +32,7 @@
#import "MPSavePanelAccessoryViewController.h" #import "MPSavePanelAccessoryViewController.h"
#import "MPTreeDelegate.h" #import "MPTreeDelegate.h"
#import "MPTargetNodeResolving.h" #import "MPTargetNodeResolving.h"
#import "MPErrorRecoveryAttempter.h"
#import "KeePassKit/KeePassKit.h" #import "KeePassKit/KeePassKit.h"
@@ -154,9 +155,17 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
if(self.compositeKey.hasPasswordOrKeyFile) { if(self.compositeKey.hasPasswordOrKeyFile) {
return YES; // key is set, so autosave should be save return YES; // key is set, so autosave should be save
} }
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"NO_PASSWORD_OR_KEY_SET", "") };
MPErrorRecoveryAttempter *recovery = [[MPErrorRecoveryAttempter alloc] init];
recovery.document = self;
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"WARNING_ON_SAVE_NO_PASSWORD_OR_KEY_SET", ""),
NSLocalizedRecoverySuggestionErrorKey : NSLocalizedString(@"WARNING_ON_SAVE_NO_PASSWORD_OR_KEY_SET_SUGGESTION", ""),
NSLocalizedRecoveryOptionsErrorKey : @[ NSLocalizedString(@"CHANGE_PASSWORD_WITH_DOTS", ""), NSLocalizedString(@"CANCEL", "") ],
NSRecoveryAttempterErrorKey : recovery
};
if(outError != NULL) { if(outError != NULL) {
*outError = [NSError errorWithDomain:MPErrorDomain code:0 userInfo:userInfo]; *outError = [NSError errorWithDomain:MPErrorDomain code:MPErrorNoPasswordOrKeyFile userInfo:userInfo];
} }
return NO; return NO;
} }
@@ -167,7 +176,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
} }
if(!self.compositeKey.hasPasswordOrKeyFile) { if(!self.compositeKey.hasPasswordOrKeyFile) {
if(outError != NULL) { if(outError != NULL) {
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"NO_PASSWORD_OR_KEY_SET", "") }; NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"WARNING_ON_SAVE_NO_PASSWORD_OR_KEY_SET", "") };
*outError = [NSError errorWithDomain:MPErrorDomain code:0 userInfo:userInfo]; *outError = [NSError errorWithDomain:MPErrorDomain code:0 userInfo:userInfo];
} }
return nil; // Saving without a password/key is not possible return nil; // Saving without a password/key is not possible
@@ -573,13 +582,11 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")]; [alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")];
alert.buttons.lastObject.keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b]; alert.buttons.lastObject.keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b];
[alert beginSheetModalForWindow:self.windowForSheet modalDelegate:self didEndSelector:@selector(_emptyTrashAlertDidEnd:returnCode:contextInfo:) contextInfo:NULL]; [alert beginSheetModalForWindow:self.windowForSheet completionHandler:^(NSModalResponse returnCode) {
}
- (void)_emptyTrashAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if(returnCode == NSAlertFirstButtonReturn) { if(returnCode == NSAlertFirstButtonReturn) {
[self _emptyTrash]; [self _emptyTrash];
} }
}];
} }
- (void)_presentTrashAlertForItem:(KPKNode *)node { - (void)_presentTrashAlertForItem:(KPKNode *)node {
@@ -595,12 +602,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")]; [alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")];
alert.buttons.lastObject.keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b]; alert.buttons.lastObject.keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b];
[alert beginSheetModalForWindow:self.windowForSheet modalDelegate:self didEndSelector:@selector(_deleteTrashedItemAlertDidEnd:returnCode:contextInfo:) contextInfo:(__bridge void *)(node)]; [alert beginSheetModalForWindow:self.windowForSheet completionHandler:^(NSModalResponse returnCode) {
}
- (void)_deleteTrashedItemAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if(returnCode == NSAlertFirstButtonReturn) { if(returnCode == NSAlertFirstButtonReturn) {
KPKNode *node = (__bridge KPKNode *)(contextInfo);
/* No undo on this operation */ /* No undo on this operation */
for( KPKEntry *entry in node.asGroup.childEntries) { for( KPKEntry *entry in node.asGroup.childEntries) {
[node.undoManager removeAllActionsWithTarget:entry]; [node.undoManager removeAllActionsWithTarget:entry];
@@ -611,6 +614,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
//[self.undoManager setActionIsDiscardable:YES]; //[self.undoManager setActionIsDiscardable:YES];
[node remove]; [node remove];
} }
}];
} }
- (void)createEntryFromTemplate:(id)sender { - (void)createEntryFromTemplate:(id)sender {

View File

@@ -17,7 +17,7 @@
@class MPOutlineViewController; @class MPOutlineViewController;
@class MPToolbarDelegate; @class MPToolbarDelegate;
@interface MPDocumentWindowController : NSWindowController <MPPasswordEditWindowDelegate> @interface MPDocumentWindowController : NSWindowController
@property (readonly, strong) MPPasswordInputController *passwordInputController; @property (readonly, strong) MPPasswordInputController *passwordInputController;
@property (readonly, strong) MPEntryViewController *entryViewController; @property (readonly, strong) MPEntryViewController *entryViewController;
@@ -31,6 +31,8 @@
- (void)showEntries; - (void)showEntries;
- (void)showPasswordInput; - (void)showPasswordInput;
- (void)editPasswordWithCompetionHandler:(void (^)(NSInteger result))handler;
#pragma mark Actions #pragma mark Actions
- (IBAction)saveDocument:(id)sender; - (IBAction)saveDocument:(id)sender;
- (IBAction)saveDocumentAs:(id)sender; - (IBAction)saveDocumentAs:(id)sender;
@@ -62,8 +64,4 @@
- (IBAction)focusEntries:(id)sender; - (IBAction)focusEntries:(id)sender;
- (IBAction)focusInspector:(id)sender; - (IBAction)focusInspector:(id)sender;
#pragma mark MPPasswordEditWindowDelegater
- (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey;
@end @end

View File

@@ -51,7 +51,7 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
@property (strong) MPToolbarDelegate *toolbarDelegate; @property (strong) MPToolbarDelegate *toolbarDelegate;
@property (strong) MPFixAutotypeWindowController *fixAutotypeWindowController; @property (strong) MPFixAutotypeWindowController *fixAutotypeWindowController;
@property (nonatomic, copy) MPPasswordChangedBlock passwordChangedBlock; //@property (nonatomic, copy) MPPasswordChangedBlock passwordChangedBlock;
@end @end
@@ -189,7 +189,6 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
#pragma mark Actions #pragma mark Actions
- (void)saveDocument:(id)sender { - (void)saveDocument:(id)sender {
self.passwordChangedBlock = nil;
MPDocument *document = self.document; MPDocument *document = self.document;
NSString *fileType = document.fileType; NSString *fileType = document.fileType;
/* we did open as legacy */ /* we did open as legacy */
@@ -203,31 +202,44 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
[alert addButtonWithTitle:NSLocalizedString(@"SAVE_LOSSY", "Save lossy")]; [alert addButtonWithTitle:NSLocalizedString(@"SAVE_LOSSY", "Save lossy")];
[alert addButtonWithTitle:NSLocalizedString(@"CHANGE_FORMAT", "")]; [alert addButtonWithTitle:NSLocalizedString(@"CHANGE_FORMAT", "")];
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")]; [alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "Cancel")];
__weak MPDocumentWindowController *welf = self;
[alert beginSheetModalForWindow:[welf.document windowForSheet] completionHandler:^(NSModalResponse returnCode) {
switch(returnCode) {
case NSAlertFirstButtonReturn:
/* Save lossy */
[welf.document saveDocument:nil];
return;
[alert beginSheetModalForWindow:self.window case NSAlertSecondButtonReturn:
modalDelegate:self [alert.window orderOut:nil];
didEndSelector:@selector(_dataLossOnSaveAlertDidEnd:returnCode:contextInfo:) [welf.document saveDocumentAs:nil];
contextInfo:NULL]; return;
case NSAlertThirdButtonReturn:
default:
return; // Cancel or unknown
}
}];
return; return;
} }
} }
else if(!document.compositeKey) { else if(!document.compositeKey) {
__weak MPDocument *weakDocument = [self document]; __weak MPDocument *weakDocument = self.document;
self.passwordChangedBlock = ^void(BOOL didChangePassword){
if(didChangePassword) { [self editPasswordWithCompetionHandler:^(NSInteger result) {
if(result == NSModalResponseOK) {
[weakDocument saveDocument:sender]; [weakDocument saveDocument:sender];
} }
}; }];
[self editPassword:nil];
return; return;
} }
else if(document.shouldEnforcePasswordChange) { else if(document.shouldEnforcePasswordChange) {
__weak MPDocument *weakDocument = [self document]; __weak MPDocument *weakDocument = [self document];
self.passwordChangedBlock = ^void(BOOL didChangePassword){ [self editPasswordWithCompetionHandler:^(NSInteger result) {
if(didChangePassword) { if(result == NSModalResponseOK) {
[weakDocument saveDocument:nil]; [weakDocument saveDocument:sender];
} }
}; }];
[self _presentPasswordIntervalAlerts]; [self _presentPasswordIntervalAlerts];
return; return;
} }
@@ -235,20 +247,18 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
[self.document saveDocument:sender]; [self.document saveDocument:sender];
} }
- (void)saveDocumentAs:(id)sender { - (void)saveDocumentAs:(id)sender {
self.passwordChangedBlock = nil;
MPDocument *document = [self document]; MPDocument *document = [self document];
if(document.compositeKey) { if(document.compositeKey) {
[[self document] saveDocumentAs:sender]; [[self document] saveDocumentAs:sender];
return; return;
} }
/* we need to make sure that a password is set */ /* we need to make sure that a password is set */
__weak MPDocument *weakDocument = [self document]; __weak MPDocument *weakDocument = self.document;
self.passwordChangedBlock = ^void(BOOL didChangePassword){ [self editPasswordWithCompetionHandler:^(NSInteger result) {
if(didChangePassword) { if(result == NSModalResponseOK) {
[weakDocument saveDocumentAs:sender]; [weakDocument saveDocumentAs:sender];
} }
}; }];
[self editPassword:nil];
} }
- (void)exportAsXML:(id)sender { - (void)exportAsXML:(id)sender {
@@ -303,15 +313,16 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
- (void)editPasswordWithCompetionHandler:(void (^)(NSInteger result))handler { - (void)editPasswordWithCompetionHandler:(void (^)(NSInteger result))handler {
if(!self.passwordEditWindowController) { if(!self.passwordEditWindowController) {
self.passwordEditWindowController = [[MPPasswordEditWindowController alloc] init]; self.passwordEditWindowController = [[MPPasswordEditWindowController alloc] init];
self.passwordEditWindowController.delegate = self;
} }
[self.document addWindowController:self.passwordEditWindowController]; [self.document addWindowController:self.passwordEditWindowController];
[NSApp beginSheet:self.passwordEditWindowController.window [self.window beginSheet:self.passwordEditWindowController.window completionHandler:^(NSModalResponse returnCode) {
modalForWindow:self.window if(handler) {
modalDelegate:self handler(returnCode);
didEndSelector:@selector(_editPasswordSheetDidEnd:returnCode:contextInfo:) }
contextInfo:NULL]; [self.passwordEditWindowController.document removeWindowController:self.passwordEditWindowController];
self.passwordEditWindowController = nil;
}];
} }
- (void)showDatabaseSettings:(id)sender { - (void)showDatabaseSettings:(id)sender {
@@ -480,14 +491,6 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
return ([[self document] validateMenuItem:menuItem]); return ([[self document] validateMenuItem:menuItem]);
} }
#pragma mark MPPasswordEditWindowDelegate
- (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey {
if(self.passwordChangedBlock) {
self.passwordChangedBlock(changedPasswordOrKey);
}
self.passwordChangedBlock = nil;
}
#pragma mark NSAlert handling #pragma mark NSAlert handling
- (void)_presentPasswordIntervalAlerts { - (void)_presentPasswordIntervalAlerts {
MPDocument *document = [self document]; MPDocument *document = [self document];
@@ -502,10 +505,15 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "")]; [alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "")];
alert.buttons[1].keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b]; alert.buttons[1].keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b];
[alert beginSheetModalForWindow:self.window [alert beginSheetModalForWindow:[self.document windowForSheet] completionHandler:^(NSModalResponse returnCode) {
modalDelegate:self if(NSAlertSecondButtonReturn == returnCode) {
didEndSelector:@selector(_enforcePasswordChangeAlertDidEnd:returnCode:contextInfo:) return;
contextInfo:NULL]; }
id __weak welf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[welf editPassword:nil];
});
}];
} }
else if(document.shouldRecommendPasswordChange) { else if(document.shouldRecommendPasswordChange) {
NSAlert *alert = [[NSAlert alloc] init]; NSAlert *alert = [[NSAlert alloc] init];
@@ -518,33 +526,8 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
[alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "")]; [alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "")];
alert.buttons[1].keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b]; alert.buttons[1].keyEquivalent = [NSString stringWithFormat:@"%c", 0x1b];
[alert beginSheetModalForWindow:self.window
modalDelegate:self
didEndSelector:@selector(_recommentPasswordChangeAlertDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
}
}
- (void)_dataLossOnSaveAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { [alert beginSheetModalForWindow:[self.document windowForSheet]completionHandler:^(NSModalResponse returnCode) {
switch(returnCode) {
case NSAlertFirstButtonReturn:
/* Save lossy */
[self.document saveDocument:nil];
return;
case NSAlertSecondButtonReturn:
[alert.window orderOut:nil];
[self.document saveDocumentAs:nil];
return;
case NSAlertThirdButtonReturn:
default:
return; // Cancel or unknown
}
}
- (void)_recommentPasswordChangeAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if(returnCode == NSAlertSecondButtonReturn) { if(returnCode == NSAlertSecondButtonReturn) {
return; return;
} }
@@ -552,43 +535,21 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[welf editPassword:nil]; [welf editPassword:nil];
}); });
}];
}
- (void)_enforcePasswordChangeAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if(NSAlertSecondButtonReturn == returnCode) {
return;
} }
id __weak welf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[welf editPassword:nil];
});
} }
#pragma mark Sheet handling #pragma mark Sheet handling
- (void)_editPasswordSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
[self.document removeWindowController:self.passwordEditWindowController];
self.passwordEditWindowController = nil;
}
- (void)_settingsSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
/* cleanup the window controller */
[self.document removeWindowController:self.documentSettingsWindowController];
self.documentSettingsWindowController = nil;
}
- (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab { - (void)_showDatabaseSetting:(MPDatabaseSettingsTab)tab {
if(!self.documentSettingsWindowController) { if(!self.documentSettingsWindowController) {
self.documentSettingsWindowController = [[MPDatabaseSettingsWindowController alloc] init]; self.documentSettingsWindowController = [[MPDatabaseSettingsWindowController alloc] init];
} }
[self.document addWindowController:self.documentSettingsWindowController]; [self.document addWindowController:self.documentSettingsWindowController];
[self.documentSettingsWindowController showSettingsTab:tab]; [self.documentSettingsWindowController showSettingsTab:tab];
[[NSApplication sharedApplication] beginSheet:self.documentSettingsWindowController.window [self.window beginSheet:self.documentSettingsWindowController.window completionHandler:^(NSModalResponse returnCode) {
modalForWindow:self.window [self.documentSettingsWindowController.document removeWindowController:self.documentSettingsWindowController];
modalDelegate:self self.documentSettingsWindowController = nil;
didEndSelector:@selector(_settingsSheetDidEnd:returnCode:contextInfo:) }];
contextInfo:NULL];
} }
#pragma mark - #pragma mark -

View File

@@ -34,7 +34,7 @@
@property (weak) IBOutlet NSButton *hasPasswordSwitchButton; @property (weak) IBOutlet NSButton *hasPasswordSwitchButton;
//@property (nonatomic,assign) BOOL allowsEmptyPasswordOrKey; //@property (nonatomic,assign) BOOL allowsEmptyPasswordOrKey;
@property (weak) id<MPPasswordEditWindowDelegate> delegate; //@property (weak) id<MPPasswordEditWindowDelegate> delegate;
- (IBAction)clearKey:(id)sender; - (IBAction)clearKey:(id)sender;
- (IBAction)generateKey:(id)sender; - (IBAction)generateKey:(id)sender;

View File

@@ -67,8 +67,8 @@
[self.changePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:hasValidPasswordOrKeyKeyPath options:nil]; [self.changePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:hasValidPasswordOrKeyKeyPath options:nil];
[self.keyfilePathControl bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(keyURL)) options:nil]; [self.keyfilePathControl bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(keyURL)) options:nil];
[self.passwordRepeatTextField setDelegate:self]; self.passwordRepeatTextField.delegate = self;
[self.passwordTextField setDelegate:self]; self.passwordTextField.delegate = self;
/* Manually initate the first check */ /* Manually initate the first check */
[self _verifyPasswordAndKey]; [self _verifyPasswordAndKey];
@@ -80,7 +80,7 @@
if(_showPassword != showPassword) { if(_showPassword != showPassword) {
_showPassword = showPassword; _showPassword = showPassword;
[self.passwordRepeatTextField setStringValue:@""]; self.passwordRepeatTextField.stringValue = @"";
[self _verifyPasswordAndKey]; [self _verifyPasswordAndKey];
} }
} }
@@ -94,27 +94,21 @@
} }
NSString *passwordPlaceHolder = _enablePassword ? NSLocalizedString(@"PASSWORD_INPUT_ENTER_PASSWORD", "") : NSLocalizedString(@"PASSWORD_INPUT_NO_PASSWORD", ""); NSString *passwordPlaceHolder = _enablePassword ? NSLocalizedString(@"PASSWORD_INPUT_ENTER_PASSWORD", "") : NSLocalizedString(@"PASSWORD_INPUT_NO_PASSWORD", "");
NSString *repeatPlaceHolder = _enablePassword ? NSLocalizedString(@"PASSWORD_INPUT_REPEAT_PASSWORD", "") : NSLocalizedString(@"PASSWORD_INPUT_NO_PASSWORD", ""); NSString *repeatPlaceHolder = _enablePassword ? NSLocalizedString(@"PASSWORD_INPUT_REPEAT_PASSWORD", "") : NSLocalizedString(@"PASSWORD_INPUT_NO_PASSWORD", "");
[[self.passwordTextField cell] setPlaceholderString:passwordPlaceHolder]; [self.passwordTextField.cell setPlaceholderString:passwordPlaceHolder];
[[self.passwordRepeatTextField cell] setPlaceholderString:repeatPlaceHolder]; [self.passwordRepeatTextField.cell setPlaceholderString:repeatPlaceHolder];
} }
#pragma mark Actions #pragma mark Actions
- (IBAction)save:(id)sender { - (IBAction)save:(id)sender {
const BOOL hasPassword = ([self.hasPasswordSwitchButton state] == NSOnState); const BOOL hasPassword = HNHUIBoolForState(self.hasPasswordSwitchButton.state);
NSString *password = hasPassword ? [self.passwordTextField stringValue] : nil; NSString *password = hasPassword ? self.passwordTextField.stringValue : nil;
MPDocument *document = self.document; MPDocument *document = self.document;
[document changePassword:password keyFileURL:[self.keyfilePathControl URL]]; [document changePassword:password keyFileURL:self.keyfilePathControl.URL];
[self dismissSheet:NSRunStoppedResponse]; [self dismissSheet:NSModalResponseOK];
if(self.delegate && [self.delegate respondsToSelector:@selector(didFinishPasswordEditing:)]) {
[self.delegate didFinishPasswordEditing:YES];
}
} }
- (IBAction)cancel:(id)sender { - (IBAction)cancel:(id)sender {
[self dismissSheet:NSRunAbortedResponse]; [self dismissSheet:NSModalResponseCancel];
if(self.delegate && [self.delegate respondsToSelector:@selector(didFinishPasswordEditing:)]) {
[self.delegate didFinishPasswordEditing:NO];
}
} }
- (IBAction)clearKey:(id)sender { - (IBAction)clearKey:(id)sender {
@@ -126,9 +120,9 @@
NSData *data = [NSData generateKeyfiledataForVersion:document.tree.minimumVersion]; NSData *data = [NSData generateKeyfiledataForVersion:document.tree.minimumVersion];
if(data) { if(data) {
NSSavePanel *savePanel = [NSSavePanel savePanel]; NSSavePanel *savePanel = [NSSavePanel savePanel];
[savePanel setAllowedFileTypes:@[@"key", @"xml"]]; savePanel.allowedFileTypes = @[@"key", @"xml"];
[savePanel setCanCreateDirectories:YES]; savePanel.canCreateDirectories = YES;
[savePanel setTitle:NSLocalizedString(@"SAVE_KEYFILE", "")]; savePanel.title = NSLocalizedString(@"SAVE_KEYFILE", "");
[savePanel beginWithCompletionHandler:^(NSInteger result) { [savePanel beginWithCompletionHandler:^(NSInteger result) {
if(result == NSFileHandlingPanelOKButton) { if(result == NSFileHandlingPanelOKButton) {
NSURL *keyURL = [savePanel URL]; NSURL *keyURL = [savePanel URL];

View File

@@ -3,7 +3,7 @@
// //
#ifdef __OBJC__ #ifdef __OBJC__
#define __MAC_OS_X_VERSION_SOFT_MAX_REQUIRED __MAC_10_8 #define __MAC_OS_X_VERSION_SOFT_MAX_REQUIRED __MAC_10_9
#import "MJGAvailability.h" #import "MJGAvailability.h"
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#endif #endif

View File

@@ -10,6 +10,10 @@
FOUNDATION_EXPORT NSString *const MPErrorDomain; FOUNDATION_EXPORT NSString *const MPErrorDomain;
typedef NS_ENUM(NSInteger, MPErrorCodes) {
MPErrorNoPasswordOrKeyFile = 10000,
};
@interface NSError (Messages) @interface NSError (Messages)
+ (NSError *)errorWithCode:(NSInteger)code description:(NSString *)description; + (NSError *)errorWithCode:(NSInteger)code description:(NSString *)description;

Binary file not shown.