Changeset 19995

Show
Ignore:
Timestamp:
04/22/07 16:07:57 (2 years ago)
Author:
patrick
Message:

Added the ability for users to change the NSApplication delegate class by
modifying vrjuggler.plist in the application bundle. I came up with the idea
for this while thinking about the documentation for VR Juggler applications
that want to interact with Cocoa. Originally, my plan was for users to
disable the use of vrj::CocoaWrapper? in the kernel and use their own bridging
code instead, but the work done by vrj::CocoaWrapper? is so simple, and it
really shouldn't be done any other way. The much more interesting aspect is
being able to change the NSApplication delegate since that is what gets
hooked up to menu events and such. Thanks to the dynamic nature of
Objective-C, it turned out to be not only feasible, but simple to do this.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/vrjuggler/data/bundle/vrjuggler.plist

    r19884 r19995  
    55        <key>VRJConfigHandling</key> 
    66        <false/> 
     7        <key>VRJControllerClass</key> 
     8        <string>VrjMainController</string> 
    79</dict> 
    810</plist> 
  • juggler/trunk/modules/vrjuggler/vrj/Kernel/CocoaWrapper.mm

    r19992 r19995  
    2929#include <assert.h> 
    3030#include <boost/bind.hpp> 
     31#include <objc/objc-runtime.h> 
    3132 
    3233#import <Foundation/NSValue.h> 
     
    428429   // application:openFile: and application:openFiles: messages. 
    429430   BOOL load_cfg_files = YES; 
     431   NSString* ctrl_class_name = @"VrjMainController"; 
    430432 
    431433   if ( vrj_dict ) 
     
    437439         load_cfg_files = [cfg_handling boolValue]; 
    438440      } 
    439    } 
    440  
    441    VrjMainController* main_controller = 
    442       [[[VrjMainController alloc] init] autorelease]; 
     441 
     442      NSString* name = [vrj_dict objectForKey:@"VRJControllerClass"]; 
     443 
     444      if ( nil != name ) 
     445      { 
     446         ctrl_class_name = name; 
     447      } 
     448   } 
     449 
     450   id controller_class = objc_getClass([ctrl_class_name UTF8String]); 
     451 
     452   if ( nil == controller_class ) 
     453   { 
     454      NSLog(@"WARNING: Could not find declaration of %@!\n", ctrl_class_name); 
     455      NSLog(@"         Falling back on VrjMainController\n"); 
     456      controller_class = [VrjMainController class]; 
     457   } 
     458 
     459   id main_controller = [[[controller_class alloc] init] autorelease]; 
    443460   [main_controller setLoadConfigs:load_cfg_files]; 
    444461