diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 9e1b7844b..e23aab878 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -54,7 +54,7 @@ CPRunStoppedResponse = -1000; CPRunAbortedResponse = -1001; CPRunContinuesResponse = -1002; -/*! +/*! @ingroup appkit @class CPApplication @@ -62,7 +62,7 @@ CPRunContinuesResponse = -1002; Every GUI application has exactly one instance of CPApplication (or of a custom subclass of CPApplication). Your program's main() function can create that instance by calling the \c CPApplicationMain function. A simple example looks like this: - +
     function main(args, namedArgs)
     {
@@ -82,25 +82,25 @@ CPRunContinuesResponse  = -1002;
 @implementation CPApplication : CPResponder
 {
     CPArray                 _eventListeners;
-    
+
     CPEvent                 _currentEvent;
-    
+
     CPArray                 _windows;
     CPWindow                _keyWindow;
     CPWindow                _mainWindow;
     CPWindow                _previousKeyWindow;
     CPWindow                _previousMainWindow;
-    
+
     CPMenu                  _mainMenu;
     CPDocumentController    _documentController;
-    
+
     CPModalSession          _currentSession;
-    
+
     //
     id                      _delegate;
     BOOL                    _finishedLaunching;
     BOOL                    _isActive;
-    
+
     CPDictionary            _namedArgs;
     CPArray                 _args;
     CPString                _fullArgsString;
@@ -119,7 +119,7 @@ CPRunContinuesResponse  = -1002;
 {
     if (!CPApp)
         CPApp = [[CPApplication alloc] init];
-    
+
     return CPApp;
 }
 
@@ -137,71 +137,12 @@ CPRunContinuesResponse  = -1002;
     if (self)
     {
         _eventListeners = [];
-        
+
         _windows = [];
-        
+
         [_windows addObject:nil];
-    
-        // FIXME: This should be read from the cib.
-        var mainMenu = [[CPMenu alloc] initWithTitle:@"MainMenu"];
-        
-        // FIXME: We should implement autoenabling.
-        [mainMenu setAutoenablesItems:NO];
-
-        var bundle = [CPBundle bundleForClass:[CPApplication class]],
-            newMenuItem = [[CPMenuItem alloc] initWithTitle:@"New" action:@selector(newDocument:) keyEquivalent:@"n"];
-
-        [newMenuItem setImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPApplication/New.png"] size:CGSizeMake(16.0, 16.0)]];
-        [newMenuItem setAlternateImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPApplication/NewHighlighted.png"] size:CGSizeMake(16.0, 16.0)]];
-
-        [mainMenu addItem:newMenuItem];
-        
-        var openMenuItem = [[CPMenuItem alloc] initWithTitle:@"Open" action:@selector(openDocument:) keyEquivalent:@"o"];
-        
-        [openMenuItem setImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPApplication/Open.png"] size:CGSizeMake(16.0, 16.0)]];
-        [openMenuItem setAlternateImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPApplication/OpenHighlighted.png"] size:CGSizeMake(16.0, 16.0)]];
-        
-        [mainMenu addItem:openMenuItem];
-        
-        var saveMenu = [[CPMenu alloc] initWithTitle:@"Save"],
-            saveMenuItem = [[CPMenuItem alloc] initWithTitle:@"Save" action:@selector(saveDocument:) keyEquivalent:nil];
-        
-        [saveMenuItem setImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPApplication/Save.png"] size:CGSizeMake(16.0, 16.0)]];
-        [saveMenuItem setAlternateImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPApplication/SaveHighlighted.png"] size:CGSizeMake(16.0, 16.0)]];        
-        
-        [saveMenu addItem:[[CPMenuItem alloc] initWithTitle:@"Save" action:@selector(saveDocument:) keyEquivalent:@"s"]];
-        [saveMenu addItem:[[CPMenuItem alloc] initWithTitle:@"Save As" action:@selector(saveDocumentAs:) keyEquivalent:nil]];
-        
-        [saveMenuItem setSubmenu:saveMenu];
-        
-        [mainMenu addItem:saveMenuItem];
-        
-        var editMenuItem = [[CPMenuItem alloc] initWithTitle:@"Edit" action:nil keyEquivalent:nil],
-            editMenu = [[CPMenu alloc] initWithTitle:@"Edit"],
-            
-            undoMenuItem = [[CPMenuItem alloc] initWithTitle:@"Undo" action:@selector(undo:) keyEquivalent:CPUndoKeyEquivalent],
-            redoMenuItem = [[CPMenuItem alloc] initWithTitle:@"Redo" action:@selector(redo:) keyEquivalent:CPRedoKeyEquivalent];
-
-        [undoMenuItem setKeyEquivalentModifierMask:CPUndoKeyEquivalentModifierMask];        
-        [redoMenuItem setKeyEquivalentModifierMask:CPRedoKeyEquivalentModifierMask];
-        
-        [editMenu addItem:undoMenuItem];
-        [editMenu addItem:redoMenuItem];
-        
-        [editMenu addItem:[[CPMenuItem alloc] initWithTitle:@"Cut" action:@selector(cut:) keyEquivalent:@"x"]],
-        [editMenu addItem:[[CPMenuItem alloc] initWithTitle:@"Copy" action:@selector(copy:) keyEquivalent:@"c"]],
-        [editMenu addItem:[[CPMenuItem alloc] initWithTitle:@"Paste" action:@selector(paste:) keyEquivalent:@"v"]];
-    
-        [editMenuItem setSubmenu:editMenu];
-        [editMenuItem setHidden:YES];
-        
-        [mainMenu addItem:editMenuItem];
-        
-        [mainMenu addItem:[CPMenuItem separatorItem]];
-
-        [self setMainMenu:mainMenu];
     }
-    
+
     return self;
 }
 
@@ -282,28 +223,28 @@ CPRunContinuesResponse  = -1002;
 
     // We also want to set the default cursor on the body, so that buttons and things don't have an iBeam
     [[CPCursor arrowCursor] set];
-    
+
     var bundle = [CPBundle mainBundle],
         types = [bundle objectForInfoDictionaryKey:@"CPBundleDocumentTypes"];
-        
+
     if ([types count] > 0)
         _documentController = [CPDocumentController sharedDocumentController];
-        
+
     var delegateClassName = [bundle objectForInfoDictionaryKey:@"CPApplicationDelegateClass"];
-    
+
     if (delegateClassName)
     {
         var delegateClass = objj_getClass(delegateClassName);
-        
+
         if (delegateClass)
             if ([_documentController class] == delegateClass)
                 [self setDelegate:_documentController];
             else
                 [self setDelegate:[[delegateClass alloc] init]];
     }
-    
+
     var defaultCenter = [CPNotificationCenter defaultCenter];
-    
+
     [defaultCenter
         postNotificationName:CPApplicationWillFinishLaunchingNotification
         object:self];
@@ -392,14 +333,14 @@ CPRunContinuesResponse  = -1002;
             versionLabel = [contentView viewWithTag:3],
             copyrightLabel = [contentView viewWithTag:4],
             standardPath = [[CPBundle bundleForClass:[self class]] pathForResource:@"standardApplicationIcon.png"];
-    
+
         // FIXME move this into the CIB eventually
         [applicationLabel setFont:[CPFont boldSystemFontOfSize:14.0]];
         [applicationLabel setAlignment:CPCenterTextAlignment];
         [versionLabel setAlignment:CPCenterTextAlignment];
         [copyrightLabel setAlignment:CPCenterTextAlignment];
 
-        [imageView setImage:applicationIcon || [[CPImage alloc] initWithContentsOfFile:standardPath 
+        [imageView setImage:applicationIcon || [[CPImage alloc] initWithContentsOfFile:standardPath
                                                                                   size:CGSizeMake(256, 256)]];
 
         [applicationLabel setStringValue:applicationTitle || ""];
@@ -503,10 +444,10 @@ CPRunContinuesResponse  = -1002;
         return;
         // raise exception;
     }
-    
+
     _currentSession._state = aCode;
     _currentSession = _currentSession._previous;
-    
+
 //    if (aCode == CPRunAbortedResponse)
         [self _removeRunModalLoop];
 }
@@ -515,12 +456,12 @@ CPRunContinuesResponse  = -1002;
 - (void)_removeRunModalLoop
 {
     var count = _eventListeners.length;
-    
+
     while (count--)
         if (_eventListeners[count]._callback === _CPRunModalLoop)
         {
             _eventListeners.splice(count, 1);
-            
+
             return;
         }
 }
@@ -558,12 +499,12 @@ CPRunContinuesResponse  = -1002;
 {
     aModalSession._previous = _currentSession;
     _currentSession = aModalSession;
-    
+
     var theWindow = aModalSession._window;
 
     [theWindow center];
     [theWindow makeKeyAndOrderFront:self];
-    
+
 //    [theWindow._bridge _obscureWindowsBelowModalWindow];
 
     [CPApp setCallback:_CPRunModalLoop forNextEventMatchingMask:CPAnyEventMask untilDate:nil inMode:0 dequeue:NO];
@@ -577,7 +518,7 @@ CPRunContinuesResponse  = -1002;
 {
     if (!_currentSession)
         return nil;
-    
+
     return _currentSession._window;
 }
 
@@ -622,7 +563,7 @@ CPRunContinuesResponse  = -1002;
     {
         if (_eventListeners[_eventListeners.length - 1]._mask & (1 << [anEvent type]))
             _eventListeners.pop()._callback(anEvent);
-        
+
         return;
     }
 
@@ -733,11 +674,11 @@ CPRunContinuesResponse  = -1002;
 
     if ([super tryToPerform:anAction with:anObject])
         return YES;
-    
+
     if([_delegate respondsToSelector:anAction])
     {
         [_delegate performSelector:anAction withObject:anObject];
-        
+
         return YES;
     }
 
@@ -757,9 +698,9 @@ CPRunContinuesResponse  = -1002;
 
     if (!target)
         return NO;
-    
+
     [target performSelector:anAction withObject:aSender];
-    
+
     return YES;
 }
 
@@ -778,10 +719,10 @@ CPRunContinuesResponse  = -1002;
 {
     if (!anAction)
         return nil;
-        
+
     if (aTarget)
         return aTarget;
-        
+
     return [self targetForAction:anAction];
 }
 
@@ -806,28 +747,28 @@ CPRunContinuesResponse  = -1002;
 {
     var responder = [aWindow firstResponder],
         checkWindow = YES;
-    
+
     while (responder)
     {
         if ([responder respondsToSelector:anAction])
             return responder;
-        
+
         if (responder == aWindow)
             checkWindow = NO;
-        
+
         responder = [responder nextResponder];
     }
-    
+
     if (checkWindow && [aWindow respondsToSelector:anAction])
         return aWindow;
-    
+
     var delegate = [aWindow delegate];
-    
+
     if ([delegate respondsToSelector:anAction])
         return delegate;
 
     var windowController = [aWindow windowController];
-    
+
     if ([windowController respondsToSelector:anAction])
         return windowController;
 
@@ -856,26 +797,26 @@ CPRunContinuesResponse  = -1002;
 {
     if (!anAction)
         return nil;
-    
+
     var target = [self _targetForWindow:[self keyWindow] action:anAction];
-    
+
     if (target)
         return target;
-        
+
     target = [self _targetForWindow:[self mainWindow] action:anAction];
-    
+
     if (target)
         return target;
-    
+
     if ([self respondsToSelector:anAction])
         return self;
-    
+
     if ([_delegate respondsToSelector:anAction])
         return _delegate;
-        
+
     if ([_documentController respondsToSelector:anAction])
         return _documentController;
-    
+
     return nil;
 }
 
@@ -905,14 +846,14 @@ CPRunContinuesResponse  = -1002;
     @param aContextInfo
 */
 - (void)beginSheet:(CPWindow)aSheet modalForWindow:(CPWindow)aWindow modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo
