diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index c5ddfdfaa..56964473d 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -213,85 +213,46 @@ CPRunContinuesResponse = -1002; { if (_delegate == aDelegate) return; - - var defaultCenter = [CPNotificationCenter defaultCenter]; - + + var defaultCenter = [CPNotificationCenter defaultCenter], + delegateNotifications = + [ + CPApplicationWillFinishLaunchingNotification, @selector(applicationWillFinishLaunching:), + CPApplicationDidFinishLaunchingNotification, @selector(applicationDidFinishLaunching:), + CPApplicationWillBecomeActiveNotification, @selector(applicationWillBecomeActive:), + CPApplicationDidBecomeActiveNotification, @selector(applicationDidBecomeActive:), + CPApplicationWillResignActiveNotification, @selector(applicationWillResignActive:), + CPApplicationDidResignActiveNotification, @selector(applicationDidResignActive:), + CPApplicationWillTerminateNotification, @selector(applicationWillTerminate:) + ], + count = [delegateNotifications count]; + if (_delegate) { - [defaultCenter - removeObserver:_delegate - name:CPApplicationWillFinishLaunchingNotification - object:self]; + var index = 0; - [defaultCenter - removeObserver:_delegate - name:CPApplicationDidFinishLaunchingNotification - object:self]; + for (; index < count; index += 2) + { + var notificationName = delegateNotifications[index], + selector = delegateNotifications[index + 1]; - [defaultCenter - removeObserver:_delegate - name:CPApplicationWillBecomeActiveNotification - object:self]; - - [defaultCenter - removeObserver:_delegate - name:CPApplicationDidBecomeActiveNotification - object:self]; - - [defaultCenter - removeObserver:_delegate - name:CPApplicationWillResignActiveNotification - object:self]; - - [defaultCenter - removeObserver:_delegate - name:CPApplicationDidResignActiveNotification - object:self]; + if ([_delegate respondsToSelector:selector]) + [defaultCenter removeObserver:_delegate name:notificationName object:self]; + } } - + _delegate = aDelegate; - - if ([_delegate respondsToSelector:@selector(applicationWillFinishLaunching:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(applicationWillFinishLaunching:) - name:CPApplicationWillFinishLaunchingNotification - object:self]; - - if ([_delegate respondsToSelector:@selector(applicationDidFinishLaunching:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(applicationDidFinishLaunching:) - name:CPApplicationDidFinishLaunchingNotification - object:self]; - if ([_delegate respondsToSelector:@selector(applicationWillBecomeActive:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(applicationWillBecomeActive:) - name:CPApplicationWillBecomeActiveNotification - object:self]; + var index = 0; - if ([_delegate respondsToSelector:@selector(applicationDidBecomeActive:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(applicationDidBecomeActive:) - name:CPApplicationDidBecomeActiveNotification - object:self]; + for (; index < count; index += 2) + { + var notificationName = delegateNotifications[index], + selector = delegateNotifications[index + 1]; - if ([_delegate respondsToSelector:@selector(applicationWillResignActive:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(applicationWillResignActive:) - name:CPApplicationWillResignActiveNotification - object:self]; - - if ([_delegate respondsToSelector:@selector(applicationDidResignActive:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(applicationDidResignActive:) - name:CPApplicationDidResignActiveNotification - object:self]; + if ([_delegate respondsToSelector:selector]) + [defaultCenter addObserver:_delegate selector:selector name:notificationName object:self]; + } } /*! @@ -370,6 +331,10 @@ CPRunContinuesResponse = -1002; - (void)terminate:(id)aSender { + [[CPNotificationCenter defaultCenter] + postNotificationName:CPApplicationWillTerminateNotification + object:self]; + if (![CPPlatform isBrowser]) { [[CPDocumentController sharedDocumentController] closeAllDocumentsWithDelegate:self diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index 7e29770da..d6ddd55b9 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -488,10 +488,10 @@ var CPDocumentUntitledCount = 0; [_writeRequest setValue:@"close" forHTTPHeaderField:@"Connection"]; - if (aSaveOperation == CPSaveOperation) + if (aSaveOperation === CPSaveOperation) [_writeRequest setValue:@"true" forHTTPHeaderField:@"x-cappuccino-overwrite"]; - if (aSaveOperation != CPSaveToOperation) + if (aSaveOperation !== CPSaveToOperation) [self updateChangeCount:CPChangeCleared]; // FIXME: Oh man is this every looking for trouble, we need to handle login at the Cappuccino level, with HTTP Errors. diff --git a/AppKit/Platform/DOM/CPPlatform.j b/AppKit/Platform/DOM/CPPlatform.j index 2c2c971b4..90c29cb90 100644 --- a/AppKit/Platform/DOM/CPPlatform.j +++ b/AppKit/Platform/DOM/CPPlatform.j @@ -44,6 +44,12 @@ var screenNeedsInitialization = NO, // We do this here because doing it later breaks IE. if (document.documentElement) document.documentElement.style.overflow = "hidden"; + + if ([CPPlatform isBrowser]) + window.onunload = function() + { + [CPApp terminate:nil]; + } } + (BOOL)isBrowser