mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 08:12:28 +00:00
extracted merge to function. Added action to merge arbitrary files
This commit is contained in:
@@ -150,6 +150,7 @@ FOUNDATION_EXPORT NSString *const MPDocumentGroupKey;
|
||||
|
||||
- (void)writeXMLToURL:(NSURL *)url;
|
||||
- (void)readXMLfromURL:(NSURL *)url;
|
||||
- (void)mergeWithContentsFromURL:(NSURL *)url;
|
||||
|
||||
/* Undoable Intiialization of elements */
|
||||
- (KPKGroup *)createGroup:(KPKGroup *)parent;
|
||||
|
||||
@@ -283,6 +283,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
|
||||
self.fileChangeDialogOpen = YES;
|
||||
|
||||
/* Dispatch the alert to the main queue */
|
||||
__weak MPDocument *welf = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
NSAlert *alert = [[NSAlert alloc] init];
|
||||
@@ -292,18 +293,16 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
|
||||
[alert addButtonWithTitle:NSLocalizedString(@"KEEP_MINE", @"Ignore the changes to an open file!")];
|
||||
[alert addButtonWithTitle:NSLocalizedString(@"LOAD_CHANGES", @"Reopen the file!")];
|
||||
[alert addButtonWithTitle:NSLocalizedString(@"MERGE_CHANGES", @"Merge changes into file!")];
|
||||
[alert beginSheetModalForWindow:self.windowForSheet completionHandler:^(NSModalResponse returnCode) {
|
||||
[alert beginSheetModalForWindow:welf.windowForSheet completionHandler:^(NSModalResponse returnCode) {
|
||||
|
||||
self.fileChangeDialogOpen = NO;
|
||||
welf.fileChangeDialogOpen = NO;
|
||||
|
||||
switch(returnCode) {
|
||||
case NSAlertSecondButtonReturn:
|
||||
[self revertToContentsOfURL:self.fileURL ofType:self.fileType error:nil];
|
||||
[welf revertToContentsOfURL:welf.fileURL ofType:welf.fileType error:nil];
|
||||
break;
|
||||
case NSAlertThirdButtonReturn: {
|
||||
KPKTree *otherTree = [[KPKTree alloc] initWithContentsOfUrl:self.fileURL key:self.compositeKey error:nil];
|
||||
[self.tree syncronizeWithTree:otherTree options:KPKSynchronizationSynchronizeOption];
|
||||
break;
|
||||
[welf mergeWithContentsFromURL:self.fileURL];
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@@ -327,6 +326,23 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
|
||||
self.encryptedData = nil;
|
||||
}
|
||||
|
||||
- (void)mergeWithContentsFromURL:(NSURL *)url {
|
||||
/* TODO read file to check what format to use */
|
||||
NSError *error;
|
||||
KPKTree *otherTree = [[KPKTree alloc] initWithContentsOfUrl:url key:self.compositeKey error:&error];
|
||||
if(!otherTree) {
|
||||
if(error.code == KPKErrorPasswordAndOrKeyfileWrong) {
|
||||
[self presentError:error];
|
||||
}
|
||||
else {
|
||||
[self presentError:error];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[self.tree syncronizeWithTree:otherTree options:KPKSynchronizationSynchronizeOption];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Lock/Unlock/Decrypt
|
||||
|
||||
- (void)lockDatabase:(id)sender {
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
- (IBAction)editTrashGroup:(id)sender;
|
||||
|
||||
- (IBAction)exportAsXML:(id)sender;
|
||||
- (IBAction)mergeWithOther:(id)sender;
|
||||
- (IBAction)importFromXML:(id)sender;
|
||||
|
||||
- (IBAction)lock:(id)sender;
|
||||
|
||||
@@ -296,6 +296,20 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)mergeWithOther:(id)sender {
|
||||
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
||||
MPDocument *document = self.document;
|
||||
openPanel.allowsMultipleSelection = NO;
|
||||
openPanel.canChooseDirectories = NO;
|
||||
openPanel.canChooseFiles = YES;
|
||||
//openPanel.allowedFileTypes = @[(id)kUTTypeXML];
|
||||
[openPanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
|
||||
if(result == NSFileHandlingPanelOKButton) {
|
||||
[document mergeWithContentsFromURL:openPanel.URL];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)fixAutotype:(id)sender {
|
||||
if(!self.fixAutotypeWindowController) {
|
||||
self.fixAutotypeWindowController = [[MPFixAutotypeWindowController alloc] init];
|
||||
|
||||
Reference in New Issue
Block a user