From 1299ad6aa29cd606ee9f33630bde0de22bae999f Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 16 Dec 1998 17:36:48 +0000 Subject: [PATCH] More tidying. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3471 72102866-910b-0410-8b05-ffd578937521 --- Source/NSApplication.m | 66 ++++++++++++++++++++++++++++++++++-------- Source/NSWindow.m | 21 ++++++-------- 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 29af890f0..77053ab4e 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -95,6 +95,10 @@ static id NSApp; static NSString *NSAbortModalException = @"NSAbortModalException"; +@interface NSApplication (Private) +- (void) _windowWillClose: (NSNotification*)n; +- (void) _windowWillOpen: (NSWindow*)win; +@end @implementation NSApplication @@ -1322,17 +1326,7 @@ NSWindow *w; */ if ([window_list indexOfObjectIdenticalTo: aWindow] == NSNotFound) { - [window_list addObject: aWindow]; - [aWindow setWindowNumber: window_count++]; - - /* - * If this was the first window then make it the main and key window. - */ - if ([window_list count] == 1) - { - [aWindow becomeMainWindow]; - [aWindow becomeKeyWindow]; - } + [self _windowWillOpen: aWindow]; } /* @@ -1342,6 +1336,15 @@ NSWindow *w; if ([aWindow isKindOfClass: [NSMenu class]]) return; + /* + * If this was the first window then make it the main and key window. + */ + if ([window_list count] == 1) + { + [aWindow becomeMainWindow]; + [aWindow becomeKeyWindow]; + } + /* * Can't permit an untitled window in the window menu. */ @@ -1379,7 +1382,6 @@ NSWindow *w; { menu = [[NSMenu alloc] initWithTitle: [windows_menu title]]; [self setWindowsMenu: menu]; - [menu release]; } /* @@ -1729,3 +1731,43 @@ BOOL result = YES; @end /* NSApplication */ +@implementation NSApplication (Private) +- (void) _windowWillClose: (NSNotification*)n +{ + NSWindow *win = [n object]; + + if ([win isReleasedWhenClosed]) + { + NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; + + [nc removeObserver: self + name: NSWindowWillCloseNotification + object: win]; + [window_list removeObjectIdenticalTo: win]; + + /* + * Horrible kludge to handle case where an application has no menu - we + * assume that this is the only window in the application and terminate. + * We only do this for windows that release when closed - any other + * window may be intended to re-open. + */ + if (main_menu == nil) + [self terminate: nil]; + } +} + +- (void) _windowWillOpen: (NSWindow*)win +{ + if ([window_list indexOfObjectIdenticalTo: win] == NSNotFound) + { + NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; + + [window_list addObject: win]; + [win setWindowNumber: window_count++]; + [nc addObserver: self + selector: @selector(_windowWillClose:) + name: NSWindowWillCloseNotification + object: win]; + } +} +@end diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 38c5899e8..206cc43b6 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -630,24 +630,21 @@ NSView *v; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; NSApplication *theApp = [NSApplication sharedApplication]; + /* + * If 'is_released_when_closed' then the window will be removed from the + * applications list of windows (causing it to be released) - so we must + * bracket any work we do in a retain/release sequence. + */ + if (is_released_when_closed) + [self retain]; + [nc postNotificationName: NSWindowWillCloseNotification object: self]; [theApp removeWindowsItem: self]; [self orderOut: self]; visible = NO; if (is_released_when_closed) - { - [self autorelease]; - - /* - * Horrible kludge to handle case where an application has no menu - we - * assume that this is the only window in the application and terminate. - * We only do this for windows that release when closed - any other - * window may be intended to re-open. - */ - if ([theApp mainMenu] == nil) - [theApp terminate: nil]; - } + [self release]; } - (void)deminiaturize:sender