PageRenderTime 26ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/Debug/AppKit/browser.platform/CPApplication.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 479 lines | 478 code | 1 blank | 0 comment | 0 complexity | 7c69ec44b25a9c55745f7d95865cc050 MD5 | raw file
  1I;21;Foundation/CPBundle.ji;17;CPCompatibility.ji;9;CPEvent.ji;8;CPMenu.ji;13;CPResponder.ji;22;CPDocumentController.ji;14;CPThemeBlend.jc;23702;
  2var CPMainCibFile = "CPMainCibFile",
  3    CPMainCibFileHumanFriendly = "Main cib file base name";
  4CPApp = nil;
  5CPApplicationWillFinishLaunchingNotification = "CPApplicationWillFinishLaunchingNotification";
  6CPApplicationDidFinishLaunchingNotification = "CPApplicationDidFinishLaunchingNotification";
  7CPRunStoppedResponse = -1000;
  8CPRunAbortedResponse = -1001;
  9CPRunContinuesResponse = -1002;
 10{var the_class = objj_allocateClassPair(CPResponder, "CPApplication"),
 11meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_eventListeners"), new objj_ivar("_currentEvent"), new objj_ivar("_windows"), new objj_ivar("_keyWindow"), new objj_ivar("_mainWindow"), new objj_ivar("_mainMenu"), new objj_ivar("_documentController"), new objj_ivar("_currentSession"), new objj_ivar("_delegate"), new objj_ivar("_namedArgs"), new objj_ivar("_args"), new objj_ivar("_fullArgsString")]);
 12objj_registerClassPair(the_class);
 13objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 14class_addMethods(the_class, [new objj_method(sel_getUid("init"), function $CPApplication__init(self, _cmd)
 15{ with(self)
 16{
 17    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPResponder") }, "init");
 18    if (self)
 19    {
 20        _eventListeners = [];
 21        _windows = [];
 22        objj_msgSend(_windows, "addObject:", nil);
 23        _mainMenu = objj_msgSend(objj_msgSend(CPMenu, "alloc"), "initWithTitle:", "MainMenu");
 24        objj_msgSend(_mainMenu, "setAutoenablesItems:", NO);
 25        var bundle = objj_msgSend(CPBundle, "bundleForClass:", objj_msgSend(CPApplication, "class")),
 26            newMenuItem = objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "New", sel_getUid("newDocument:"), "N");
 27        objj_msgSend(newMenuItem, "setImage:", objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPApplication/New.png"), CGSizeMake(16.0, 16.0)));
 28        objj_msgSend(newMenuItem, "setAlternateImage:", objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPApplication/NewHighlighted.png"), CGSizeMake(16.0, 16.0)));
 29        objj_msgSend(_mainMenu, "addItem:", newMenuItem);
 30        var openMenuItem = objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Open", sel_getUid("openDocument:"), "O");
 31        objj_msgSend(openMenuItem, "setImage:", objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPApplication/Open.png"), CGSizeMake(16.0, 16.0)));
 32        objj_msgSend(openMenuItem, "setAlternateImage:", objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPApplication/OpenHighlighted.png"), CGSizeMake(16.0, 16.0)));
 33        objj_msgSend(_mainMenu, "addItem:", openMenuItem);
 34        var saveMenu = objj_msgSend(objj_msgSend(CPMenu, "alloc"), "initWithTitle:", "Save"),
 35            saveMenuItem = objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Save", sel_getUid("saveDocument:"), nil);
 36        objj_msgSend(saveMenuItem, "setImage:", objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPApplication/Save.png"), CGSizeMake(16.0, 16.0)));
 37        objj_msgSend(saveMenuItem, "setAlternateImage:", objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPApplication/SaveHighlighted.png"), CGSizeMake(16.0, 16.0)));
 38        objj_msgSend(saveMenu, "addItem:", objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Save", sel_getUid("saveDocument:"), "S"));
 39        objj_msgSend(saveMenu, "addItem:", objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Save As", sel_getUid("saveDocumentAs:"), nil));
 40        objj_msgSend(saveMenuItem, "setSubmenu:", saveMenu);
 41        objj_msgSend(_mainMenu, "addItem:", saveMenuItem);
 42        var editMenuItem = objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Edit", nil, nil),
 43            editMenu = objj_msgSend(objj_msgSend(CPMenu, "alloc"), "initWithTitle:", "Edit"),
 44            undoMenuItem = objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Undo", sel_getUid("undo:"), CPUndoKeyEquivalent),
 45            redoMenuItem = objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Redo", sel_getUid("redo:"), CPRedoKeyEquivalent);
 46        objj_msgSend(undoMenuItem, "setKeyEquivalentModifierMask:", CPUndoKeyEquivalentModifierMask);
 47        objj_msgSend(redoMenuItem, "setKeyEquivalentModifierMask:", CPRedoKeyEquivalentModifierMask);
 48        objj_msgSend(editMenu, "addItem:", undoMenuItem);
 49        objj_msgSend(editMenu, "addItem:", redoMenuItem);
 50        objj_msgSend(editMenu, "addItem:", objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Cut", sel_getUid("cut:"), "X")),
 51        objj_msgSend(editMenu, "addItem:", objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Copy", sel_getUid("copy:"), "C")),
 52        objj_msgSend(editMenu, "addItem:", objj_msgSend(objj_msgSend(CPMenuItem, "alloc"), "initWithTitle:action:keyEquivalent:", "Paste", sel_getUid("paste:"), "V"));
 53        objj_msgSend(editMenuItem, "setSubmenu:", editMenu);
 54        objj_msgSend(editMenuItem, "setHidden:", YES);
 55        objj_msgSend(_mainMenu, "addItem:", editMenuItem);
 56        objj_msgSend(_mainMenu, "addItem:", objj_msgSend(CPMenuItem, "separatorItem"));
 57    }
 58    return self;
 59}
 60}), new objj_method(sel_getUid("setDelegate:"), function $CPApplication__setDelegate_(self, _cmd, aDelegate)
 61{ with(self)
 62{
 63    if (_delegate == aDelegate)
 64        return;
 65    var defaultCenter = objj_msgSend(CPNotificationCenter, "defaultCenter");
 66    if (_delegate)
 67    {
 68        objj_msgSend(defaultCenter, "removeObserver:name:object:", _delegate, CPApplicationWillFinishLaunchingNotification, self);
 69        objj_msgSend(defaultCenter, "removeObserver:name:object:", _delegate, CPApplicationDidFinishLaunchingNotification, self);
 70    }
 71    _delegate = aDelegate;
 72    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("applicationWillFinishLaunching:")))
 73        objj_msgSend(defaultCenter, "addObserver:selector:name:object:", _delegate, sel_getUid("applicationWillFinishLaunching:"), CPApplicationWillFinishLaunchingNotification, self);
 74    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("applicationDidFinishLaunching:")))
 75        objj_msgSend(defaultCenter, "addObserver:selector:name:object:", _delegate, sel_getUid("applicationDidFinishLaunching:"), CPApplicationDidFinishLaunchingNotification, self);
 76}
 77}), new objj_method(sel_getUid("delegate"), function $CPApplication__delegate(self, _cmd)
 78{ with(self)
 79{
 80    return _delegate;
 81}
 82}), new objj_method(sel_getUid("finishLaunching"), function $CPApplication__finishLaunching(self, _cmd)
 83{ with(self)
 84{
 85    var bundle = objj_msgSend(CPBundle, "mainBundle"),
 86        types = objj_msgSend(bundle, "objectForInfoDictionaryKey:", "CPBundleDocumentTypes");
 87    if (objj_msgSend(types, "count") > 0)
 88        _documentController = objj_msgSend(CPDocumentController, "sharedDocumentController");
 89    var delegateClassName = objj_msgSend(bundle, "objectForInfoDictionaryKey:", "CPApplicationDelegateClass");
 90    if (delegateClassName)
 91    {
 92        var delegateClass = objj_getClass(delegateClassName);
 93        if (delegateClass)
 94            if (objj_msgSend(_documentController, "class") == delegateClass)
 95                objj_msgSend(self, "setDelegate:", _documentController);
 96            else
 97                objj_msgSend(self, "setDelegate:", objj_msgSend(objj_msgSend(delegateClass, "alloc"), "init"));
 98    }
 99    var defaultCenter = objj_msgSend(CPNotificationCenter, "defaultCenter");
100    objj_msgSend(defaultCenter, "postNotificationName:object:", CPApplicationWillFinishLaunchingNotification, self);
101    if (_documentController)
102        objj_msgSend(_documentController, "newDocument:", self);
103    objj_msgSend(defaultCenter, "postNotificationName:object:", CPApplicationDidFinishLaunchingNotification, self);
104    objj_msgSend(objj_msgSend(CPRunLoop, "currentRunLoop"), "limitDateForMode:", CPDefaultRunLoopMode);
105}
106}), new objj_method(sel_getUid("run"), function $CPApplication__run(self, _cmd)
107{ with(self)
108{
109    objj_msgSend(self, "finishLaunching");
110}
111}), new objj_method(sel_getUid("runModalForWindow:"), function $CPApplication__runModalForWindow_(self, _cmd, aWindow)
112{ with(self)
113{
114    objj_msgSend(self, "runModalSession:", objj_msgSend(self, "beginModalSessionForWindow:", aWindow));
115}
116}), new objj_method(sel_getUid("stopModalWithCode:"), function $CPApplication__stopModalWithCode_(self, _cmd, aCode)
117{ with(self)
118{
119    if (!_currentSession)
120    {
121        return;
122    }
123    _currentSession._state = aCode;
124    _currentSession = _currentSession._previous;
125        objj_msgSend(self, "_removeRunModalLoop");
126}
127}), new objj_method(sel_getUid("_removeRunModalLoop"), function $CPApplication___removeRunModalLoop(self, _cmd)
128{ with(self)
129{
130    var count = _eventListeners.length;
131    while (count--)
132        if (_eventListeners[count]._callback === _CPRunModalLoop)
133        {
134            _eventListeners.splice(count, 1);
135            return;
136        }
137}
138}), new objj_method(sel_getUid("stopModal"), function $CPApplication__stopModal(self, _cmd)
139{ with(self)
140{
141    objj_msgSend(self, "stopModalWithCode:", CPRunStoppedResponse)
142}
143}), new objj_method(sel_getUid("abortModal"), function $CPApplication__abortModal(self, _cmd)
144{ with(self)
145{
146    objj_msgSend(self, "stopModalWithCode:", CPRunAbortedResponse);
147}
148}), new objj_method(sel_getUid("beginModalSessionForWindow:"), function $CPApplication__beginModalSessionForWindow_(self, _cmd, aWindow)
149{ with(self)
150{
151    return _CPModalSessionMake(aWindow, 0);
152}
153}), new objj_method(sel_getUid("runModalSession:"), function $CPApplication__runModalSession_(self, _cmd, aModalSession)
154{ with(self)
155{
156    aModalSession._previous = _currentSession;
157    _currentSession = aModalSession;
158    var theWindow = aModalSession._window;
159    objj_msgSend(theWindow, "center");
160    objj_msgSend(theWindow, "makeKeyAndOrderFront:", self);
161    objj_msgSend(CPApp, "setCallback:forNextEventMatchingMask:untilDate:inMode:dequeue:", _CPRunModalLoop, CPAnyEventMask, nil, 0, NO);
162}
163}), new objj_method(sel_getUid("modalWindow"), function $CPApplication__modalWindow(self, _cmd)
164{ with(self)
165{
166    if (!_currentSession)
167        return nil;
168    return _currentSession._window;
169}
170}), new objj_method(sel_getUid("_handleKeyEquivalent:"), function $CPApplication___handleKeyEquivalent_(self, _cmd, anEvent)
171{ with(self)
172{
173    if (objj_msgSend(_mainMenu, "performKeyEquivalent:", anEvent))
174        return YES;
175    return NO;
176}
177}), new objj_method(sel_getUid("sendEvent:"), function $CPApplication__sendEvent_(self, _cmd, anEvent)
178{ with(self)
179{
180    if (objj_msgSend(anEvent, "type") == CPKeyDown &&
181        objj_msgSend(anEvent, "modifierFlags") & (CPCommandKeyMask | CPControlKeyMask) &&
182        objj_msgSend(objj_msgSend(anEvent, "characters"), "length") > 0 &&
183        objj_msgSend(self, "_handleKeyEquivalent:", anEvent))
184        return;
185    if (_eventListeners.length)
186    {
187        if (_eventListeners[_eventListeners.length - 1]._mask & (1 << objj_msgSend(anEvent, "type")))
188            _eventListeners.pop()._callback(anEvent);
189        return;
190    }
191    objj_msgSend(objj_msgSend(anEvent, "window"), "sendEvent:", anEvent);
192}
193}), new objj_method(sel_getUid("doCommandBySelector:"), function $CPApplication__doCommandBySelector_(self, _cmd, aSelector)
194{ with(self)
195{
196    if (objj_msgSend(_delegate, "respondsToSelector:", aSelector))
197        objj_msgSend(_delegate, "performSelector:", aSelector);
198    else
199        objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPResponder") }, "doCommandBySelector:", aSelector);
200}
201}), new objj_method(sel_getUid("keyWindow"), function $CPApplication__keyWindow(self, _cmd)
202{ with(self)
203{
204    return _keyWindow;
205}
206}), new objj_method(sel_getUid("mainWindow"), function $CPApplication__mainWindow(self, _cmd)
207{ with(self)
208{
209    return _mainWindow;
210}
211}), new objj_method(sel_getUid("windowWithWindowNumber:"), function $CPApplication__windowWithWindowNumber_(self, _cmd, aWindowNumber)
212{ with(self)
213{
214    return _windows[aWindowNumber];
215}
216}), new objj_method(sel_getUid("windows"), function $CPApplication__windows(self, _cmd)
217{ with(self)
218{
219    return _windows;
220}
221}), new objj_method(sel_getUid("mainMenu"), function $CPApplication__mainMenu(self, _cmd)
222{ with(self)
223{
224    return _mainMenu;
225}
226}), new objj_method(sel_getUid("setMainMenu:"), function $CPApplication__setMainMenu_(self, _cmd, aMenu)
227{ with(self)
228{
229    _mainMenu = aMenu;
230}
231}), new objj_method(sel_getUid("orderFrontStandardAboutPanel:"), function $CPApplication__orderFrontStandardAboutPanel_(self, _cmd, aSender)
232{ with(self)
233{
234    objj_msgSend(self, "orderFrontStandardAboutPanelWithOptions:", nil);
235}
236}), new objj_method(sel_getUid("orderFrontStandardAboutPanelWithOptions:"), function $CPApplication__orderFrontStandardAboutPanelWithOptions_(self, _cmd, aDictionary)
237{ with(self)
238{
239}
240}), new objj_method(sel_getUid("tryToPerform:with:"), function $CPApplication__tryToPerform_with_(self, _cmd, anAction, anObject)
241{ with(self)
242{
243    if (!anAction)
244        return NO;
245    if (objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPResponder") }, "tryToPerform:with:", anAction, anObject))
246        return YES;
247    if(objj_msgSend(_delegate, "respondsToSelector:", anAction))
248    {
249        objj_msgSend(_delegate, "performSelector:withObject:", anAction, anObject);
250        return YES;
251    }
252    return NO;
253}
254}), new objj_method(sel_getUid("sendAction:to:from:"), function $CPApplication__sendAction_to_from_(self, _cmd, anAction, aTarget, aSender)
255{ with(self)
256{
257    var target = objj_msgSend(self, "targetForAction:to:from:", anAction, aTarget, aSender);
258    if (!target)
259        return NO;
260    objj_msgSend(target, "performSelector:withObject:", anAction, aSender);
261    return YES;
262}
263}), new objj_method(sel_getUid("targetForAction:to:from:"), function $CPApplication__targetForAction_to_from_(self, _cmd, anAction, aTarget, aSender)
264{ with(self)
265{
266    if (!anAction)
267        return nil;
268    if (aTarget)
269        return aTarget;
270    return objj_msgSend(self, "targetForAction:", anAction);
271}
272}), new objj_method(sel_getUid("_targetForWindow:action:"), function $CPApplication___targetForWindow_action_(self, _cmd, aWindow, anAction)
273{ with(self)
274{
275    var responder = objj_msgSend(aWindow, "firstResponder"),
276        checkWindow = YES;
277    while (responder)
278    {
279        if (objj_msgSend(responder, "respondsToSelector:", anAction))
280            return responder;
281        if (responder == aWindow)
282            checkWindow = NO;
283        responder = objj_msgSend(responder, "nextResponder");
284    }
285    if (checkWindow && objj_msgSend(aWindow, "respondsToSelector:", anAction))
286        return aWindow;
287    var delegate = objj_msgSend(aWindow, "delegate");
288    if (objj_msgSend(delegate, "respondsToSelector:", anAction))
289        return delegate;
290    var windowController = objj_msgSend(aWindow, "windowController");
291    if (objj_msgSend(windowController, "respondsToSelector:", anAction))
292        return windowController;
293    var theDocument = objj_msgSend(windowController, "document");
294    if (theDocument != delegate && objj_msgSend(theDocument, "respondsToSelector:", anAction))
295        return theDocument;
296    return nil;
297}
298}), new objj_method(sel_getUid("targetForAction:"), function $CPApplication__targetForAction_(self, _cmd, anAction)
299{ with(self)
300{
301    if (!anAction)
302        return nil;
303    var target = objj_msgSend(self, "_targetForWindow:action:", objj_msgSend(self, "keyWindow"), anAction);
304    if (target)
305        return target;
306    target = objj_msgSend(self, "_targetForWindow:action:", objj_msgSend(self, "mainWindow"), anAction);
307    if (target)
308        return target;
309    if (objj_msgSend(self, "respondsToSelector:", anAction))
310        return self;
311    if (objj_msgSend(_delegate, "respondsToSelector:", anAction))
312        return _delegate;
313    if (objj_msgSend(_documentController, "respondsToSelector:", anAction))
314        return _documentController;
315    return nil;
316}
317}), new objj_method(sel_getUid("setCallback:forNextEventMatchingMask:untilDate:inMode:dequeue:"), function $CPApplication__setCallback_forNextEventMatchingMask_untilDate_inMode_dequeue_(self, _cmd, aCallback, aMask, anExpiration, aMode, shouldDequeue)
318{ with(self)
319{
320    _eventListeners.push(_CPEventListenerMake(aMask, aCallback));
321    if (_eventListeners.length == 3) objj_debug_print_backtrace();
322}
323}), new objj_method(sel_getUid("setTarget:selector:forNextEventMatchingMask:untilDate:inMode:dequeue:"), function $CPApplication__setTarget_selector_forNextEventMatchingMask_untilDate_inMode_dequeue_(self, _cmd, aTarget, aSelector, aMask, anExpiration, aMode, shouldDequeue)
324{ with(self)
325{
326    _eventListeners.push(_CPEventListenerMake(aMask, function (anEvent) { objj_msgSend(aTarget, aSelector, anEvent); }));
327}
328}), new objj_method(sel_getUid("beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:"), function $CPApplication__beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(self, _cmd, aSheet, aWindow, aModalDelegate, aDidEndSelector, aContextInfo)
329{ with(self)
330{
331    objj_msgSend(aWindow, "_attachSheet:modalDelegate:didEndSelector:contextInfo:", aSheet, aModalDelegate, aDidEndSelector, aContextInfo);
332}
333}), new objj_method(sel_getUid("arguments"), function $CPApplication__arguments(self, _cmd)
334{ with(self)
335{
336    if(_fullArgsString != window.location.hash)
337        objj_msgSend(self, "_reloadArguments");
338    return _args;
339}
340}), new objj_method(sel_getUid("setArguments:"), function $CPApplication__setArguments_(self, _cmd, args)
341{ with(self)
342{
343    if(!args || args.length == 0)
344    {
345        _args = [];
346        window.location.hash = "#";
347        return;
348    }
349    if(objj_msgSend(args, "class") != CPArray)
350        args = objj_msgSend(CPArray, "arrayWithObject:", args);
351    _args = args;
352    var toEncode = objj_msgSend(_args, "copy");
353    for(var i=0, count = toEncode.length; i<count; i++)
354        toEncode[i] = encodeURIComponent(toEncode[i]);
355    var hash = objj_msgSend(toEncode, "componentsJoinedByString:", "/");
356    window.location.hash = "#" + hash;
357}
358}), new objj_method(sel_getUid("_reloadArguments"), function $CPApplication___reloadArguments(self, _cmd)
359{ with(self)
360{
361    _fullArgsString = window.location.hash;
362    var args = _fullArgsString.replace("#", "").split("/").slice(0);
363    for(var i=0, count = args.length; i<count; i++)
364        args[i] = decodeURIComponent(args[i]);
365    _args = args;
366}
367}), new objj_method(sel_getUid("namedArguments"), function $CPApplication__namedArguments(self, _cmd)
368{ with(self)
369{
370    return _namedArgs;
371}
372})]);
373class_addMethods(meta_class, [new objj_method(sel_getUid("sharedApplication"), function $CPApplication__sharedApplication(self, _cmd)
374{ with(self)
375{
376    if (!CPApp)
377        CPApp = objj_msgSend(objj_msgSend(CPApplication, "alloc"), "init");
378    return CPApp;
379}
380})]);
381}
382var _CPModalSessionMake = function(aWindow, aStopCode)
383{
384    return { _window:aWindow, _state:CPRunContinuesResponse , _previous:nil };
385}
386var _CPEventListenerMake = function(anEventMask, aCallback)
387{
388    return { _mask:anEventMask, _callback:aCallback };
389}
390var _CPRunModalLoop = function(anEvent)
391{
392    objj_msgSend(CPApp, "setCallback:forNextEventMatchingMask:untilDate:inMode:dequeue:", _CPRunModalLoop, CPAnyEventMask, nil, 0, NO);
393    var theWindow = objj_msgSend(anEvent, "window"),
394        modalSession = CPApp._currentSession;
395    if (theWindow == modalSession._window || objj_msgSend(theWindow, "worksWhenModal"))
396        objj_msgSend(theWindow, "sendEvent:", anEvent);
397}
398CPApplicationMain= function(args, namedArgs)
399{
400    var mainBundle = objj_msgSend(CPBundle, "mainBundle"),
401        principalClass = objj_msgSend(mainBundle, "principalClass");
402    if (!principalClass)
403        principalClass = objj_msgSend(CPApplication, "class");
404    objj_msgSend(principalClass, "sharedApplication");
405    if (!args && !namedArgs)
406    {
407        var args = objj_msgSend(CPApp, "arguments"),
408            searchParams = window.location.search.substring(1).split("&");
409            namedArgs = objj_msgSend(CPDictionary, "dictionary");
410        if(objj_msgSend(args, "containsObject:", "debug"))
411            CPLogRegister(CPLogPopup);
412        for(var i=0; i<searchParams.length; i++)
413        {
414            var index = searchParams[i].indexOf('=');
415            if(index == -1)
416                objj_msgSend(namedArgs, "setObject:forKey:",  "", searchParams[i]);
417            else
418                objj_msgSend(namedArgs, "setObject:forKey:",  searchParams[i].substring(index+1),  searchParams[i].substring(0, index));
419        }
420    }
421    CPApp._args = args;
422    CPApp._namedArgs = namedArgs;
423    objj_msgSend(_CPAppBootstrapper, "performActions");
424}
425var _CPAppBootstrapperActions = nil;
426{var the_class = objj_allocateClassPair(CPObject, "_CPAppBootstrapper"),
427meta_class = the_class.isa;objj_registerClassPair(the_class);
428objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
429class_addMethods(meta_class, [new objj_method(sel_getUid("actions"), function $_CPAppBootstrapper__actions(self, _cmd)
430{ with(self)
431{
432    return [sel_getUid("loadDefaultTheme"), sel_getUid("loadMainCibFile")];
433}
434}), new objj_method(sel_getUid("performActions"), function $_CPAppBootstrapper__performActions(self, _cmd)
435{ with(self)
436{
437    if (!_CPAppBootstrapperActions)
438        _CPAppBootstrapperActions = objj_msgSend(self, "actions");
439    while (_CPAppBootstrapperActions.length)
440    {
441        var action = _CPAppBootstrapperActions.shift();
442        if (objj_msgSend(self, action))
443            return;
444    }
445    objj_msgSend(CPApp, "run");
446}
447}), new objj_method(sel_getUid("loadDefaultTheme"), function $_CPAppBootstrapper__loadDefaultTheme(self, _cmd)
448{ with(self)
449{
450    var blend = objj_msgSend(objj_msgSend(CPThemeBlend, "alloc"), "initWithContentsOfURL:", objj_msgSend(objj_msgSend(CPBundle, "bundleForClass:", objj_msgSend(CPApplication, "class")), "pathForResource:", "Aristo.blend"));
451    objj_msgSend(blend, "loadWithDelegate:", self);
452    return YES;
453}
454}), new objj_method(sel_getUid("blendDidFinishLoading:"), function $_CPAppBootstrapper__blendDidFinishLoading_(self, _cmd, aBundle)
455{ with(self)
456{
457    objj_msgSend(CPTheme, "setDefaultTheme:", objj_msgSend(CPTheme, "themeNamed:", "Aristo"));
458    objj_msgSend(self, "performActions");
459}
460}), new objj_method(sel_getUid("loadMainCibFile"), function $_CPAppBootstrapper__loadMainCibFile(self, _cmd)
461{ with(self)
462{
463    var mainBundle = objj_msgSend(CPBundle, "mainBundle"),
464        mainCibFile = objj_msgSend(mainBundle, "objectForInfoDictionaryKey:", CPMainCibFile) || objj_msgSend(mainBundle, "objectForInfoDictionaryKey:", CPMainCibFileHumanFriendly);
465    if (mainCibFile)
466    {
467        objj_msgSend(CPBundle, "loadCibFile:externalNameTable:loadDelegate:", objj_msgSend(mainBundle, "pathForResource:", mainCibFile), objj_msgSend(CPDictionary, "dictionaryWithObject:forKey:", CPApp, CPCibOwner), self);
468        return YES;
469    }
470    return NO;
471}
472}), new objj_method(sel_getUid("cibDidFinishLoading:"), function $_CPAppBootstrapper__cibDidFinishLoading_(self, _cmd, aCib)
473{ with(self)
474{
475    objj_msgSend(self, "performActions");
476}
477})]);
478}
479