Added Import from XML functionality. KPKXmlTreeReader is not fully working with all possible formats (zipped or non zipped data)

This commit is contained in:
michael starke
2013-12-02 02:06:21 +01:00
parent 3f1e7d36c9
commit 336fe02e2d
7 changed files with 50 additions and 10 deletions

View File

@@ -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>

View File

@@ -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

View File

@@ -27,7 +27,9 @@
@(MPActionLock) : @"lock:",
@(MPActionEmptyTrash) : @"emptyTrash:",
@(MPActionDatabaseSettings) : @"showDatabaseSettings:",
@(MPActionEditTemplateGroup) : @"editTemplateGroup:"
@(MPActionEditTemplateGroup) : @"editTemplateGroup:",
@(MPActionExportXML) : @"exportAsXML",
@(MPActionImportXML) : @"importFromXMl",
};
});
return actionDict;

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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];
}