Changeset 264

Show
Ignore:
Timestamp:
11/18/07 13:42:49 (1 year ago)
Author:
rentzsch
Message:

[NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of the runloop via performSelector:withObject:afterDelay:0.0. The script was firing fine, but the model file wasn't actually there anymore (the script was executing after safe save had saved the model file to /some/tmp/dir and after it deleted the original, but before safe save moved the newly-saved file back to the original file's location).

Also re-architected loading of XDesign plugin based on runtime Xcode version instead of the mere presence of files on-disk. This is preparation of Xcode 3 compatibility where the user can have Xcode 2.5 and 3 installed simultaneously.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cocoa/mogenerator/Xmod/Xmod.h

    r250 r264  
    22#import <objc/objc-class.h> 
    33 
    4 @interface Xmod : NSObject {} 
     4@interface Xmod : NSObject { 
     5        NSBundle *bundle; 
     6
     7+ (id)sharedXmod; 
     8- (id)initWithBundle:(NSBundle*)bundle_; 
    59- (IBAction)autocustomizeEntityClasses:(id)sender_; 
     10- (void)runScriptNamed:(NSString*)scriptName_; 
    611@end 
  • trunk/cocoa/mogenerator/Xmod/Xmod.m

    r263 r264  
    11#import "Xmod.h" 
    22#import "MethodSwizzle.h" 
    3  
    4 NSBundle *selfBundle; 
    5  
    6 static void runScriptNamed(NSString *scriptName) { 
    7         NSString *scriptPath = [selfBundle pathForResource:scriptName ofType:@"scpt" inDirectory:@"Scripts"]; 
    8         NSCAssert1(scriptPath, @"failed to find %@.scpt", scriptName); 
    9         NSDictionary *scriptInitError = nil; 
    10         NSAppleScript *script = [[[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath] 
    11                                                                                                                                         error:&scriptInitError] autorelease]; 
    12         NSCAssert2(!scriptInitError, @"failed to init %@.scpt: %@", scriptName, scriptInitError); 
    13         if (!scriptInitError) { 
    14                 NSDictionary *scriptExecuteError = nil; 
    15                 [script executeAndReturnError:&scriptExecuteError]; 
    16                 NSCAssert2(!scriptInitError, @"failed to execute %@.scpt: %@", scriptName, scriptExecuteError); 
    17         } 
    18 } 
    193 
    204@interface NSObject (xmod_saveModelToFile) 
     
    237- (BOOL)xmod_saveModelToFile:(NSString*)modelPackagePath_ { 
    248        BOOL result = [self xmod_saveModelToFile:modelPackagePath_]; 
    25         if (result) { 
    26                 runScriptNamed(@"Xmod"); 
    27         } 
     9        if (result) 
     10                [[Xmod sharedXmod] performSelector:@selector(runScriptNamed:) withObject:@"Xmod" afterDelay:0.0]; 
    2811        return result; 
    2912} 
     
    3215@implementation Xmod 
    3316 
     17Xmod *gSharedXmod; 
     18 
    3419+ (void)pluginDidLoad:(NSBundle*)bundle_ { 
    35         selfBundle = bundle_; 
    36         [[self alloc] init]; 
     20        gSharedXmod = [[self alloc] initWithBundle:bundle_]; 
     21
     22 
     23+ (id)sharedXmod { 
     24        return gSharedXmod; 
     25
     26 
     27- (id)initWithBundle:(NSBundle*)bundle_ { 
     28        self = [super init]; 
     29        if (self) { 
     30                bundle = [bundle_ retain]; 
     31                [[NSNotificationCenter defaultCenter] addObserver:self 
     32                                                                                                 selector:@selector(applicationDidFinishLaunching:) 
     33                                                                                                         name:NSApplicationDidFinishLaunchingNotification 
     34                                                                                                   object:nil]; 
     35        } 
     36        return self; 
     37
     38 
     39- (void)applicationDidFinishLaunching:(NSNotification*)notification_ { 
     40        //      Force loading of the Core Data XDesign plugin so we can find the class to swizzle its instance method. 
     41        NSBundle *coreDataPlugin = nil; 
    3742         
    38         //      Force loading of the Core Data XDesign plugin so we can find the class to swizzle its instance method. 
    39 #define Xcode24_XDCoreDataModelPlugin @"/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin" 
    40 #define Xcode25_XDCoreDataModelPlugin @"/Xcode2.5/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin" 
    41          
    42         NSBundle *coreDataPlugin = nil; 
    43         if ([[NSFileManager defaultManager] fileExistsAtPath:Xcode25_XDCoreDataModelPlugin]) { 
    44                 coreDataPlugin = [NSBundle bundleWithPath:Xcode25_XDCoreDataModelPlugin]; 
     43        NSString *xcodeVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; 
     44        NSAssert(xcodeVersion, @"failed to read Xcode version"); 
     45        if ([xcodeVersion isEqualToString:@"2.4"]) { 
     46                coreDataPlugin = [NSBundle bundleWithPath:@"/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin"]; 
     47        } else if ([xcodeVersion isEqualToString:@"2.5"]) { 
     48                coreDataPlugin = [NSBundle bundleWithPath:@"/Xcode2.5/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin"]; 
    4549        } else { 
    46                 coreDataPlugin = [NSBundle bundleWithPath:Xcode24_XDCoreDataModelPlugin]; 
    47         }        
     50                //      Unknown territory, exit. 
     51                return; 
     52        } 
    4853        NSAssert(coreDataPlugin, @"failed to load XDCoreDataModel.xdplugin"); 
    4954        [coreDataPlugin load]; 
     
    5661                                                                  @selector(xmod_saveModelToFile:)); 
    5762        NSAssert(swizzled, @"failed to swizzle -[XDPersistenceDocumentController saveModelToFile:]"); 
    58 
    59  
    60 - (id)init { 
    61         self = [super init]; 
    62         if (self) { 
    63                 [[NSNotificationCenter defaultCenter] addObserver:self 
    64                                                                                                  selector:@selector(applicationDidFinishLaunching:) 
    65                                                                                                          name:NSApplicationDidFinishLaunchingNotification 
    66                                                                                                    object:nil]; 
    67         } 
    68         return self; 
    69 
    70  
    71 - (void)applicationDidFinishLaunching:(NSNotification*)notification_ { 
     63         
     64        //      Install the Autocustomize menu item. 
    7265        NSMenu *designMenu = [[[NSApp mainMenu] itemWithTitle:@"Design"] submenu]; 
    7366        NSMenu *dataModelMenu = [[designMenu itemWithTitle:@"Data Model"] submenu]; 
     
    8174 
    8275- (IBAction)autocustomizeEntityClasses:(id)sender_ { 
    83         runScriptNamed(@"Autocustomize Entity Classes"); 
     76        [self runScriptNamed:@"Autocustomize Entity Classes"]; 
     77
     78 
     79- (void)runScriptNamed:(NSString*)scriptName_ { 
     80        NSString *scriptPath = [bundle pathForResource:scriptName_ ofType:@"scpt" inDirectory:@"Scripts"]; 
     81        NSAssert1(scriptPath, @"failed to find %@.scpt", scriptName_); 
     82        NSDictionary *scriptInitError = nil; 
     83        NSAppleScript *script = [[[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath] 
     84                                                                                                                                        error:&scriptInitError] autorelease]; 
     85        NSAssert2(!scriptInitError, @"failed to init %@.scpt: %@", scriptName_, scriptInitError); 
     86        if (!scriptInitError) { 
     87                NSDictionary *scriptExecuteError = nil; 
     88                [script executeAndReturnError:&scriptExecuteError]; 
     89                NSAssert2(!scriptInitError, @"failed to execute %@.scpt: %@", scriptName_, scriptExecuteError); 
     90        } 
    8491} 
    8592 
  • trunk/cocoa/mogenerator/Xmod/Xmod.xcodeproj/wolf.mode1

    r250 r264  
    11<?xml version="1.0" encoding="UTF-8"?> 
    2 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
     2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
    33<plist version="1.0"> 
    44<dict> 
     
    186186        <array/> 
    187187        <key>OpenEditors</key> 
    188         <array/> 
     188        <array> 
     189                <dict> 
     190                        <key>Content</key> 
     191                        <dict> 
     192                                <key>PBXProjectModuleGUID</key> 
     193                                <string>7907BA1F0CED0E23003A8BA0</string> 
     194                                <key>PBXProjectModuleLabel</key> 
     195                                <string>Xmod.m</string> 
     196                                <key>PBXSplitModuleInNavigatorKey</key> 
     197                                <dict> 
     198                                        <key>Split0</key> 
     199                                        <dict> 
     200                                                <key>PBXProjectModuleGUID</key> 
     201                                                <string>7907BA200CED0E23003A8BA0</string> 
     202                                                <key>PBXProjectModuleLabel</key> 
     203                                                <string>Xmod.m</string> 
     204                                                <key>_historyCapacity</key> 
     205                                                <integer>0</integer> 
     206                                                <key>bookmark</key> 
     207                                                <string>794C2E670CF0CA330003EC27</string> 
     208                                                <key>history</key> 
     209                                                <array> 
     210                                                        <string>79A7D2BE0CF0C56F00193A80</string> 
     211                                                </array> 
     212                                        </dict> 
     213                                        <key>SplitCount</key> 
     214                                        <string>1</string> 
     215                                </dict> 
     216                                <key>StatusBarVisibility</key> 
     217                                <true/> 
     218                        </dict> 
     219                        <key>Geometry</key> 
     220                        <dict> 
     221                                <key>Frame</key> 
     222                                <string>{{0, 20}, {921, 831}}</string> 
     223                                <key>PBXModuleWindowStatusBarHidden2</key> 
     224                                <false/> 
     225                                <key>RubberWindowFrame</key> 
     226                                <string>396 144 921 872 0 0 1680 1028 </string> 
     227                        </dict> 
     228                </dict> 
     229                <dict> 
     230                        <key>Content</key> 
     231                        <dict> 
     232                                <key>PBXProjectModuleGUID</key> 
     233                                <string>798EFBDB0CF0B4980090D926</string> 
     234                                <key>PBXProjectModuleLabel</key> 
     235                                <string>Xmod.h</string> 
     236                                <key>PBXSplitModuleInNavigatorKey</key> 
     237                                <dict> 
     238                                        <key>Split0</key> 
     239                                        <dict> 
     240                                                <key>PBXProjectModuleGUID</key> 
     241                                                <string>798EFBDC0CF0B4980090D926</string> 
     242                                                <key>PBXProjectModuleLabel</key> 
     243                                                <string>Xmod.h</string> 
     244                                                <key>_historyCapacity</key> 
     245                                                <integer>0</integer> 
     246                                                <key>bookmark</key> 
     247                                                <string>794C2E680CF0CA330003EC27</string> 
     248                                                <key>history</key> 
     249                                                <array> 
     250                                                        <string>794C2E520CF0CA070003EC27</string> 
     251                                                </array> 
     252                                        </dict> 
     253                                        <key>SplitCount</key> 
     254                                        <string>1</string> 
     255                                </dict> 
     256                                <key>StatusBarVisibility</key> 
     257                                <true/> 
     258                        </dict> 
     259                        <key>Geometry</key> 
     260                        <dict> 
     261                                <key>Frame</key> 
     262                                <string>{{0, 20}, {743, 597}}</string> 
     263                                <key>PBXModuleWindowStatusBarHidden2</key> 
     264                                <false/> 
     265                                <key>RubberWindowFrame</key> 
     266                                <string>896 377 743 638 0 0 1680 1028 </string> 
     267                        </dict> 
     268                </dict> 
     269        </array> 
    189270        <key>PerspectiveWidths</key> 
    190271        <array> 
     
    199280                                <string>active-target-popup</string> 
    200281                                <string>active-buildstyle-popup</string> 
     282                                <string>action</string> 
    201283                                <string>NSToolbarFlexibleSpaceItem</string> 
    202284                                <string>buildOrClean</string> 
     
    259341                                                                <string>08FB77AFFE84173DC02AAC07</string> 
    260342                                                                <string>089C167CFE841241C02AAC07</string> 
     343                                                                <string>19C28FB8FE9D52D311CA2CBB</string> 
    261344                                                                <string>1C37FBAC04509CD000000102</string> 
    262345                                                                <string>1C37FABC05509CD000000102</string> 
     
    265348                                                        <array> 
    266349                                                                <array> 
    267                                                                         <integer>11</integer> 
    268                                                                         <integer>7</integer> 
     350                                                                        <integer>14</integer> 
     351                                                                        <integer>13</integer> 
    269352                                                                        <integer>0</integer> 
    270353                                                                </array> 
     
    290373                                                </array> 
    291374                                                <key>RubberWindowFrame</key> 
    292                                                 <string>1107 1061 853 471 0 0 2560 1578 </string> 
     375                                                <string>536 535 853 471 0 0 1680 1028 </string> 
    293376                                        </dict> 
    294377                                        <key>Module</key> 
     
    327410                                                                <string>{{0, 0}, {645, 0}}</string> 
    328411                                                                <key>RubberWindowFrame</key> 
    329                                                                 <string>1107 1061 853 471 0 0 2560 1578 </string> 
     412                                                                <string>536 535 853 471 0 0 1680 1028 </string> 
    330413                                                        </dict> 
    331414                                                        <key>Module</key> 
     
    347430                                                                <string>{{0, 5}, {645, 425}}</string> 
    348431                                                                <key>RubberWindowFrame</key> 
    349                                                                 <string>1107 1061 853 471 0 0 2560 1578 </string> 
     432                                                                <string>536 535 853 471 0 0 1680 1028 </string> 
    350433                                                        </dict> 
    351434                                                        <key>Module</key> 
     
    371454                        <key>TableOfContents</key> 
    372455                        <array> 
    373                                 <string>7988A27E0C8FF1B00098F17A</string> 
     456                                <string>794C2E4B0CF0C61A0003EC27</string> 
    374457                                <string>1CE0B1FE06471DED0097A5F4</string> 
    375                                 <string>7988A27F0C8FF1B00098F17A</string> 
     458                                <string>794C2E4C0CF0C61A0003EC27</string> 
    376459                                <string>1CE0B20306471E060097A5F4</string> 
    377460                                <string>1CE0B20506471E060097A5F4</string> 
     
    508591        <array> 
    509592                <string>79DFC1390B59BFE80056C80E</string> 
     593                <string>798EFBDB0CF0B4980090D926</string> 
     594                <string>7907BA1F0CED0E23003A8BA0</string> 
    510595                <string>/Users/wolf/code/sf/redshed/cocoa/mogenerator/Xmod/Xmod.xcodeproj</string> 
    511596        </array> 
    512597        <key>WindowString</key> 
    513         <string>1107 1061 853 471 0 0 2560 1578 </string> 
     598        <string>536 535 853 471 0 0 1680 1028 </string> 
    514599        <key>WindowTools</key> 
    515600        <array> 
     
    541626                                                                <string>{{0, 0}, {500, 218}}</string> 
    542627                                                                <key>RubberWindowFrame</key> 
    543                                                                 <string>63 1019 500 500 0 0 2560 1578 </string> 
     628                                                                <string>36 501 500 500 0 0 1680 1028 </string> 
    544629                                                        </dict> 
    545630                                                        <key>Module</key> 
     
    565650                                                                <string>{{0, 223}, {500, 236}}</string> 
    566651                                                                <key>RubberWindowFrame</key> 
    567                                                                 <string>63 1019 500 500 0 0 2560 1578 </string> 
     652                                                                <string>36 501 500 500 0 0 1680 1028 </string> 
    568653                                                        </dict> 
    569654                                                        <key>Module</key> 
     
    588673                        <array> 
    589674                                <string>79DFC1390B59BFE80056C80E</string> 
    590                                 <string>7988A2800C8FF1B00098F17A</string> 
     675                                <string>794C2E540CF0CA070003EC27</string> 
    591676                                <string>1CD0528F0623707200166675</string> 
    592677                                <string>XCMainBuildResultsModuleGUID</string> 
     
    595680                        <string>xcode.toolbar.config.build</string> 
    596681                        <key>WindowString</key> 
    597                         <string>63 1019 500 500 0 0 2560 1578 </string> 
     682                        <string>36 501 500 500 0 0 1680 1028 </string> 
    598683                        <key>WindowToolGUID</key> 
    599684                        <string>79DFC1390B59BFE80056C80E</string> 
  • trunk/cocoa/mogenerator/Xmod/Xmod.xcodeproj/wolf.pbxuser

    r250 r264  
    7777                                ); 
    7878                        }; 
    79                         PBXPerProjectTemplateStateSaveDate = 210759999; 
    80                         PBXWorkspaceStateSaveDate = 210759999; 
     79                        PBXPerProjectTemplateStateSaveDate = 217105925; 
     80                        PBXWorkspaceStateSaveDate = 217105925; 
     81                }; 
     82                perUserProjectItems = { 
     83                        794C2E520CF0CA070003EC27 /* PBXTextBookmark */ = 794C2E520CF0CA070003EC27 /* PBXTextBookmark */; 
     84                        794C2E670CF0CA330003EC27 /* PBXTextBookmark */ = 794C2E670CF0CA330003EC27 /* PBXTextBookmark */; 
     85                        794C2E680CF0CA330003EC27 /* PBXTextBookmark */ = 794C2E680CF0CA330003EC27 /* PBXTextBookmark */; 
     86                        79A7D2BE0CF0C56F00193A80 /* PBXTextBookmark */ = 79A7D2BE0CF0C56F00193A80 /* PBXTextBookmark */; 
    8187                }; 
    8288                sourceControlManager = 79DFC1170B59B8870056C80E /* Source Control */; 
    8389                userBuildSettings = { 
    8490                }; 
     91        }; 
     92        794C2E520CF0CA070003EC27 /* PBXTextBookmark */ = { 
     93                isa = PBXTextBookmark; 
     94                fRef = 79DFC11D0B59B8C80056C80E /* Xmod.h */; 
     95                name = "+ (id)sharedXmod;"; 
     96                rLen = 17; 
     97                rLoc = 103; 
     98                rType = 0; 
     99                vrLen = 265; 
     100                vrLoc = 0; 
     101        }; 
     102        794C2E670CF0CA330003EC27 /* PBXTextBookmark */ = { 
     103                isa = PBXTextBookmark; 
     104                fRef = 79DFC11E0B59B8C80056C80E /* Xmod.m */; 
     105                name = "Xmod.m: 1"; 
     106                rLen = 0; 
     107                rLoc = 0; 
     108                rType = 0; 
     109                vrLen = 1983; 
     110                vrLoc = 0; 
     111        }; 
     112        794C2E680CF0CA330003EC27 /* PBXTextBookmark */ = { 
     113                isa = PBXTextBookmark; 
     114                fRef = 79DFC11D0B59B8C80056C80E /* Xmod.h */; 
     115                name = "+ (id)sharedXmod;"; 
     116                rLen = 17; 
     117                rLoc = 103; 
     118                rType = 0; 
     119                vrLen = 265; 
     120                vrLoc = 0; 
     121        }; 
     122        79A7D2BE0CF0C56F00193A80 /* PBXTextBookmark */ = { 
     123                isa = PBXTextBookmark; 
     124                fRef = 79DFC11E0B59B8C80056C80E /* Xmod.m */; 
     125                name = "Xmod.m: 51"; 
     126                rLen = 0; 
     127                rLoc = 1767; 
     128                rType = 0; 
     129                vrLen = 2211; 
     130                vrLoc = 1164; 
    85131        }; 
    86132        79D150FA0C8FBDE9006706AF /* Xmod.applescript */ = { 
     
    106152        79DFC11D0B59B8C80056C80E /* Xmod.h */ = { 
    107153                uiCtxt = { 
    108                         sepNavIntBoundsRect = "{{0, 0}, {1261, 667}}"; 
    109                         sepNavSelRange = "{134, 0}"; 
    110                         sepNavVisRect = "{{0, 0}, {1261, 667}}"; 
    111                         sepNavWindowFrame = "{{751, 476}, {1300, 725}}"; 
     154                        sepNavIntBoundsRect = "{{0, 0}, {704, 565}}"; 
     155                        sepNavSelRange = "{103, 17}"; 
     156                        sepNavVisRect = "{{0, 0}, {704, 565}}"; 
     157                        sepNavWindowFrame = "{{896, 345}, {743, 670}}"; 
    112158                }; 
    113159        }; 
    114160        79DFC11E0B59B8C80056C80E /* Xmod.m */ = { 
    115161                uiCtxt = { 
    116                         sepNavIntBoundsRect = "{{0, 0}, {1186, 1106}}"; 
     162                        sepNavIntBoundsRect = "{{0, 0}, {882, 1316}}"; 
    117163                        sepNavSelRange = "{0, 0}"; 
    118                         sepNavVisRect = "{{0, 0}, {1186, 856}}"; 
    119                         sepNavWindowFrame = "{{1120, 289}, {1225, 914}}"; 
     164                        sepNavVisRect = "{{0, 0}, {882, 799}}"; 
     165                        sepNavWindowFrame = "{{396, 112}, {921, 904}}"; 
    120166                }; 
    121167        };