Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 119 lines (102 sloc) 4.538 kB
1566fec @rentzsch [NEW] Xmo'd: mogenerator + Xcode.
authored
1 #import "Xmod.h"
9d3a214 @rentzsch [NEW] Xmod: Migrate from MethodSwizzle to JRSwizzle. Modify project t…
authored
2 #import "JRSwizzle.h"
1566fec @rentzsch [NEW] Xmo'd: mogenerator + Xcode.
authored
3
7c31685 @rentzsch [NEW] Xmod 1.8: Now compatible with Xcode 3.0. Now fires off osascrip…
authored
4 /*
5 Xcode 2.4
6 10.4 SDK ppc, i386
7 Xcode 2.5
8 10.5 SDK ppc, i386
9 Xcode 3.0
10 10.5 SDK ppc GC, ppc64 GC, i386 GC, x86_64 GC
c6d0ef3 @rentzsch [NEW] Xmo'd running under Snow Leopard 10.6.1 + Xcode 3.2.1. Dropping…
authored
11 Xcode 3.2
12 10.6 SDK i386 GC, x86_64 GC
7c31685 @rentzsch [NEW] Xmod 1.8: Now compatible with Xcode 3.0. Now fires off osascrip…
authored
13 */
14
a191e62 @rentzsch [NEW] Xmo'd for Xcode 2.x.
authored
15 @interface NSObject (xmod_saveModelToFile)
1566fec @rentzsch [NEW] Xmo'd: mogenerator + Xcode.
authored
16 @end
a191e62 @rentzsch [NEW] Xmo'd for Xcode 2.x.
authored
17 @implementation NSObject (xmod_saveModelToFile)
18 - (BOOL)xmod_saveModelToFile:(NSString*)modelPackagePath_ {
19 BOOL result = [self xmod_saveModelToFile:modelPackagePath_];
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
20 if (result)
21 [[Xmod sharedXmod] performSelector:@selector(runScriptNamed:) withObject:@"Xmod" afterDelay:0.0];
1566fec @rentzsch [NEW] Xmo'd: mogenerator + Xcode.
authored
22 return result;
23 }
24 @end
25
26 @implementation Xmod
27
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
28 Xmod *gSharedXmod;
29
1566fec @rentzsch [NEW] Xmo'd: mogenerator + Xcode.
authored
30 + (void)pluginDidLoad:(NSBundle*)bundle_ {
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
31 gSharedXmod = [[self alloc] initWithBundle:bundle_];
1566fec @rentzsch [NEW] Xmo'd: mogenerator + Xcode.
authored
32 }
33
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
34 + (id)sharedXmod {
35 return gSharedXmod;
36 }
37
38 - (id)initWithBundle:(NSBundle*)bundle_ {
6473be9 @rentzsch [NEW] Xmo'd: Autocustomize Entity Classes Xcode 2.x menu item.
authored
39 self = [super init];
40 if (self) {
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
41 bundle = [bundle_ retain];
6473be9 @rentzsch [NEW] Xmo'd: Autocustomize Entity Classes Xcode 2.x menu item.
authored
42 [[NSNotificationCenter defaultCenter] addObserver:self
43 selector:@selector(applicationDidFinishLaunching:)
44 name:NSApplicationDidFinishLaunchingNotification
45 object:nil];
46 }
47 return self;
48 }
49
50 - (void)applicationDidFinishLaunching:(NSNotification*)notification_ {
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
51 // Force loading of the Core Data XDesign plugin so we can find the class to swizzle its instance method.
52 NSBundle *coreDataPlugin = nil;
53
54 NSString *xcodeVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
55 NSAssert(xcodeVersion, @"failed to read Xcode version");
56 if ([xcodeVersion isEqualToString:@"2.4"]) {
57 coreDataPlugin = [NSBundle bundleWithPath:@"/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin"];
58 } else if ([xcodeVersion isEqualToString:@"2.5"]) {
59 coreDataPlugin = [NSBundle bundleWithPath:@"/Xcode2.5/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin"];
c6d0ef3 @rentzsch [NEW] Xmo'd running under Snow Leopard 10.6.1 + Xcode 3.2.1. Dropping…
authored
60 } else if ([xcodeVersion isEqualToString:@"3.0"] || [xcodeVersion hasPrefix:@"3.1"] || [xcodeVersion hasPrefix:@"3.2"]) {
7c31685 @rentzsch [NEW] Xmod 1.8: Now compatible with Xcode 3.0. Now fires off osascrip…
authored
61 coreDataPlugin = [NSBundle bundleWithPath:@"/Developer/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin"];
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
62 } else {
5ba7853 @rentzsch [NEW] Xmo'd: Add Xcode 3.1 support (just had to add recognition of th…
authored
63 NSLog(@"Xmod: unknown Xcode version (%@), not loading.", xcodeVersion);
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
64 return;
65 }
66 NSAssert(coreDataPlugin, @"failed to load XDCoreDataModel.xdplugin");
67 [coreDataPlugin load];
68
69 Class persistenceDocumentController = NSClassFromString(@"XDPersistenceDocumentController");
70 NSAssert(persistenceDocumentController, @"failed to load XDPersistenceDocumentController");
71
9d3a214 @rentzsch [NEW] Xmod: Migrate from MethodSwizzle to JRSwizzle. Modify project t…
authored
72 NSError *error = nil;
73 BOOL swizzled = [persistenceDocumentController jr_swizzleMethod:@selector(saveModelToFile:)
74 withMethod:@selector(xmod_saveModelToFile:)
75 error:&error];
76 NSAssert1(swizzled, @"failed to swizzle -[XDPersistenceDocumentController saveModelToFile:]: %@", error);
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
77
78 // Install the Autocustomize menu item.
6473be9 @rentzsch [NEW] Xmo'd: Autocustomize Entity Classes Xcode 2.x menu item.
authored
79 NSMenu *designMenu = [[[NSApp mainMenu] itemWithTitle:@"Design"] submenu];
80 NSMenu *dataModelMenu = [[designMenu itemWithTitle:@"Data Model"] submenu];
81
82 NSMenuItem *myMenuItem = [dataModelMenu insertItemWithTitle:@"Autocustomize Entity Classes"
83 action:@selector(autocustomizeEntityClasses:)
84 keyEquivalent:@""
85 atIndex:0];
86 [myMenuItem setTarget:self];
87 }
88
89 - (IBAction)autocustomizeEntityClasses:(id)sender_ {
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
90 [self runScriptNamed:@"Autocustomize Entity Classes"];
91 }
92
93 - (void)runScriptNamed:(NSString*)scriptName_ {
94 NSString *scriptPath = [bundle pathForResource:scriptName_ ofType:@"scpt" inDirectory:@"Scripts"];
95 NSAssert1(scriptPath, @"failed to find %@.scpt", scriptName_);
7c31685 @rentzsch [NEW] Xmod 1.8: Now compatible with Xcode 3.0. Now fires off osascrip…
authored
96 #if 1
97 NSTask *osascriptTask = [[[NSTask alloc] init] autorelease];
98 [osascriptTask setLaunchPath:@"/usr/bin/osascript"];
99 [osascriptTask setArguments:[NSArray arrayWithObject:scriptPath]];
100 [osascriptTask launch];
101 #else
102 // Executing an AppleScript inside Xcode's context is weird.
103 // Scripts like `tell app "Finder" to get folder of file` simply fail. I suspect rogue
104 // coercion handlers or namespace bugs. So now I just fire off an osascript invocation
105 // to give the script a clean nonweird enironment.
34845a3 @rentzsch [NEW] Xcode 2.5 compatible. Move Xmod script execution to the top of …
authored
106 NSDictionary *scriptInitError = nil;
107 NSAppleScript *script = [[[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath]
108 error:&scriptInitError] autorelease];
109 NSAssert2(!scriptInitError, @"failed to init %@.scpt: %@", scriptName_, scriptInitError);
110 if (!scriptInitError) {
111 NSDictionary *scriptExecuteError = nil;
112 [script executeAndReturnError:&scriptExecuteError];
113 NSAssert2(!scriptInitError, @"failed to execute %@.scpt: %@", scriptName_, scriptExecuteError);
114 }
7c31685 @rentzsch [NEW] Xmod 1.8: Now compatible with Xcode 3.0. Now fires off osascrip…
authored
115 #endif
6473be9 @rentzsch [NEW] Xmo'd: Autocustomize Entity Classes Xcode 2.x menu item.
authored
116 }
117
1566fec @rentzsch [NEW] Xmo'd: mogenerator + Xcode.
authored
118 @end
Something went wrong with that request. Please try again.