From a0a81be042b06e7bf96948991ea84fc94c49eedc Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Tue, 27 Oct 2009 18:44:09 -0700 Subject: [PATCH 1/7] Add support for reviewing unsaved documents before application termination. --- AppKit/CPApplication.j | 30 +++++++++++++++++++++++++++++- AppKit/CPDocumentController.j | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) 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/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 From 228e801c91dd6f720c25c0d5c88bd9c1c641a634 Mon Sep 17 00:00:00 2001 From: Justin Mecham Date: Tue, 27 Oct 2009 21:23:16 -0400 Subject: [PATCH 2/7] Fixed the class name for archiving CPViewControllers (was CPCollectionView). --- Tools/nib2cib/NSViewController.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/nib2cib/NSViewController.j b/Tools/nib2cib/NSViewController.j index 18fcc5527..58d8fada3 100644 --- a/Tools/nib2cib/NSViewController.j +++ b/Tools/nib2cib/NSViewController.j @@ -43,7 +43,7 @@ - (Class)classForKeyedArchiver { - return [CPCollectionView class]; + return [CPViewController class]; } @end From 25634a66cb2d300fa9d96245ff266488486e63a2 Mon Sep 17 00:00:00 2001 From: Justin Mecham Date: Tue, 27 Oct 2009 21:22:00 -0400 Subject: [PATCH 3/7] Added support to nib2cib for specifying the "Nib Name" property of the View Controller palette to enable view controller initialization from cibs. --- AppKit/CPViewController.j | 15 ++++++++++----- Tools/nib2cib/NSViewController.j | 9 ++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/AppKit/CPViewController.j b/AppKit/CPViewController.j index a5493b960..63b3c275b 100644 --- a/AppKit/CPViewController.j +++ b/AppKit/CPViewController.j @@ -166,14 +166,15 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", - CPViewControllerTitleKey = @"CPViewControllerTitleKey"; + CPViewControllerTitleKey = @"CPViewControllerTitleKey", + CPViewControllerCibNameKey = @"CPViewControllerCibNameKey"; @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,19 +184,23 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", { _view = [aCoder decodeObjectForKey:CPViewControllerViewKey]; _title = [aCoder decodeObjectForKey:CPViewControllerTitleKey]; + _cibName = [aCoder decodeObjectForKey:CPViewControllerCibNameKey]; + _cibBundle = [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 { [super encodeWithCoder:aCoder]; + [aCoder encodeObject:_cibName forKey:CPViewControllerCibNameKey]; [aCoder encodeObject:_view forKey:CPViewControllerViewKey]; [aCoder encodeObject:_title forKey:CPViewControllerTitleKey]; } diff --git a/Tools/nib2cib/NSViewController.j b/Tools/nib2cib/NSViewController.j index 58d8fada3..9dc3ea5ac 100644 --- a/Tools/nib2cib/NSViewController.j +++ b/Tools/nib2cib/NSViewController.j @@ -27,14 +27,17 @@ - (id)NS_initWithCoder:(CPCoder)aCoder { - return [super NS_initWithCoder:aCoder]; + self = [super NS_initWithCoder:aCoder]; + + if (self) + _cibName = [aCoder decodeObjectForKey:@"NSNibName"]; + + return self; } @end @implementation NSViewController : CPViewController -{ -} - (id)initWithCoder:(CPCoder)aCoder { From d263c74d5def91f27cbaa529515f94afb7d72009 Mon Sep 17 00:00:00 2001 From: Justin Mecham Date: Tue, 27 Oct 2009 22:00:27 -0400 Subject: [PATCH 4/7] Added support for archiving NSTitle and NSNibBundleIdentifier from the View Controller palette for NSViewControllers. --- AppKit/CPViewController.j | 9 ++++++--- Tools/nib2cib/NSViewController.j | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/AppKit/CPViewController.j b/AppKit/CPViewController.j index 63b3c275b..0eebc67a4 100644 --- a/AppKit/CPViewController.j +++ b/AppKit/CPViewController.j @@ -167,7 +167,8 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", CPViewControllerTitleKey = @"CPViewControllerTitleKey", - CPViewControllerCibNameKey = @"CPViewControllerCibNameKey"; + CPViewControllerCibNameKey = @"CPViewControllerCibNameKey", + CPViewControllerBundleKey = @"CPViewControllerBundleKey"; @implementation CPViewController (CPCoding) @@ -185,7 +186,8 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", _view = [aCoder decodeObjectForKey:CPViewControllerViewKey]; _title = [aCoder decodeObjectForKey:CPViewControllerTitleKey]; _cibName = [aCoder decodeObjectForKey:CPViewControllerCibNameKey]; - _cibBundle = [CPBundle mainBundle]; + _cibBundle = [aCoder decodeObjectForKey:CPViewControllerBundleKey] || [CPBundle mainBundle]; + _cibExternalNameTable = [CPDictionary dictionaryWithObject:self forKey:CPCibOwner]; } @@ -200,9 +202,10 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", { [super encodeWithCoder:aCoder]; - [aCoder encodeObject:_cibName forKey:CPViewControllerCibNameKey]; [aCoder encodeObject:_view forKey:CPViewControllerViewKey]; [aCoder encodeObject:_title forKey:CPViewControllerTitleKey]; + [aCoder encodeObject:_cibName forKey:CPViewControllerCibNameKey]; + [aCoder encodeObject:_cibBundle forKey:CPViewControllerBundleKey]; } @end diff --git a/Tools/nib2cib/NSViewController.j b/Tools/nib2cib/NSViewController.j index 9dc3ea5ac..7284a124a 100644 --- a/Tools/nib2cib/NSViewController.j +++ b/Tools/nib2cib/NSViewController.j @@ -30,7 +30,11 @@ self = [super NS_initWithCoder:aCoder]; if (self) + { + _title = [aCoder decodeObjectForKey:@"NSTitle"]; _cibName = [aCoder decodeObjectForKey:@"NSNibName"]; + _cibBundle = [aCoder decodeObjectForKey:@"NSNibBundleIdentifier"]; + } return self; } From 42611f3a8431956ee226a4c18967efd6891c3176 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Wed, 28 Oct 2009 00:07:23 -0700 Subject: [PATCH 5/7] Missing GET_FILE import. --- Objective-J/Tools/objj/lib-js/objj/objjc.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Objective-J/Tools/objj/lib-js/objj/objjc.js b/Objective-J/Tools/objj/lib-js/objj/objjc.js index 553d60e7a..461d2c3a3 100644 --- a/Objective-J/Tools/objj/lib-js/objj/objjc.js +++ b/Objective-J/Tools/objj/lib-js/objj/objjc.js @@ -3,8 +3,9 @@ var FILE = require("file"), objj = require("./objj"), objj_preprocess = objj.objj_preprocess, IS_FILE = objj.IS_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, From 22c248454ef0bba9595d72a0a147cc23cbee6899 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Wed, 28 Oct 2009 00:11:42 -0700 Subject: [PATCH 6/7] Fix for the fact that bundles are not encodable in the last commits. --- AppKit/CPViewController.j | 6 ++++-- Tools/nib2cib/NSViewController.j | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/AppKit/CPViewController.j b/AppKit/CPViewController.j index 0eebc67a4..7aa31ec85 100644 --- a/AppKit/CPViewController.j +++ b/AppKit/CPViewController.j @@ -186,7 +186,9 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", _view = [aCoder decodeObjectForKey:CPViewControllerViewKey]; _title = [aCoder decodeObjectForKey:CPViewControllerTitleKey]; _cibName = [aCoder decodeObjectForKey:CPViewControllerCibNameKey]; - _cibBundle = [aCoder decodeObjectForKey:CPViewControllerBundleKey] || [CPBundle mainBundle]; + + var bundlePath = [aCoder decodeObjectForKey:CPViewControllerBundleKey]; + _cibBundle = bundlePath ? [CPBundle bundleWithPath:bundlePath] : [CPBundle mainBundle]; _cibExternalNameTable = [CPDictionary dictionaryWithObject:self forKey:CPCibOwner]; } @@ -205,7 +207,7 @@ var CPViewControllerViewKey = @"CPViewControllerViewKey", [aCoder encodeObject:_view forKey:CPViewControllerViewKey]; [aCoder encodeObject:_title forKey:CPViewControllerTitleKey]; [aCoder encodeObject:_cibName forKey:CPViewControllerCibNameKey]; - [aCoder encodeObject:_cibBundle forKey:CPViewControllerBundleKey]; + [aCoder encodeObject:[_cibBundle bundlePath] forKey:CPViewControllerBundleKey]; } @end diff --git a/Tools/nib2cib/NSViewController.j b/Tools/nib2cib/NSViewController.j index 7284a124a..a0e522a7a 100644 --- a/Tools/nib2cib/NSViewController.j +++ b/Tools/nib2cib/NSViewController.j @@ -33,7 +33,7 @@ { _title = [aCoder decodeObjectForKey:@"NSTitle"]; _cibName = [aCoder decodeObjectForKey:@"NSNibName"]; - _cibBundle = [aCoder decodeObjectForKey:@"NSNibBundleIdentifier"]; + _cibBundle = [CPBundle bundleWithPath:[aCoder decodeObjectForKey:@"NSNibBundleIdentifier"]]; } return self; From ba84e6d3e26d7a4be222fe7fe42cdb6bef3dfa3b Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Wed, 28 Oct 2009 00:12:03 -0700 Subject: [PATCH 7/7] Support for sendsActionOnEndEditing in CPControl. Only works for textfields right now. --- AppKit/CPControl.j | 3 ++- AppKit/CPTextField.j | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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/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; }