From 1f60eb1a440541b95a0535a07e01288a12bb5222 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Sun, 21 Jan 2007 11:34:40 +0000 Subject: [PATCH] Close virgin windows on open --- Sources/VLDocument.h | 2 ++ Sources/VLDocument.mm | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Sources/VLDocument.h b/Sources/VLDocument.h index e3dc7a8..83c1243 100644 --- a/Sources/VLDocument.h +++ b/Sources/VLDocument.h @@ -27,6 +27,7 @@ NSString * tmpPath; NSFileWrapper * vcsWrapper; int repeatVolta; + bool brandNew; VLSheetWindow * sheetWin; VLLogWindow * logWin; @@ -39,6 +40,7 @@ - (NSNumber *) songTime; - (NSNumber *) songDivisions; - (int) repeatVolta; +- (bool) brandNew; - (void) setKey:(int)key transpose:(BOOL)transpose; - (void) setTimeNum:(int)num denom:(int)denom; diff --git a/Sources/VLDocument.mm b/Sources/VLDocument.mm index fe6d28b..5f253a1 100644 --- a/Sources/VLDocument.mm +++ b/Sources/VLDocument.mm @@ -73,6 +73,7 @@ tmpPath = nil; vcsWrapper = nil; repeatVolta = 2; + brandNew = true; [self setHasUndoManager:YES]; undo = [[VLKeyValueUndo alloc] initWithOwner:self @@ -114,6 +115,8 @@ logWin = nil; else if (win == pdfWin) pdfWin = nil; + else if (win == sheetWin) + sheetWin = nil; [super removeWindowController:win]; } @@ -223,6 +226,11 @@ return repeatVolta; } +- (bool) brandNew +{ + return brandNew && ![self isDocumentEdited]; +} + - (void) setRepeatVolta:(int)volta { repeatVolta = volta; @@ -305,6 +313,17 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)wrapper ofType:(NSString *)typeName error:(NSError **)outError { + brandNew = false; + // + // On opening a document, close all unchanged empty documents + // + NSEnumerator * docs = [[[NSDocumentController sharedDocumentController] + documents] objectEnumerator]; + while (VLDocument * doc = [docs nextObject]) + if ([doc brandNew]) + [[doc windowControllers] + makeObjectsPerformSelector:@selector(close)]; + if ([typeName isEqual:@"VLNativeType"]) { return [self readFromXMLFileWrapper:wrapper error:outError]; } else {