mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 08:12:28 +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];
|
||||
}
|
||||
|
||||
- (void)saveDocumentAs:(id)sender {
|
||||
[super saveDocumentAs:sender];
|
||||
}
|
||||
|
||||
- (void)saveDocument:(id)sender {
|
||||
[super saveDocument:sender];
|
||||
}
|
||||
|
||||
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
|
||||
{
|
||||
[super windowControllerDidLoadNib:aController];
|
||||
@@ -137,13 +145,18 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
||||
|
||||
- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
||||
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
|
||||
}
|
||||
NSString *fileType = [self fileTypeFromLastRunSavePanel];
|
||||
KPKVersion version = [[self class] versionForFileType:fileType];
|
||||
if(version == KPKUnknownVersion) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#pragma mark Actions
|
||||
- (IBAction)saveDocument:(id)sender;
|
||||
- (IBAction)saveDocumentAs:(id)sender;
|
||||
|
||||
- (IBAction)editPassword:(id)sender;
|
||||
- (IBAction)showDatabaseSettings:(id)sender;
|
||||
|
||||
@@ -29,10 +29,11 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
||||
MPAlertLossySaveWarning,
|
||||
};
|
||||
|
||||
typedef void (^MPPasswordChangedBlock)(void);
|
||||
|
||||
@interface MPDocumentWindowController () {
|
||||
@private
|
||||
id _firstResponder;
|
||||
BOOL _saveAfterPasswordChange;
|
||||
}
|
||||
|
||||
@property (strong) IBOutlet NSSplitView *splitView;
|
||||
@@ -48,6 +49,8 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
||||
@property (strong) MPPasswordEditWindowController *passwordEditWindowController;
|
||||
@property (strong) MPToolbarDelegate *toolbarDelegate;
|
||||
|
||||
@property (nonatomic, copy) MPPasswordChangedBlock passwordChangedBlock;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPDocumentWindowController
|
||||
@@ -56,7 +59,6 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
||||
self = [super initWithWindowNibName:@"DocumentWindow" owner:self];
|
||||
if( self ) {
|
||||
_firstResponder = nil;
|
||||
_saveAfterPasswordChange = NO;
|
||||
_toolbarDelegate = [[MPToolbarDelegate alloc] init];
|
||||
_outlineViewController = [[MPOutlineViewController alloc] init];
|
||||
_entryViewController = [[MPEntryViewController alloc] init];
|
||||
@@ -167,7 +169,7 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
||||
|
||||
#pragma mark Actions
|
||||
- (void)saveDocument:(id)sender {
|
||||
_saveAfterPasswordChange = NO;
|
||||
self.passwordChangedBlock = nil;
|
||||
MPDocument *document = [self document];
|
||||
NSString *fileType = [document fileType];
|
||||
/* we did open as legacy */
|
||||
@@ -187,13 +189,25 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
||||
}
|
||||
}
|
||||
else if(!document.compositeKey) {
|
||||
_saveAfterPasswordChange = YES;
|
||||
__weak MPDocument *weakDocument = [self document];
|
||||
self.passwordChangedBlock = ^void(void){[weakDocument saveDocument:sender];};
|
||||
[self editPassword:sender];
|
||||
return;
|
||||
}
|
||||
/* All set and good ready to save */
|
||||
[[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 {
|
||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||
@@ -238,7 +252,7 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
||||
self.passwordEditWindowController.delegate = self;
|
||||
}
|
||||
/* 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];
|
||||
}
|
||||
|
||||
@@ -375,10 +389,10 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
||||
|
||||
#pragma mark MPPasswordEditWindowDelegate
|
||||
- (void)didFinishPasswordEditing:(BOOL)changedPasswordOrKey {
|
||||
if(changedPasswordOrKey && _saveAfterPasswordChange) {
|
||||
[self saveDocument:nil];
|
||||
if(changedPasswordOrKey && self.passwordChangedBlock) {
|
||||
self.passwordChangedBlock();
|
||||
}
|
||||
_saveAfterPasswordChange = NO;
|
||||
self.passwordChangedBlock = nil;
|
||||
}
|
||||
|
||||
#pragma mark Alert Delegate
|
||||
|
||||
Reference in New Issue
Block a user