diff --git a/Sources/VLDocument.h b/Sources/VLDocument.h index 698a86c..8a0ce09 100644 --- a/Sources/VLDocument.h +++ b/Sources/VLDocument.h @@ -24,6 +24,7 @@ NSString * songGroove; NSNumber * songTempo; NSString * tmpPath; + NSFileWrapper * vcsWrapper; VLSheetWindow * sheetWin; VLLogWindow * logWin; diff --git a/Sources/VLDocument.mm b/Sources/VLDocument.mm index c5bb5f4..af783b0 100644 --- a/Sources/VLDocument.mm +++ b/Sources/VLDocument.mm @@ -34,6 +34,7 @@ pdfWin = nil; logWin = nil; tmpPath = nil; + vcsWrapper = nil; } return self; } @@ -47,6 +48,7 @@ [songLyricist release]; [songComposer release]; [songArranger release]; + [vcsWrapper release]; if (tmpPath) { [[NSFileManager defaultManager] removeFileAtPath:tmpPath handler:nil]; @@ -190,6 +192,30 @@ stringByAppendingPathExtension:extension]]; } +- (BOOL)saveToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError **)outError +{ + NSFileWrapper * preservedVCSWrapper = nil; + switch (saveOperation) { + case NSSaveToOperation: + case NSAutosaveOperation: + preservedVCSWrapper = vcsWrapper; + [preservedVCSWrapper retain]; + // Fall through + case NSSaveAsOperation: + [vcsWrapper release]; + vcsWrapper = nil; + // Fall through + case NSSaveOperation: + break; + } + BOOL res = [super saveToURL:absoluteURL ofType:typeName + forSaveOperation:saveOperation error:outError]; + if (!vcsWrapper) + vcsWrapper = preservedVCSWrapper; + + return res; +} + - (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName error:(NSError **)outError { if ([typeName isEqual:@"VLNativeType"]) { diff --git a/Sources/VLXMLDocument.mm b/Sources/VLXMLDocument.mm index 0177b8e..4e1e24a 100644 --- a/Sources/VLXMLDocument.mm +++ b/Sources/VLXMLDocument.mm @@ -300,6 +300,8 @@ const char * sSteps = "C DbD EbE F GbG AbA BbB "; autorelease]; [wrap addRegularFileWithContents:contents preferredFilename:@"Song"]; + if (vcsWrapper) + [wrap addFileWrapper:vcsWrapper]; return wrap; } @@ -456,8 +458,13 @@ int8_t sStepToPitch[] = { - (BOOL)readFromXMLFileWrapper:(NSFileWrapper *)wrapper error:(NSError **)outError { - return [self readFromXMLData: [[[wrapper fileWrappers] objectForKey:@"Song"] - regularFileContents] + NSDictionary * wrappers = [wrapper fileWrappers]; + if ((vcsWrapper = [wrappers objectForKey:@"CVS"]) + || (vcsWrapper = [wrappers objectForKey:@".svn"]) + ) + [vcsWrapper retain]; + return [self readFromXMLData: + [[wrappers objectForKey:@"Song"] regularFileContents] error:outError]; }