Add CPApplicationWillTerminateNotification.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I
2010-04-12 12:21:45 -07:00
parent 8aecf880e5
commit b3141f1a62
3 changed files with 43 additions and 72 deletions
+35 -70
View File
@@ -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
+2 -2
View File
@@ -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.
+6
View File
@@ -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