-{    
+{
     var styleMask = [aSheet styleMask];
     if (!(styleMask & CPDocModalWindowMask))
     {
         [CPException raise:CPInternalInconsistencyException reason:@"Currently only CPDocModalWindowMask style mask is supported for attached sheets"];
         return;
     }
-    
+
     [aWindow orderFront:self];
     [aWindow _attachSheet:aSheet modalDelegate:aModalDelegate didEndSelector:aDidEndSelector contextInfo:aContextInfo];
 }
@@ -920,15 +861,15 @@ CPRunContinuesResponse  = -1002;
 - (void)endSheet:(CPWindow)sheet returnCode:(int)returnCode
 {
     var count = [_windows count];
-    
+
     while (--count >= 0)
     {
         var aWindow = [_windows objectAtIndex:count];
         var context = aWindow._sheetContext;
-    
+
         if (context != nil && context["sheet"] === sheet)
         {
-            context["returnCode"] = returnCode; 
+            context["returnCode"] = returnCode;
             [aWindow _detachSheetWindow];
             return;
         }
@@ -944,7 +885,7 @@ CPRunContinuesResponse  = -1002;
 {
     if(_fullArgsString !== window.location.hash)
         [self _reloadArguments];
-    
+
     return _args;
 }
 
@@ -954,28 +895,28 @@ CPRunContinuesResponse  = -1002;
     {
         _args = [];
         window.location.hash = @"#";
-        
+
         return;
     }
-    
+
     if([args class] != CPArray)
         args = [CPArray arrayWithObject:args];
-    
+
     _args = args;
-    
+
     var toEncode = [_args copy];
     for(var i=0, count = toEncode.length; i