From 15d8b973ba9d5aeb70e02052724f4f7d73cce5a6 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Thu, 3 Feb 2000 17:04:37 +0000 Subject: [PATCH] A few testing fixes. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@5917 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++ Gorm.m | 81 ++++++++++++++++++++++++-------------- GormDocument.h | 2 +- GormDocument.m | 105 ++++++++++++++++--------------------------------- GormPrivate.h | 3 +- 5 files changed, 93 insertions(+), 103 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7700a6c9..2fde3133 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Feb 3 16:16:59 2000 Richard Frith-Macdonald + + * Gorm.m: tidied start/end testing. + * GormDocument.m: ditto + Sat Jan 15 04:35:59 2000 Nicola Pero * GormObjectEditor.m ([GormObjectEditor -activate]), diff --git a/Gorm.m b/Gorm.m index 135b45bd..decce6bf 100644 --- a/Gorm.m +++ b/Gorm.m @@ -153,7 +153,6 @@ NSString *GormLinkPboardType = @"GormLinkPboardType"; RELEASE(infoPanel); RELEASE(inspectorsManager); RELEASE(palettesManager); - RELEASE(hiddenDuringTest); RELEASE(documents); RELEASE(classManager); [super dealloc]; @@ -267,8 +266,8 @@ NSString *GormLinkPboardType = @"GormLinkPboardType"; else { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + NSUserDefaults *defs; NSEnumerator *e; - NSWindow *w; id val; [nc postNotificationName: IBWillEndTestingInterfaceNotification @@ -288,15 +287,14 @@ NSString *GormLinkPboardType = @"GormLinkPboardType"; } DESTROY(testContainer); - /* - * Restore old windows. - */ - e = [hiddenDuringTest objectEnumerator]; - while ((w = [e nextObject]) != nil) - { - [w orderFront: self]; - } - [hiddenDuringTest removeAllObjects]; +{ +NSAutoreleasePool *p = [NSAutoreleasePool new]; + defs = [NSUserDefaults standardUserDefaults]; + [defs setObject: menuLocations forKey: @"NSMenuLocations"]; + DESTROY(menuLocations); +[p release]; +} + [self setMainMenu: mainMenu]; isTesting = NO; @@ -313,7 +311,6 @@ NSString *GormLinkPboardType = @"GormLinkPboardType"; - (void) finishLaunching { NSMenu *aMenu; - NSMenu *mainMenu; NSMenu *modulesMenu; NSMenu *windowsMenu; NSMenuItem *menuItem; @@ -556,7 +553,6 @@ NSString *GormLinkPboardType = @"GormLinkPboardType"; targetImage = [[NSImage alloc] initWithContentsOfFile: path]; documents = [NSMutableArray new]; - hiddenDuringTest = [NSMutableArray new]; [nc addObserver: self selector: @selector(handleNotification:) name: IBSelectionChangedNotification @@ -824,37 +820,29 @@ NSString *GormLinkPboardType = @"GormLinkPboardType"; } else { + NSUserDefaults *defs; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; GormDocument *a = (GormDocument*)[self activeDocument]; - NSEnumerator *e; - NSWindow *w; NSData *d; + [a beginArchiving]; + d = [NSArchiver archivedDataWithRootObject: a]; + [a endArchiving]; + [nc postNotificationName: IBWillBeginTestingInterfaceNotification object: self]; isTesting = YES; - [a beginArchiving]; - d = [NSArchiver archivedDataWithRootObject: a]; - [a endArchiving]; - - e = [[self windows] objectEnumerator]; - while ((w = [e nextObject]) != nil) - { - if ([w isVisible] == YES - && [w isKindOfClass: [NSMenuWindow class]] == NO) - { - [hiddenDuringTest addObject: w]; - [w orderOut: self]; - } - } - if ([selectionOwner conformsToProtocol: @protocol(IBEditors)] == YES) { [(id)selectionOwner makeSelectionVisible: NO]; } + defs = [NSUserDefaults standardUserDefaults]; + menuLocations = [[defs objectForKey: @"NSMenuLocations"] copy]; + [defs removeObjectForKey: @"NSMenuLocations"]; + testContainer = [NSUnarchiver unarchiveObjectWithData: d]; if (testContainer != nil) { @@ -862,6 +850,39 @@ NSString *GormLinkPboardType = @"GormLinkPboardType"; RETAIN(testContainer); } + /* + * If the NIB didn't have a main menu, create one, + * otherwise, ensure that 'quit' ends testing mode. + */ + if ([self mainMenu] == mainMenu) + { + NSMenu *testMenu; + + testMenu = [[NSMenu alloc] initWithTitle: @"Test"]; + [testMenu addItemWithTitle: @"Quit" + action: @selector(endTesting:) + keyEquivalent: @"q"]; + [self setMainMenu: testMenu]; + RELEASE(testMenu); + } + else + { + NSMenu *testMenu = [self mainMenu]; + NSMenuItem *item; + + item = [testMenu itemWithTitle: @"Quit"]; + if (item != nil) + { + [item setAction: @selector(endTesting:)]; + } + else + { + [testMenu addItemWithTitle: @"Quit" + action: @selector(endTesting:) + keyEquivalent: @"q"]; + } + } + [nc postNotificationName: IBDidBeginTestingInterfaceNotification object: self]; diff --git a/GormDocument.h b/GormDocument.h index 9a4646ba..c145b776 100644 --- a/GormDocument.h +++ b/GormDocument.h @@ -30,12 +30,12 @@ NSMatrix *selectionView; NSScrollView *scrollView; id objectsView; - BOOL hiddenDuringTest; BOOL hasSetDefaults; BOOL isActive; NSMenu *savedMenu; NSMenuItem *quitItem; /* Replaced during test */ NSMutableArray *savedEditors; + NSMutableArray *hidden; } - (void) addConnector: (id)aConnector; - (NSArray*) allConnectors; diff --git a/GormDocument.m b/GormDocument.m index 4a5a6fa3..4673d05f 100644 --- a/GormDocument.m +++ b/GormDocument.m @@ -378,6 +378,7 @@ static NSImage *classesImage = nil; [[NSNotificationCenter defaultCenter] removeObserver: self]; [window setDelegate: nil]; [window performClose: self]; + RELEASE(hidden); RELEASE(window); RELEASE(filesOwner); RELEASE(firstResponder); @@ -637,96 +638,57 @@ static NSImage *classesImage = nil; { if ([window isVisible] == YES) { - hiddenDuringTest = YES; + [hidden addObject: window]; [window setExcludedFromWindowsMenu: YES]; [window orderOut: self]; - /* - * If this is the active document, we must replace the main menu with - * our own version using a modified 'Quit' item (to end testing). - * and we should try to make one of our windows key. - */ - if ([(id)NSApp activeDocument] == self) + } + if ([(id)NSApp activeDocument] == self) + { + NSEnumerator *enumerator; + id obj; + + enumerator = [nameTable objectEnumerator]; + while ((obj = [enumerator nextObject]) != nil) { - NSWindow *keyWindow = nil; - NSMenu *testMenu = nil; - NSMenuItem *item; - NSArray *links; - NSEnumerator *e; - NSNibConnector *con; - - [connections makeObjectsPerform: @selector(establishConnection)]; - /* - * Get links for all the top-level objects - */ - links = [self connectorsForDestination: filesOwner - ofClass: [NSNibConnector class]]; - e = [links objectEnumerator]; - while ((con = [e nextObject]) != nil) + if ([obj isKindOfClass: [NSMenu class]] == YES) { - id obj = [con source]; - - if ([obj isKindOfClass: [NSMenu class]] == YES) + if ([[obj window] isVisible] == YES) { - testMenu = obj; - } - else if ([obj isKindOfClass: [NSWindow class]] == YES) - { - if (keyWindow == nil || [keyWindow isVisible] == NO) - { - keyWindow = obj; - } + [hidden addObject: obj]; + [obj close]; } } - - if (testMenu == nil) + else if ([obj isKindOfClass: [NSWindow class]] == YES) { - testMenu = [[NSMenu alloc] initWithTitle: @"Test"]; - AUTORELEASE(testMenu); + if ([obj isVisible] == YES) + { + [hidden addObject: obj]; + [obj orderOut: self]; + } } - item = [testMenu itemWithTitle: @"Quit"]; - if (item != nil) - { - quitItem = RETAIN(item); - [testMenu removeItem: item]; - } - [testMenu addItemWithTitle: @"Quit" - action: @selector(endTesting:) - keyEquivalent: @"q"]; - savedMenu = RETAIN([NSApp mainMenu]); - [NSApp setMainMenu: testMenu]; - [keyWindow makeKeyAndOrderFront: self]; - RELEASE(testMenu); } } } else if ([name isEqual: IBWillEndTestingInterfaceNotification] == YES) { - if (hiddenDuringTest == YES) + if ([hidden count] > 0) { - hiddenDuringTest = NO; - /* - * If this is the active document, we must restore the main menu - * and restore the 'Quit' menu item (which was used to end testing) - * to its original value. - */ - if ([(id)NSApp activeDocument] == self) - { - NSMenu *testMenu = [NSApp mainMenu]; - NSMenuItem *item = [testMenu itemWithTitle: @"Quit"]; + NSEnumerator *enumerator; + id obj; - [testMenu removeItem: item]; - if (quitItem != nil) + enumerator = [hidden objectEnumerator]; + while ((obj = [enumerator nextObject]) != nil) + { + if ([obj isKindOfClass: [NSMenu class]] == YES) { - [testMenu addItem: quitItem]; - DESTROY(quitItem); + [obj display]; + } + else if ([obj isKindOfClass: [NSWindow class]] == YES) + { + [obj orderFront: self]; } - /* - * restore the main menu. - */ - [NSApp setMainMenu: savedMenu]; - DESTROY(savedMenu); } - [window orderFront: self]; + [hidden removeAllObjects]; [window setExcludedFromWindowsMenu: NO]; } } @@ -861,6 +823,7 @@ static NSImage *classesImage = nil; fontManager = [GormFontManager new]; [self setName: @"NSFont" forObject: fontManager]; + hidden = [NSMutableArray new]; /* * Watch to see when we are starting/ending testing. */ diff --git a/GormPrivate.h b/GormPrivate.h index 19e002e3..08310dce 100644 --- a/GormPrivate.h +++ b/GormPrivate.h @@ -31,8 +31,9 @@ extern NSString *GormLinkPboardType; NSMutableArray *documents; BOOL isConnecting; BOOL isTesting; - NSMutableArray *hiddenDuringTest; id testContainer; + NSMenu *mainMenu; + NSDictionary *menuLocations; NSImage *linkImage; NSImage *sourceImage; NSImage *targetImage;