diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 76e65a768..c5033ed53 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -39,6 +39,11 @@ CPApp = nil; CPApplicationWillFinishLaunchingNotification = @"CPApplicationWillFinishLaunchingNotification"; CPApplicationDidFinishLaunchingNotification = @"CPApplicationDidFinishLaunchingNotification"; +CPApplicationWillTerminateNotification = @"CPApplicationWillTerminateNotification"; + +CPTerminateNow = YES; +CPTerminateCancel = NO; +CPTerminateLater = -1; // not currently supported CPRunStoppedResponse = -1000; CPRunAbortedResponse = -1001; @@ -295,7 +300,30 @@ CPRunContinuesResponse = -1002; - (void)terminate:(id)aSender { - [CPPlatform terminateApplication]; + [[CPDocumentController sharedDocumentController] closeAllDocumentsWithDelegate:self + didCloseAllSelector:@selector(_documentController:didCloseAll:context:) + contextInfo:nil]; +} + +- (void)_documentController:(NSDocumentController *)docController didCloseAll:(BOOL)didCloseAll context:(Object)info +{ + // callback method for terminate: + if (didCloseAll) + { + if ([_delegate respondsToSelector:@selector(applicationShouldTerminate:)]) + [self replyToApplicationShouldTerminate:[_delegate applicationShouldTerminate:self]]; + else + [self replyToApplicationShouldTerminate:YES]; + } +} + +- (void)replyToApplicationShouldTerminate:(BOOL)terminate +{ + if (terminate == CPTerminateNow) + { + [[CPNotificationCenter defaultCenter] postNotificationName:CPApplicationWillTerminateNotification object:self]; + [CPPlatform terminateApplication]; + } } - (void)activateIgnoringOtherApps:(BOOL)shouldIgnoreOtherApps diff --git a/AppKit/CPControl.j b/AppKit/CPControl.j index d00f3aa6f..f9ddc817e 100644 --- a/AppKit/CPControl.j +++ b/AppKit/CPControl.j @@ -94,7 +94,8 @@ var CPControlBlackColor = [CPColor blackColor]; id _target; SEL _action; int _sendActionOn; - + BOOL _sendsActionOnEndEditing @accessors(property=sendsActionOnEndEditing); + // Mouse Tracking Support BOOL _continuousTracking; BOOL _trackingWasWithinFrame; diff --git a/AppKit/CPDocumentController.j b/AppKit/CPDocumentController.j index 7011c7902..c392d172e 100644 --- a/AppKit/CPDocumentController.j +++ b/AppKit/CPDocumentController.j @@ -323,3 +323,38 @@ var CPSharedDocumentController = nil; } @end + +@implementation CPDocumentController (Closing) + +- (void)closeAllDocumentsWithDelegate:(id)aDelegate didCloseAllSelector:(SEL)didCloseSelector contextInfo:(Object)info +{ + var context = { + delegate: aDelegate, + selector: didCloseSelector, + context: info + }; + + [self _closeDocumentsStartingWith:nil shouldClose:YES context:context]; +} + +// Recursive callback method. Start it by passing in a document of nil. +- (void)_closeDocumentsStartingWith:(CPDocument)aDocument shouldClose:(BOOL)shouldClose context:(Object)context +{ + if (shouldClose) + { + [aDocument close]; + + if ([[self documents] count] > 0) + { + [[[self documents] lastObject] canCloseDocumentWithDelegate:self + shouldCloseSelector:@selector(_closeDocumentsStartingWith:shouldClose:context:) + contextInfo:context]; + return; + } + } + + if ([context.delegate respondsToSelector:context.selector]) + objj_msgSend(context.delegate, context.selector, self, [[self documents] count] === 0, context.context); +} + +@end diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index ebf0815c9..1b253d44c 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -269,8 +269,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); if (aDOMEvent && aDOMEvent.keyCode == CPReturnKeyCode) { - [owner sendAction:[owner action] to:[owner target]]; - [[owner window] makeFirstResponder:nil]; + [owner sendAction:[owner action] to:[owner target]]; + [owner selectText:nil]; } else if (aDOMEvent && aDOMEvent.keyCode == CPTabKeyCode) { @@ -666,6 +666,9 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); //post CPControlTextDidEndEditingNotification [self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]]; + if ([self sendsActionOnEndEditing]) + [self sendAction:[self action] to:[self target]]; + return YES; } diff --git a/AppKit/CPViewController.j b/AppKit/CPViewController.j index a5493b960..7aa31ec85 100644 --- a/AppKit/CPViewController.j +++ b/AppKit/CPViewController.j @@ -166,14 +166,16 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", - CPViewControllerTitleKey = @"CPViewControllerTitleKey"; + CPViewControllerTitleKey = @"CPViewControllerTitleKey", + CPViewControllerCibNameKey = @"CPViewControllerCibNameKey", + CPViewControllerBundleKey = @"CPViewControllerBundleKey"; @implementation CPViewController (CPCoding) /*! - Initializes the view item by unarchiving data from a coder. + Initializes the view controller by unarchiving data from a coder. @param aCoder the coder from which the data will be unarchived - @return the initialized collection view item + @return the initialized view controller */ - (id)initWithCoder:(CPCoder)aCoder { @@ -183,14 +185,20 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", { _view = [aCoder decodeObjectForKey:CPViewControllerViewKey]; _title = [aCoder decodeObjectForKey:CPViewControllerTitleKey]; + _cibName = [aCoder decodeObjectForKey:CPViewControllerCibNameKey]; + + var bundlePath = [aCoder decodeObjectForKey:CPViewControllerBundleKey]; + _cibBundle = bundlePath ? [CPBundle bundleWithPath:bundlePath] : [CPBundle mainBundle]; + + _cibExternalNameTable = [CPDictionary dictionaryWithObject:self forKey:CPCibOwner]; } return self; } /*! - Archives the colletion view item to the provided coder. - @param aCoder the coder to which the view item should be archived + Archives the view controller to the provided coder. + @param aCoder the coder to which the view controller should be archived */ - (void)encodeWithCoder:(CPCoder)aCoder { @@ -198,6 +206,8 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", [aCoder encodeObject:_view forKey:CPViewControllerViewKey]; [aCoder encodeObject:_title forKey:CPViewControllerTitleKey]; + [aCoder encodeObject:_cibName forKey:CPViewControllerCibNameKey]; + [aCoder encodeObject:[_cibBundle bundlePath] forKey:CPViewControllerBundleKey]; } @end diff --git a/Objective-J/CommonJS/objective-j/lib-js/objective-j/compiler.js b/Objective-J/CommonJS/objective-j/lib-js/objective-j/compiler.js index b9d371630..1c921ee43 100644 --- a/Objective-J/CommonJS/objective-j/lib-js/objective-j/compiler.js +++ b/Objective-J/CommonJS/objective-j/lib-js/objective-j/compiler.js @@ -3,9 +3,9 @@ var FILE = require("file"), objj = require("objective-j"), objj_preprocess = objj.objj_preprocess, IS_FILE = objj.IS_FILE, - GET_FILE = objj.GET_FILE, - GET_CODE = objj.GET_CODE, IS_LOCAL = objj.IS_LOCAL, + GET_CODE = objj.GET_CODE, + GET_FILE = objj.GET_FILE, MARKER_IMPORT_STD = objj.MARKER_IMPORT_STD, MARKER_IMPORT_LOCAL = objj.MARKER_IMPORT_LOCAL, MARKER_CODE = objj.MARKER_CODE, diff --git a/Tools/nib2cib/NSViewController.j b/Tools/nib2cib/NSViewController.j index 18fcc5527..a0e522a7a 100644 --- a/Tools/nib2cib/NSViewController.j +++ b/Tools/nib2cib/NSViewController.j @@ -27,14 +27,21 @@ - (id)NS_initWithCoder:(CPCoder)aCoder { - return [super NS_initWithCoder:aCoder]; + self = [super NS_initWithCoder:aCoder]; + + if (self) + { + _title = [aCoder decodeObjectForKey:@"NSTitle"]; + _cibName = [aCoder decodeObjectForKey:@"NSNibName"]; + _cibBundle = [CPBundle bundleWithPath:[aCoder decodeObjectForKey:@"NSNibBundleIdentifier"]]; + } + + return self; } @end @implementation NSViewController : CPViewController -{ -} - (id)initWithCoder:(CPCoder)aCoder { @@ -43,7 +50,7 @@ - (Class)classForKeyedArchiver { - return [CPCollectionView class]; + return [CPViewController class]; } @end