mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 16:22:21 +00:00
Save as now asks for a Password if none was set.
This commit is contained in:
@@ -130,6 +130,14 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
|||||||
[self addWindowController:windowController];
|
[self addWindowController:windowController];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)saveDocumentAs:(id)sender {
|
||||||
|
[super saveDocumentAs:sender];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)saveDocument:(id)sender {
|
||||||
|
[super saveDocument:sender];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
|
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
|
||||||
{
|
{
|
||||||
[super windowControllerDidLoadNib:aController];
|
[super windowControllerDidLoadNib:aController];
|
||||||
@@ -137,13 +145,18 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
|||||||
|
|
||||||
- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
||||||
if(!self.compositeKey.hasPasswordOrKeyFile) {
|
if(!self.compositeKey.hasPasswordOrKeyFile) {
|
||||||
|
if(outError != NULL) {
|
||||||
|
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"NO_PASSWORD_OR_KEY_SET", "") };
|
||||||
|
*outError = [NSError errorWithDomain:MPErrorDomain code:0 userInfo:userInfo];
|
||||||
|
}
|
||||||
return NO; // No password or key. No save possible
|
return NO; // No password or key. No save possible
|
||||||
}
|
}
|
||||||
NSString *fileType = [self fileTypeFromLastRunSavePanel];
|
NSString *fileType = [self fileTypeFromLastRunSavePanel];
|
||||||
KPKVersion version = [[self class] versionForFileType:fileType];
|
KPKVersion version = [[self class] versionForFileType:fileType];
|
||||||
if(version == KPKUnknownVersion) {
|
if(version == KPKUnknownVersion) {
|
||||||
if(outError != NULL) {
|
if(outError != NULL) {
|
||||||
*outError = [NSError errorWithDomain:MPErrorDomain code:0 userInfo:nil];
|
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"UNKNOWN_FILE_VERSION", "") };
|
||||||
|
*outError = [NSError errorWithDomain:MPErrorDomain code:0 userInfo:userInfo];
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#pragma mark Actions
|
#pragma mark Actions
|
||||||
- (IBAction)saveDocument:(id)sender;
|
- (IBAction)saveDocument:(id)sender;
|
||||||
|
- (IBAction)saveDocumentAs:(id)sender;
|
||||||
|
|
||||||
- (IBAction)editPassword:(id)sender;
|
- (IBAction)editPassword:(id)sender;
|
||||||
- (IBAction)showDatabaseSettings:(id)sender;
|
- (IBAction)showDatabaseSettings:(id)sender;
|
||||||
|
|||||||
@@ -29,10 +29,11 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
MPAlertLossySaveWarning,
|
MPAlertLossySaveWarning,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (^MPPasswordChangedBlock)(void);
|
||||||
|
|
||||||
@interface MPDocumentWindowController () {
|
@interface MPDocumentWindowController () {
|
||||||
@private
|
@private
|
||||||
id _firstResponder;
|
id _firstResponder;
|
||||||
BOOL _saveAfterPasswordChange;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (strong) IBOutlet NSSplitView *splitView;
|
@property (strong) IBOutlet NSSplitView *splitView;
|
||||||
@@ -48,6 +49,8 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
@property (strong) MPPasswordEditWindowController *passwordEditWindowController;
|
@property (strong) MPPasswordEditWindowController *passwordEditWindowController;
|
||||||
@property (strong) MPToolbarDelegate *toolbarDelegate;
|
@property (strong) MPToolbarDelegate *toolbarDelegate;
|
||||||
|
|
||||||
|
@property (nonatomic, copy) MPPasswordChangedBlock passwordChangedBlock;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MPDocumentWindowController
|
@implementation MPDocumentWindowController
|
||||||
@@ -56,7 +59,6 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
self = [super initWithWindowNibName:@"DocumentWindow" owner:self];
|
self = [super initWithWindowNibName:@"DocumentWindow" owner:self];
|
||||||
if( self ) {
|
if( self ) {
|
||||||
_firstResponder = nil;
|
_firstResponder = nil;
|
||||||
_saveAfterPasswordChange = NO;
|
|
||||||
_toolbarDelegate = [[MPToolbarDelegate alloc] init];
|
_toolbarDelegate = [[MPToolbarDelegate alloc] init];
|
||||||
_outlineViewController = [[MPOutlineViewController alloc] init];
|
_outlineViewController = [[MPOutlineViewController alloc] init];
|
||||||
_entryViewController = [[MPEntryViewController alloc] init];
|
_entryViewController = [[MPEntryViewController alloc] init];
|
||||||
@@ -167,7 +169,7 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
|
|
||||||
#pragma mark Actions
|
#pragma mark Actions
|
||||||
- (void)saveDocument:(id)sender {
|
- (void)saveDocument:(id)sender {
|
||||||
_saveAfterPasswordChange = NO;
|
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 */
|
||||||
@@ -187,13 +189,25 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!document.compositeKey) {
|
else if(!document.compositeKey) {
|
||||||
_saveAfterPasswordChange = YES;
|
__weak MPDocument *weakDocument = [self document];
|
||||||
|
self.passwordChangedBlock = ^void(void){[weakDocument saveDocument:sender];};
|
||||||
[self editPassword:sender];
|
[self editPassword:sender];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* All set and good ready to save */
|
/* All set and good ready to save */
|
||||||
[[self document] saveDocument:sender];
|
[[self document] saveDocument:sender];
|
||||||
}
|
}
|
||||||
|
- (void)saveDocumentAs:(id)sender {
|
||||||
|
self.passwordChangedBlock = nil;
|
||||||
|
MPDocument *document = [self document];
|
||||||
|
if(!document.compositeKey) {
|
||||||
|
__weak MPDocument *weakDocument = [self document];
|
||||||
|
self.passwordChangedBlock = ^void(void){[weakDocument saveDocumentAs:sender];};
|
||||||
|
[self editPassword:sender];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
[[self document] saveDocumentAs:sender];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)exportAsXML:(id)sender {
|
- (void)exportAsXML:(id)sender {
|
||||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||||
@@ -238,7 +252,7 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
self.passwordEditWindowController.delegate = self;
|
self.passwordEditWindowController.delegate = self;
|
||||||
}
|
}
|
||||||
/* Disallow empty password if we want to save afterwards, otherwise the dialog keeps poping up */
|
/* Disallow empty password if we want to save afterwards, otherwise the dialog keeps poping up */
|
||||||
self.passwordEditWindowController.allowsEmptyPasswordOrKey = !_saveAfterPasswordChange;
|
self.passwordEditWindowController.allowsEmptyPasswordOrKey = (self.passwordChangedBlock == nil);
|
||||||
[NSApp beginSheet:[self.passwordEditWindowController window] modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
|
[NSApp beginSheet:[self.passwordEditWindowController window] modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,10 +389,10 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
|
|
||||||
#pragma mark MPPasswordEditWindowDelegate
|
#pragma mark MPPasswordEditWindowDelegate
|
||||||
- (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey {
|
- (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey {
|
||||||
if(changedPasswordOrKey && _saveAfterPasswordChange) {
|
if(changedPasswordOrKey && self.passwordChangedBlock) {
|
||||||
[self saveDocument:nil];
|
self.passwordChangedBlock();
|
||||||
}
|
}
|
||||||
_saveAfterPasswordChange = NO;
|
self.passwordChangedBlock = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Alert Delegate
|
#pragma mark Alert Delegate
|
||||||
|
|||||||
Reference in New Issue
Block a user