1 #import "ITApplicationController.h"
2 #import "ITCategory-NSApplication.h"
4 @implementation ITApplicationController
7 if (self = [super init]) {
8 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"ITDebugMode"]) {
14 _dockMenu = [[NSMenu alloc] initWithTitle:[[NSApplication sharedApplication] applicationName]];
16 _debugMenu = [[NSMenu alloc] initWithTitle:@"Debug"];
17 _debugMenuItem = [[NSMenuItem alloc] initWithTitle:@"Debug" action:nil keyEquivalent:@""];
18 [_debugMenuItem setSubmenu:_debugMenu];
19 _dockDebugMenuItem = [[NSMenuItem alloc] initWithTitle:@"Debug" action:nil keyEquivalent:@""];
20 [_dockDebugMenuItem setSubmenu:_debugMenu];
25 - (void)reloadPlugins {
30 _plugins = [[NSMutableArray alloc] init];
32 NSArray *pluginPaths = [NSBundle pathsForResourcesOfType:@"plugin" inDirectory:[[NSBundle mainBundle] builtInPlugInsPath]];
33 NSEnumerator *pluginPathEnumerator = [pluginPaths objectEnumerator];
36 while (pluginPath = [pluginPathEnumerator nextObject]) {
37 NSBundle *plugin = [NSBundle bundleWithPath:pluginPath];
39 Class pluginClass = [plugin principalClass];
41 if ([pluginClass instancesRespondToSelector:@selector(initWithApplicationController:)]) {
42 pluginInstance = [(id <ITApplicationControllerGenericPlugin>)[pluginClass alloc] initWithApplicationController:self];
44 pluginInstance = [[pluginClass alloc] init];
47 [_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.
53 - (NSArray *)plugins {
57 - (NSMenu *)dockMenu {
61 - (NSMenu *)debugMenu {
65 - (void)enableDebugMenu {
66 NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];
67 int helpIndex = [mainMenu indexOfItemWithTitle:@"Help"];
68 if (helpIndex != -1) {
69 [mainMenu insertItem:_debugMenuItem atIndex:helpIndex];
71 [mainMenu addItem:_debugMenuItem];
74 [_dockMenu insertItem:_dockDebugMenuItem atIndex:0];
75 if ([_dockMenu numberOfItems] > 1) {
76 [_dockMenu insertItem:[NSMenuItem separatorItem] atIndex:1];
80 - (void)disableDebugMenu {
81 [[[NSApplication sharedApplication] mainMenu] removeItem:_debugMenuItem];
82 [_dockMenu removeItem:_dockDebugMenuItem];
83 if ([_dockMenu numberOfItems] > 1) {
84 NSMenuItem *sep = [_dockMenu itemAtIndex:0];
85 if ([sep isSeparatorItem]) {
86 [_dockMenu removeItem:sep];
92 [_dockDebugMenuItem release];
93 [_debugMenuItem release];
99 - (NSMenu *)applicationDockMenu:(NSApplication *)sender {