mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 17:32:17 +00:00
Added Import from XML functionality. KPKXmlTreeReader is not fully working with all possible formats (zipped or non zipped data)
This commit is contained in:
@@ -94,6 +94,18 @@
|
||||
<menuItem isSeparatorItem="YES" id="79">
|
||||
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
|
||||
</menuItem>
|
||||
<menuItem title="Import XML…" id="rW0-r1-QYL">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="importFromXML:" target="-1" id="ESL-Uw-7fk"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Export As XML…" keyEquivalent="E" id="1259">
|
||||
<connections>
|
||||
<action selector="exportAsXML:" target="-1" id="NCG-gr-YI5"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="FVA-Cn-g79"/>
|
||||
<menuItem title="Lock" keyEquivalent="L" id="1261">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES"/>
|
||||
<connections>
|
||||
@@ -115,11 +127,6 @@
|
||||
<action selector="saveDocumentAs:" target="-1" id="1255"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Export As XML…" keyEquivalent="E" id="1259">
|
||||
<connections>
|
||||
<action selector="exportDatabase:" target="-1" id="1260"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Revert to Saved" id="112">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
@(MPActionLock) : @"lock:",
|
||||
@(MPActionEmptyTrash) : @"emptyTrash:",
|
||||
@(MPActionDatabaseSettings) : @"showDatabaseSettings:",
|
||||
@(MPActionEditTemplateGroup) : @"editTemplateGroup:"
|
||||
@(MPActionEditTemplateGroup) : @"editTemplateGroup:",
|
||||
@(MPActionExportXML) : @"exportAsXML",
|
||||
@(MPActionImportXML) : @"importFromXMl",
|
||||
};
|
||||
});
|
||||
return actionDict;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user