1 #import "ITApplicationController.h"
2 #import "ITCategory-NSApplication.h"
4 @protocol _ITKitITApplicationControllerFSInterpreterResultCompatibility <NSObject>
6 - (NSString *)errorMessage;
10 @protocol _ITKitITApplicationControllerFSInterpreterCompatibility <NSObject>
11 - (void)setObject:(id)object forIdentifier:(NSString *)identifier;
12 - (id <_ITKitITApplicationControllerFSInterpreterResultCompatibility>)execute:(NSString *)command;
15 @implementation ITApplicationController
18 if (self = [super init]) {
19 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"ITDebugMode"]) {
25 _dockMenu = [[NSMenu alloc] initWithTitle:[[NSApplication sharedApplication] applicationName]];
27 _debugMenu = [[NSMenu alloc] initWithTitle:@"Debug"];
28 _debugMenuItem = [[NSMenuItem alloc] initWithTitle:@"Debug" action:nil keyEquivalent:@""];
29 [_debugMenuItem setSubmenu:_debugMenu];
30 _dockDebugMenuItem = [[NSMenuItem alloc] initWithTitle:@"Debug" action:nil keyEquivalent:@""];
31 [_dockDebugMenuItem setSubmenu:_debugMenu];
36 - (void)reloadPlugins {
41 _plugins = [[NSMutableArray alloc] init];
43 NSArray *pluginPaths = [NSBundle pathsForResourcesOfType:@"plugin" inDirectory:[[NSBundle mainBundle] builtInPlugInsPath]];
44 NSEnumerator *pluginPathEnumerator = [pluginPaths objectEnumerator];
47 while (pluginPath = [pluginPathEnumerator nextObject]) {
48 NSBundle *plugin = [NSBundle bundleWithPath:pluginPath];
50 Class pluginClass = [plugin principalClass];
52 if ([pluginClass instancesRespondToSelector:@selector(initWithApplicationController:)]) {
53 pluginInstance = [(id <ITApplicationControllerGenericPlugin>)[pluginClass alloc] initWithApplicationController:self];
55 pluginInstance = [[pluginClass alloc] init];
58 [_plugins addObject:[pluginInstance autorelease]]; // autoreleasing so that when we reload plugins, and the _plugins array is released, the accompanying previously-loaded plugins die with it.
63 Class fsinterpreterClass;
64 if (fsinterpreterClass = NSClassFromString(@"FSInterpreter")) {
65 NSArray *fscriptPaths = [NSBundle pathsForResourcesOfType:@"fscriptplugin" inDirectory:[[NSBundle mainBundle] builtInPlugInsPath]];
66 NSEnumerator *fscriptPathEnumerator = [fscriptPaths objectEnumerator];
69 while (fscriptPath = [fscriptPathEnumerator nextObject]) {
70 NSString *fscriptSource = [NSString stringWithContentsOfFile:fscriptPath];
72 id fscriptInterpreter = [(id <_ITKitITApplicationControllerFSInterpreterCompatibility>)[fsinterpreterClass alloc] init];
74 [fscriptInterpreter setObject:self forIdentifier:@"applicationController"];
75 [fscriptInterpreter setObject:fscriptInterpreter forIdentifier:@"hostInterpreter"];
76 result = [fscriptInterpreter execute:fscriptSource];
78 NSRunAlertPanel(@"F-Script Plugin Error",[NSString stringWithFormat:@"Plugin: %@\nRange: %@\nMessage:%@", fscriptPath, NSStringFromRange([result errorRange]), [result errorMessage]],@"Dismiss",nil,nil);
79 [fscriptInterpreter release];
81 [_plugins addObject:[fscriptInterpreter autorelease]];
88 - (NSArray *)plugins {
92 - (NSMenu *)dockMenu {
96 - (NSMenu *)debugMenu {
100 - (void)enableDebugMenu {
101 NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];
102 int helpIndex = [mainMenu indexOfItemWithTitle:@"Help"];
103 if (helpIndex != -1) {
104 [mainMenu insertItem:_debugMenuItem atIndex:helpIndex];
106 [mainMenu addItem:_debugMenuItem];
109 [_dockMenu insertItem:_dockDebugMenuItem atIndex:0];
110 if ([_dockMenu numberOfItems] > 1) {
111 [_dockMenu insertItem:[NSMenuItem separatorItem] atIndex:1];
115 - (void)disableDebugMenu {
116 [[[NSApplication sharedApplication] mainMenu] removeItem:_debugMenuItem];
117 [_dockMenu removeItem:_dockDebugMenuItem];
118 if ([_dockMenu numberOfItems] > 1) {
119 NSMenuItem *sep = [_dockMenu itemAtIndex:0];
120 if ([sep isSeparatorItem]) {
121 [_dockMenu removeItem:sep];
127 [_dockDebugMenuItem release];
128 [_debugMenuItem release];
129 [_debugMenu release];
134 - (NSMenu *)applicationDockMenu:(NSApplication *)sender {