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 f89ef8eff..9590829de 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -501,10 +501,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/CPTableView.j b/AppKit/CPTableView.j index 00d4e0d73..8dd282e4e 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -282,8 +282,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; _tableDrawView = [[_CPTableDrawView alloc] initWithTableView:self]; [_tableDrawView setBackgroundColor:[CPColor clearColor]]; [self addSubview:_tableDrawView]; - [self _init]; + [self setBackgroundColor:[CPColor whiteColor]]; + [self _init]; } return self; @@ -296,7 +297,6 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; [_dropOperationFeedbackView setTableView:self]; _lastColumnShouldSnap = NO; - _backgroundColor = [CPColor whiteColor]; // Gradients for the source list _sourceListActiveGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [89.0/255.0, 153.0/255.0, 209.0/255.0,1.0, 33.0/255.0, 94.0/255.0, 208.0/255.0,1.0], [0,1], 2); @@ -2200,14 +2200,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; - (void)drawBackgroundInClipRect:(CGRect)aRect { if (!_usesAlternatingRowBackgroundColors) - { - var context = [[CPGraphicsContext currentContext] graphicsPort]; - - CGContextSetFillColor(context, _backgroundColor); - CGContextFillRect(context, aRect); - return; - } var rowColors = [self alternatingRowBackgroundColors], 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