Preserve version control dictionaries on save

This commit is contained in:
Matthias Neeracher 2006-11-17 08:57:29 +00:00
parent 26f135cb88
commit b1ac753039
3 changed files with 36 additions and 2 deletions

View File

@ -24,6 +24,7 @@
NSString * songGroove;
NSNumber * songTempo;
NSString * tmpPath;
NSFileWrapper * vcsWrapper;
VLSheetWindow * sheetWin;
VLLogWindow * logWin;

View File

@ -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"]) {

View File

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