mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
Add CPApplicationWillTerminateNotification.
Reviewed by me.
This commit is contained in:
+35
-70
@@ -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
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user