mirror of
https://github.com/MacPass/MacPass.git
synced 2026-01-31 20:08:23 +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">
|
<menuItem isSeparatorItem="YES" id="79">
|
||||||
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
|
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
|
||||||
</menuItem>
|
</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">
|
<menuItem title="Lock" keyEquivalent="L" id="1261">
|
||||||
<modifierMask key="keyEquivalentModifierMask" control="YES"/>
|
<modifierMask key="keyEquivalentModifierMask" control="YES"/>
|
||||||
<connections>
|
<connections>
|
||||||
@@ -115,11 +127,6 @@
|
|||||||
<action selector="saveDocumentAs:" target="-1" id="1255"/>
|
<action selector="saveDocumentAs:" target="-1" id="1255"/>
|
||||||
</connections>
|
</connections>
|
||||||
</menuItem>
|
</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">
|
<menuItem title="Revert to Saved" id="112">
|
||||||
<modifierMask key="keyEquivalentModifierMask"/>
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
<connections>
|
<connections>
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ typedef NS_ENUM(NSUInteger, MPActionType) {
|
|||||||
MPActionEmptyTrash, // empties the trashcan, if there is one
|
MPActionEmptyTrash, // empties the trashcan, if there is one
|
||||||
MPActionEditPassword, // change the database password
|
MPActionEditPassword, // change the database password
|
||||||
MPActionDatabaseSettings, // Show the settings for the database
|
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
|
* Helper to retrieve commonly used actions
|
||||||
|
|||||||
@@ -27,7 +27,9 @@
|
|||||||
@(MPActionLock) : @"lock:",
|
@(MPActionLock) : @"lock:",
|
||||||
@(MPActionEmptyTrash) : @"emptyTrash:",
|
@(MPActionEmptyTrash) : @"emptyTrash:",
|
||||||
@(MPActionDatabaseSettings) : @"showDatabaseSettings:",
|
@(MPActionDatabaseSettings) : @"showDatabaseSettings:",
|
||||||
@(MPActionEditTemplateGroup) : @"editTemplateGroup:"
|
@(MPActionEditTemplateGroup) : @"editTemplateGroup:",
|
||||||
|
@(MPActionExportXML) : @"exportAsXML",
|
||||||
|
@(MPActionImportXML) : @"importFromXMl",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return actionDict;
|
return actionDict;
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
|
|||||||
- (BOOL)isItemTrashed:(id)item;
|
- (BOOL)isItemTrashed:(id)item;
|
||||||
|
|
||||||
- (void)writeXMLToURL:(NSURL *)url;
|
- (void)writeXMLToURL:(NSURL *)url;
|
||||||
|
- (void)readXMLfromURL:(NSURL *)url;
|
||||||
|
|
||||||
/* Undoable Intiialization of elements */
|
/* Undoable Intiialization of elements */
|
||||||
- (KPKGroup *)createGroup:(KPKGroup *)parent;
|
- (KPKGroup *)createGroup:(KPKGroup *)parent;
|
||||||
|
|||||||
@@ -83,6 +83,10 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
|
|||||||
|
|
||||||
@implementation MPDocument
|
@implementation MPDocument
|
||||||
|
|
||||||
|
+ (NSSet *)keyPathsForValuesAffectingRoot {
|
||||||
|
return [NSSet setWithObject:@"tree"];
|
||||||
|
}
|
||||||
|
|
||||||
+ (KPKVersion)versionForFileType:(NSString *)fileType {
|
+ (KPKVersion)versionForFileType:(NSString *)fileType {
|
||||||
if( NSOrderedSame == [fileType compare:MPLegacyDocumentUTI options:NSCaseInsensitiveSearch]) {
|
if( NSOrderedSame == [fileType compare:MPLegacyDocumentUTI options:NSCaseInsensitiveSearch]) {
|
||||||
return KPKLegacyVersion;
|
return KPKLegacyVersion;
|
||||||
@@ -235,6 +239,13 @@ typedef NS_ENUM(NSUInteger, MPAlertType) {
|
|||||||
[xmlData writeToURL:url atomically:YES];
|
[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
|
#pragma mark Lock/Unlock/Decrypt
|
||||||
|
|
||||||
- (void)lockDatabase:(id)sender {
|
- (void)lockDatabase:(id)sender {
|
||||||
|
|||||||
@@ -33,7 +33,8 @@
|
|||||||
- (IBAction)editTemplateGroup:(id)sender;
|
- (IBAction)editTemplateGroup:(id)sender;
|
||||||
- (IBAction)editTrashGroup:(id)sender;
|
- (IBAction)editTrashGroup:(id)sender;
|
||||||
|
|
||||||
- (IBAction)exportDatabase:(id)sender;
|
- (IBAction)exportAsXML:(id)sender;
|
||||||
|
- (IBAction)importFromXML:(id)sender;
|
||||||
|
|
||||||
- (IBAction)lock:(id)sender;
|
- (IBAction)lock:(id)sender;
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
[[self document] saveDocument:sender];
|
[[self document] saveDocument:sender];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)exportDatabase:(id)sender {
|
- (void)exportAsXML:(id)sender {
|
||||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||||
MPDocument *document = [self document];
|
MPDocument *document = [self document];
|
||||||
[savePanel setNameFieldStringValue:[document displayName]];
|
[savePanel setNameFieldStringValue:[document displayName]];
|
||||||
@@ -198,10 +198,26 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
|
|||||||
[savePanel setCanSelectHiddenExtension:YES];
|
[savePanel setCanSelectHiddenExtension:YES];
|
||||||
[savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
|
[savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
|
||||||
if(result == NSFileHandlingPanelOKButton) {
|
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 {
|
- (void)performFindPanelAction:(id)sender {
|
||||||
[self.entryViewController showFilter:sender];
|
[self.entryViewController showFilter:sender];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user