Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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.
  • Loading branch information...
commit 34845a3ec0f443dc07daa2384dd213609f26cb99 1 parent 0a69057
@rentzsch authored
View
7 Xmod/Xmod.h
@@ -1,6 +1,11 @@
#import <Cocoa/Cocoa.h>
#import <objc/objc-class.h>
-@interface Xmod : NSObject {}
+@interface Xmod : NSObject {
+ NSBundle *bundle;
+}
++ (id)sharedXmod;
+- (id)initWithBundle:(NSBundle*)bundle_;
- (IBAction)autocustomizeEntityClasses:(id)sender_;
+- (void)runScriptNamed:(NSString*)scriptName_;
@end
View
95 Xmod/Xmod.m
@@ -1,65 +1,33 @@
#import "Xmod.h"
#import "MethodSwizzle.h"
-NSBundle *selfBundle;
-
-static void runScriptNamed(NSString *scriptName) {
- NSString *scriptPath = [selfBundle pathForResource:scriptName ofType:@"scpt" inDirectory:@"Scripts"];
- NSCAssert1(scriptPath, @"failed to find %@.scpt", scriptName);
- NSDictionary *scriptInitError = nil;
- NSAppleScript *script = [[[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath]
- error:&scriptInitError] autorelease];
- NSCAssert2(!scriptInitError, @"failed to init %@.scpt: %@", scriptName, scriptInitError);
- if (!scriptInitError) {
- NSDictionary *scriptExecuteError = nil;
- [script executeAndReturnError:&scriptExecuteError];
- NSCAssert2(!scriptInitError, @"failed to execute %@.scpt: %@", scriptName, scriptExecuteError);
- }
-}
-
@interface NSObject (xmod_saveModelToFile)
@end
@implementation NSObject (xmod_saveModelToFile)
- (BOOL)xmod_saveModelToFile:(NSString*)modelPackagePath_ {
BOOL result = [self xmod_saveModelToFile:modelPackagePath_];
- if (result) {
- runScriptNamed(@"Xmod");
- }
+ if (result)
+ [[Xmod sharedXmod] performSelector:@selector(runScriptNamed:) withObject:@"Xmod" afterDelay:0.0];
return result;
}
@end
@implementation Xmod
+Xmod *gSharedXmod;
+
+ (void)pluginDidLoad:(NSBundle*)bundle_ {
- selfBundle = bundle_;
- [[self alloc] init];
-
- // Force loading of the Core Data XDesign plugin so we can find the class to swizzle its instance method.
-#define Xcode24_XDCoreDataModelPlugin @"/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin"
-#define Xcode25_XDCoreDataModelPlugin @"/Xcode2.5/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin"
-
- NSBundle *coreDataPlugin = nil;
- if ([[NSFileManager defaultManager] fileExistsAtPath:Xcode25_XDCoreDataModelPlugin]) {
- coreDataPlugin = [NSBundle bundleWithPath:Xcode25_XDCoreDataModelPlugin];
- } else {
- coreDataPlugin = [NSBundle bundleWithPath:Xcode24_XDCoreDataModelPlugin];
- }
- NSAssert(coreDataPlugin, @"failed to load XDCoreDataModel.xdplugin");
- [coreDataPlugin load];
-
- Class persistenceDocumentController = NSClassFromString(@"XDPersistenceDocumentController");
- NSAssert(persistenceDocumentController, @"failed to load XDPersistenceDocumentController");
-
- BOOL swizzled = MethodSwizzle(persistenceDocumentController,
- @selector(saveModelToFile:),
- @selector(xmod_saveModelToFile:));
- NSAssert(swizzled, @"failed to swizzle -[XDPersistenceDocumentController saveModelToFile:]");
+ gSharedXmod = [[self alloc] initWithBundle:bundle_];
}
-- (id)init {
++ (id)sharedXmod {
+ return gSharedXmod;
+}
+
+- (id)initWithBundle:(NSBundle*)bundle_ {
self = [super init];
if (self) {
+ bundle = [bundle_ retain];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidFinishLaunching:)
name:NSApplicationDidFinishLaunchingNotification
@@ -69,6 +37,31 @@ - (id)init {
}
- (void)applicationDidFinishLaunching:(NSNotification*)notification_ {
+ // Force loading of the Core Data XDesign plugin so we can find the class to swizzle its instance method.
+ NSBundle *coreDataPlugin = nil;
+
+ NSString *xcodeVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
+ NSAssert(xcodeVersion, @"failed to read Xcode version");
+ if ([xcodeVersion isEqualToString:@"2.4"]) {
+ coreDataPlugin = [NSBundle bundleWithPath:@"/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin"];
+ } else if ([xcodeVersion isEqualToString:@"2.5"]) {
+ coreDataPlugin = [NSBundle bundleWithPath:@"/Xcode2.5/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin"];
+ } else {
+ // Unknown territory, exit.
+ return;
+ }
+ NSAssert(coreDataPlugin, @"failed to load XDCoreDataModel.xdplugin");
+ [coreDataPlugin load];
+
+ Class persistenceDocumentController = NSClassFromString(@"XDPersistenceDocumentController");
+ NSAssert(persistenceDocumentController, @"failed to load XDPersistenceDocumentController");
+
+ BOOL swizzled = MethodSwizzle(persistenceDocumentController,
+ @selector(saveModelToFile:),
+ @selector(xmod_saveModelToFile:));
+ NSAssert(swizzled, @"failed to swizzle -[XDPersistenceDocumentController saveModelToFile:]");
+
+ // Install the Autocustomize menu item.
NSMenu *designMenu = [[[NSApp mainMenu] itemWithTitle:@"Design"] submenu];
NSMenu *dataModelMenu = [[designMenu itemWithTitle:@"Data Model"] submenu];
@@ -80,7 +73,21 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification_ {
}
- (IBAction)autocustomizeEntityClasses:(id)sender_ {
- runScriptNamed(@"Autocustomize Entity Classes");
+ [self runScriptNamed:@"Autocustomize Entity Classes"];
+}
+
+- (void)runScriptNamed:(NSString*)scriptName_ {
+ NSString *scriptPath = [bundle pathForResource:scriptName_ ofType:@"scpt" inDirectory:@"Scripts"];
+ NSAssert1(scriptPath, @"failed to find %@.scpt", scriptName_);
+ NSDictionary *scriptInitError = nil;
+ NSAppleScript *script = [[[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath]
+ error:&scriptInitError] autorelease];
+ NSAssert2(!scriptInitError, @"failed to init %@.scpt: %@", scriptName_, scriptInitError);
+ if (!scriptInitError) {
+ NSDictionary *scriptExecuteError = nil;
+ [script executeAndReturnError:&scriptExecuteError];
+ NSAssert2(!scriptInitError, @"failed to execute %@.scpt: %@", scriptName_, scriptExecuteError);
+ }
}
@end
View
113 Xmod/Xmod.xcodeproj/wolf.mode1
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ActivePerspectiveName</key>
@@ -185,7 +185,88 @@
<key>Notifications</key>
<array/>
<key>OpenEditors</key>
- <array/>
+ <array>
+ <dict>
+ <key>Content</key>
+ <dict>
+ <key>PBXProjectModuleGUID</key>
+ <string>7907BA1F0CED0E23003A8BA0</string>
+ <key>PBXProjectModuleLabel</key>
+ <string>Xmod.m</string>
+ <key>PBXSplitModuleInNavigatorKey</key>
+ <dict>
+ <key>Split0</key>
+ <dict>
+ <key>PBXProjectModuleGUID</key>
+ <string>7907BA200CED0E23003A8BA0</string>
+ <key>PBXProjectModuleLabel</key>
+ <string>Xmod.m</string>
+ <key>_historyCapacity</key>
+ <integer>0</integer>
+ <key>bookmark</key>
+ <string>794C2E670CF0CA330003EC27</string>
+ <key>history</key>
+ <array>
+ <string>79A7D2BE0CF0C56F00193A80</string>
+ </array>
+ </dict>
+ <key>SplitCount</key>
+ <string>1</string>
+ </dict>
+ <key>StatusBarVisibility</key>
+ <true/>
+ </dict>
+ <key>Geometry</key>
+ <dict>
+ <key>Frame</key>
+ <string>{{0, 20}, {921, 831}}</string>
+ <key>PBXModuleWindowStatusBarHidden2</key>
+ <false/>
+ <key>RubberWindowFrame</key>
+ <string>396 144 921 872 0 0 1680 1028 </string>
+ </dict>
+ </dict>
+ <dict>
+ <key>Content</key>
+ <dict>
+ <key>PBXProjectModuleGUID</key>
+ <string>798EFBDB0CF0B4980090D926</string>
+ <key>PBXProjectModuleLabel</key>
+ <string>Xmod.h</string>
+ <key>PBXSplitModuleInNavigatorKey</key>
+ <dict>
+ <key>Split0</key>
+ <dict>
+ <key>PBXProjectModuleGUID</key>
+ <string>798EFBDC0CF0B4980090D926</string>
+ <key>PBXProjectModuleLabel</key>
+ <string>Xmod.h</string>
+ <key>_historyCapacity</key>
+ <integer>0</integer>
+ <key>bookmark</key>
+ <string>794C2E680CF0CA330003EC27</string>
+ <key>history</key>
+ <array>
+ <string>794C2E520CF0CA070003EC27</string>
+ </array>
+ </dict>
+ <key>SplitCount</key>
+ <string>1</string>
+ </dict>
+ <key>StatusBarVisibility</key>
+ <true/>
+ </dict>
+ <key>Geometry</key>
+ <dict>
+ <key>Frame</key>
+ <string>{{0, 20}, {743, 597}}</string>
+ <key>PBXModuleWindowStatusBarHidden2</key>
+ <false/>
+ <key>RubberWindowFrame</key>
+ <string>896 377 743 638 0 0 1680 1028 </string>
+ </dict>
+ </dict>
+ </array>
<key>PerspectiveWidths</key>
<array>
<integer>-1</integer>
@@ -198,6 +279,7 @@
<array>
<string>active-target-popup</string>
<string>active-buildstyle-popup</string>
+ <string>action</string>
<string>NSToolbarFlexibleSpaceItem</string>
<string>buildOrClean</string>
<string>build-and-runOrDebug</string>
@@ -258,14 +340,15 @@
<string>089C166AFE841209C02AAC07</string>
<string>08FB77AFFE84173DC02AAC07</string>
<string>089C167CFE841241C02AAC07</string>
+ <string>19C28FB8FE9D52D311CA2CBB</string>
<string>1C37FBAC04509CD000000102</string>
<string>1C37FABC05509CD000000102</string>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
- <integer>11</integer>
- <integer>7</integer>
+ <integer>14</integer>
+ <integer>13</integer>
<integer>0</integer>
</array>
</array>
@@ -289,7 +372,7 @@
<real>186</real>
</array>
<key>RubberWindowFrame</key>
- <string>1107 1061 853 471 0 0 2560 1578 </string>
+ <string>536 535 853 471 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXSmartGroupTreeModule</string>
@@ -326,7 +409,7 @@
<key>Frame</key>
<string>{{0, 0}, {645, 0}}</string>
<key>RubberWindowFrame</key>
- <string>1107 1061 853 471 0 0 2560 1578 </string>
+ <string>536 535 853 471 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
@@ -346,7 +429,7 @@
<key>Frame</key>
<string>{{0, 5}, {645, 425}}</string>
<key>RubberWindowFrame</key>
- <string>1107 1061 853 471 0 0 2560 1578 </string>
+ <string>536 535 853 471 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
@@ -370,9 +453,9 @@
</array>
<key>TableOfContents</key>
<array>
- <string>7988A27E0C8FF1B00098F17A</string>
+ <string>794C2E4B0CF0C61A0003EC27</string>
<string>1CE0B1FE06471DED0097A5F4</string>
- <string>7988A27F0C8FF1B00098F17A</string>
+ <string>794C2E4C0CF0C61A0003EC27</string>
<string>1CE0B20306471E060097A5F4</string>
<string>1CE0B20506471E060097A5F4</string>
</array>
@@ -507,10 +590,12 @@
<key>WindowOrderList</key>
<array>
<string>79DFC1390B59BFE80056C80E</string>
+ <string>798EFBDB0CF0B4980090D926</string>
+ <string>7907BA1F0CED0E23003A8BA0</string>
<string>/Users/wolf/code/sf/redshed/cocoa/mogenerator/Xmod/Xmod.xcodeproj</string>
</array>
<key>WindowString</key>
- <string>1107 1061 853 471 0 0 2560 1578 </string>
+ <string>536 535 853 471 0 0 1680 1028 </string>
<key>WindowTools</key>
<array>
<dict>
@@ -540,7 +625,7 @@
<key>Frame</key>
<string>{{0, 0}, {500, 218}}</string>
<key>RubberWindowFrame</key>
- <string>63 1019 500 500 0 0 2560 1578 </string>
+ <string>36 501 500 500 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
@@ -564,7 +649,7 @@
<key>Frame</key>
<string>{{0, 223}, {500, 236}}</string>
<key>RubberWindowFrame</key>
- <string>63 1019 500 500 0 0 2560 1578 </string>
+ <string>36 501 500 500 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXBuildResultsModule</string>
@@ -587,14 +672,14 @@
<key>TableOfContents</key>
<array>
<string>79DFC1390B59BFE80056C80E</string>
- <string>7988A2800C8FF1B00098F17A</string>
+ <string>794C2E540CF0CA070003EC27</string>
<string>1CD0528F0623707200166675</string>
<string>XCMainBuildResultsModuleGUID</string>
</array>
<key>ToolbarConfiguration</key>
<string>xcode.toolbar.config.build</string>
<key>WindowString</key>
- <string>63 1019 500 500 0 0 2560 1578 </string>
+ <string>36 501 500 500 0 0 1680 1028 </string>
<key>WindowToolGUID</key>
<string>79DFC1390B59BFE80056C80E</string>
<key>WindowToolIsVisible</key>
View
64 Xmod/Xmod.xcodeproj/wolf.pbxuser
@@ -76,13 +76,59 @@
PBXFileDataSource_Warnings_ColumnID,
);
};
- PBXPerProjectTemplateStateSaveDate = 210759999;
- PBXWorkspaceStateSaveDate = 210759999;
+ PBXPerProjectTemplateStateSaveDate = 217105925;
+ PBXWorkspaceStateSaveDate = 217105925;
+ };
+ perUserProjectItems = {
+ 794C2E520CF0CA070003EC27 /* PBXTextBookmark */ = 794C2E520CF0CA070003EC27 /* PBXTextBookmark */;
+ 794C2E670CF0CA330003EC27 /* PBXTextBookmark */ = 794C2E670CF0CA330003EC27 /* PBXTextBookmark */;
+ 794C2E680CF0CA330003EC27 /* PBXTextBookmark */ = 794C2E680CF0CA330003EC27 /* PBXTextBookmark */;
+ 79A7D2BE0CF0C56F00193A80 /* PBXTextBookmark */ = 79A7D2BE0CF0C56F00193A80 /* PBXTextBookmark */;
};
sourceControlManager = 79DFC1170B59B8870056C80E /* Source Control */;
userBuildSettings = {
};
};
+ 794C2E520CF0CA070003EC27 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 79DFC11D0B59B8C80056C80E /* Xmod.h */;
+ name = "+ (id)sharedXmod;";
+ rLen = 17;
+ rLoc = 103;
+ rType = 0;
+ vrLen = 265;
+ vrLoc = 0;
+ };
+ 794C2E670CF0CA330003EC27 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 79DFC11E0B59B8C80056C80E /* Xmod.m */;
+ name = "Xmod.m: 1";
+ rLen = 0;
+ rLoc = 0;
+ rType = 0;
+ vrLen = 1983;
+ vrLoc = 0;
+ };
+ 794C2E680CF0CA330003EC27 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 79DFC11D0B59B8C80056C80E /* Xmod.h */;
+ name = "+ (id)sharedXmod;";
+ rLen = 17;
+ rLoc = 103;
+ rType = 0;
+ vrLen = 265;
+ vrLoc = 0;
+ };
+ 79A7D2BE0CF0C56F00193A80 /* PBXTextBookmark */ = {
+ isa = PBXTextBookmark;
+ fRef = 79DFC11E0B59B8C80056C80E /* Xmod.m */;
+ name = "Xmod.m: 51";
+ rLen = 0;
+ rLoc = 1767;
+ rType = 0;
+ vrLen = 2211;
+ vrLoc = 1164;
+ };
79D150FA0C8FBDE9006706AF /* Xmod.applescript */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {1150, 1240}}";
@@ -105,18 +151,18 @@
};
79DFC11D0B59B8C80056C80E /* Xmod.h */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {1261, 667}}";
- sepNavSelRange = "{134, 0}";
- sepNavVisRect = "{{0, 0}, {1261, 667}}";
- sepNavWindowFrame = "{{751, 476}, {1300, 725}}";
+ sepNavIntBoundsRect = "{{0, 0}, {704, 565}}";
+ sepNavSelRange = "{103, 17}";
+ sepNavVisRect = "{{0, 0}, {704, 565}}";
+ sepNavWindowFrame = "{{896, 345}, {743, 670}}";
};
};
79DFC11E0B59B8C80056C80E /* Xmod.m */ = {
uiCtxt = {
- sepNavIntBoundsRect = "{{0, 0}, {1186, 1106}}";
+ sepNavIntBoundsRect = "{{0, 0}, {882, 1316}}";
sepNavSelRange = "{0, 0}";
- sepNavVisRect = "{{0, 0}, {1186, 856}}";
- sepNavWindowFrame = "{{1120, 289}, {1225, 914}}";
+ sepNavVisRect = "{{0, 0}, {882, 799}}";
+ sepNavWindowFrame = "{{396, 112}, {921, 904}}";
};
};
79DFC1280B59BFD60056C80E /* MethodSwizzle.m */ = {
Please sign in to comment.
Something went wrong with that request. Please try again.