1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * MacVim GUI port by Bjorn Winckler
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 * See README.txt for an overview of the Vim source code.
14 * This class is responsible for finding MacVim plugins at startup, loading
15 * them, and keeping track of them.
22 #ifdef MM_ENABLE_PLUGINS
24 #import "MMPlugInManager.h"
25 #import "PlugInInterface.h"
26 #import "PlugInImpl.h"
28 @implementation MMPlugInManager
30 static NSString *ext = @"mmplugin";
32 static NSString *appSupportSubpath = @"Application Support/MacVim/PlugIns";
34 static MMPlugInManager *plugInManager = nil;
36 + (MMPlugInManager*)sharedManager
39 plugInManager = [[MMPlugInManager alloc] init];
46 if ((self = [super init]) == nil) return nil;
47 plugInClasses = [[NSMutableArray alloc] init];
53 [plugInClasses release]; plugInClasses = nil;
57 - (NSArray *)plugInClasses;
62 - (NSMutableArray *)allBundles
64 NSArray *librarySearchPaths;
65 NSEnumerator *searchPathEnum;
67 NSMutableArray *bundleSearchPaths = [NSMutableArray array];
68 NSMutableArray *allBundles = [NSMutableArray array];
70 librarySearchPaths = NSSearchPathForDirectoriesInDomains(
71 NSLibraryDirectory, NSAllDomainsMask - NSSystemDomainMask, YES);
73 searchPathEnum = [librarySearchPaths objectEnumerator];
74 while(currPath = [searchPathEnum nextObject]) {
75 [bundleSearchPaths addObject:
76 [currPath stringByAppendingPathComponent:appSupportSubpath]];
79 [bundleSearchPaths addObject:
80 [[NSBundle mainBundle] builtInPlugInsPath]];
82 searchPathEnum = [bundleSearchPaths objectEnumerator];
83 while(currPath = [searchPathEnum nextObject]) {
84 NSDirectoryEnumerator *bundleEnum;
85 NSString *currBundlePath;
86 bundleEnum = [[NSFileManager defaultManager]
87 enumeratorAtPath:currPath];
89 while(currBundlePath = [bundleEnum nextObject]) {
90 if([[currBundlePath pathExtension] isEqualToString:ext]) {
91 [allBundles addObject:[currPath
92 stringByAppendingPathComponent:currBundlePath]];
101 - (BOOL)plugInClassIsValid:(Class)class
103 return [class conformsToProtocol:@protocol(PlugInProtocol)];
106 - (void)loadAllPlugIns
108 NSMutableArray *bundlePaths;
109 NSEnumerator *pathEnum;
111 NSBundle *currBundle;
112 Class currPrincipalClass;
114 bundlePaths = [NSMutableArray array];
116 [bundlePaths addObjectsFromArray:[self allBundles]];
118 pathEnum = [bundlePaths objectEnumerator];
119 while(currPath = [pathEnum nextObject]) {
120 currBundle = [NSBundle bundleWithPath:currPath];
122 currPrincipalClass = [currBundle principalClass];
123 if(currPrincipalClass && [self plugInClassIsValid:currPrincipalClass]) {
124 if ([currPrincipalClass initializePlugIn:
125 [MMPlugInAppMediator sharedAppMediator]]) {
126 //NSLog(@"Plug-in initialized: %@", currPath);
127 [plugInClasses addObject:currPrincipalClass];
129 NSLog(@"Plug-in failed to initialize: %@", currPath);
132 NSLog(@"Plug-in did not conform to protocol: %@", currPath);
138 - (void)unloadAllPlugIns
140 int i, count = [plugInClasses count];
141 for (i = 0; i < count; i++)
142 [[plugInClasses objectAtIndex:i] terminatePlugIn];
144 [plugInClasses removeAllObjects];