diff --git a/MacPass/Base.lproj/MainMenu.xib b/MacPass/Base.lproj/MainMenu.xib index 8e1fdf9d..ae6899a3 100644 --- a/MacPass/Base.lproj/MainMenu.xib +++ b/MacPass/Base.lproj/MainMenu.xib @@ -94,6 +94,18 @@ + + + + + + + + + + + + @@ -115,11 +127,6 @@ - - - - - diff --git a/MacPass/MPActionHelper.h b/MacPass/MPActionHelper.h index 1114c0c5..b40a7d8e 100644 --- a/MacPass/MPActionHelper.h +++ b/MacPass/MPActionHelper.h @@ -22,7 +22,9 @@ typedef NS_ENUM(NSUInteger, MPActionType) { MPActionEmptyTrash, // empties the trashcan, if there is one MPActionEditPassword, // change the database password MPActionDatabaseSettings, // Show the settings for the database - MPActionEditTemplateGroup + MPActionEditTemplateGroup, // Edit the Template group + MPActionExportXML, // Exporte as XML + MPActionImportXML // Import form XML }; /** * Helper to retrieve commonly used actions diff --git a/MacPass/MPActionHelper.m b/MacPass/MPActionHelper.m index 7d4dc1e2..6cf49d84 100644 --- a/MacPass/MPActionHelper.m +++ b/MacPass/MPActionHelper.m @@ -27,7 +27,9 @@ @(MPActionLock) : @"lock:", @(MPActionEmptyTrash) : @"emptyTrash:", @(MPActionDatabaseSettings) : @"showDatabaseSettings:", - @(MPActionEditTemplateGroup) : @"editTemplateGroup:" + @(MPActionEditTemplateGroup) : @"editTemplateGroup:", + @(MPActionExportXML) : @"exportAsXML", + @(MPActionImportXML) : @"importFromXMl", }; }); return actionDict; diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 457eb5ee..f773b3b8 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -126,6 +126,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; - (BOOL)isItemTrashed:(id)item; - (void)writeXMLToURL:(NSURL *)url; +- (void)readXMLfromURL:(NSURL *)url; /* Undoable Intiialization of elements */ - (KPKGroup *)createGroup:(KPKGroup *)parent; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index e6649697..fcc90d38 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -83,6 +83,10 @@ typedef NS_ENUM(NSUInteger, MPAlertType) { @implementation MPDocument ++ (NSSet *)keyPathsForValuesAffectingRoot { + return [NSSet setWithObject:@"tree"]; +} + + (KPKVersion)versionForFileType:(NSString *)fileType { if( NSOrderedSame == [fileType compare:MPLegacyDocumentUTI options:NSCaseInsensitiveSearch]) { return KPKLegacyVersion; @@ -235,6 +239,13 @@ typedef NS_ENUM(NSUInteger, MPAlertType) { [xmlData writeToURL:url atomically:YES]; } +- (void)readXMLfromURL:(NSURL *)url { + NSError *error; + self.tree = [[KPKTree alloc] initWithXmlContentsOfURL:url error:&error]; + self.compositeKey = nil; + _encryptedData = Nil; +} + #pragma mark Lock/Unlock/Decrypt - (void)lockDatabase:(id)sender { diff --git a/MacPass/MPDocumentWindowController.h b/MacPass/MPDocumentWindowController.h index fd5de1c8..247d95a5 100644 --- a/MacPass/MPDocumentWindowController.h +++ b/MacPass/MPDocumentWindowController.h @@ -33,7 +33,8 @@ - (IBAction)editTemplateGroup:(id)sender; - (IBAction)editTrashGroup:(id)sender; -- (IBAction)exportDatabase:(id)sender; +- (IBAction)exportAsXML:(id)sender; +- (IBAction)importFromXML:(id)sender; - (IBAction)lock:(id)sender; diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index fe49e199..4460421b 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -189,7 +189,7 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) { [[self document] saveDocument:sender]; } -- (void)exportDatabase:(id)sender { +- (void)exportAsXML:(id)sender { NSSavePanel *savePanel = [NSSavePanel savePanel]; MPDocument *document = [self document]; [savePanel setNameFieldStringValue:[document displayName]]; @@ -198,10 +198,26 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) { [savePanel setCanSelectHiddenExtension:YES]; [savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) { if(result == NSFileHandlingPanelOKButton) { - [[self document] writeXMLToURL:savePanel.URL]; + [document writeXMLToURL:savePanel.URL]; } }]; } + +- (void)importFromXML:(id)sender { + NSOpenPanel *openPanel = [NSOpenPanel openPanel]; + MPDocument *document = [self document]; + [openPanel setAllowsMultipleSelection:NO]; + [openPanel setCanChooseDirectories:NO]; + [openPanel setCanChooseFiles:YES]; + [openPanel setAllowedFileTypes:@[(id)kUTTypeXML]]; + [openPanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) { + if(result == NSFileHandlingPanelOKButton) { + [document readXMLfromURL:openPanel.URL]; + [self.outlineViewController showOutline]; + } + }]; +} + - (void)performFindPanelAction:(id)sender { [self.entryViewController showFilter:sender]; }