From f60a4a6d3c35eb171355aeca619a6224eb1c4aa7 Mon Sep 17 00:00:00 2001
From: Matt Tolton <matt@tolton.com>
Date: Sun, 29 Jun 2008 16:22:32 -0700
Subject: [PATCH] Fixed outstanding issues with plugin architecture patch.

- Added ifdef MM_ENABLE_PLUGINS around all plugin specific code.
- Added short descriptions of classes.
- Removed extraneous NSLog call.
- Added RBSplitView and CTGradient to Credits.rtf.
---
 src/MacVim/Credits.rtf       |   12 +++++++++---
 src/MacVim/MMAppController.h |    5 +++++
 src/MacVim/MMAppController.m |   21 +++++++++++++++++++++
 src/MacVim/MMPlugInManager.m |   23 ++++++++++++++++++++++-
 src/MacVim/MMVimController.h |    7 +++++++
 src/MacVim/MMVimController.m |   15 ++++++++++++---
 src/MacVim/MacVim.h          |    1 +
 src/MacVim/PlugInGUI.m       |   23 ++++++++++++++++++++++-
 src/MacVim/PlugInImpl.m      |   19 +++++++++++++++++++
 src/MacVim/PlugInInterface.h |   18 ++++++++++++++++++
 10 files changed, 136 insertions(+), 8 deletions(-)

diff --git a/src/MacVim/Credits.rtf b/src/MacVim/Credits.rtf
index a4c1cb5..9e681a2 100644
--- a/src/MacVim/Credits.rtf
+++ b/src/MacVim/Credits.rtf
@@ -29,10 +29,12 @@ Enno L\'fcbbers\
 \pard\pardeftab720\ql\qnatural
 
 \f1\fs26 \cf0 Kyle Lippincott
-\f0\fs24 \
+\f0\i0\fs24 \
 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
 
-\i0 \cf0 \
+\i \cf0 Matt Tolton
+\i0 \
+\
 ...and many others who have helped by reporting bugs etc.\
 \
 \
@@ -48,4 +50,8 @@ Thanks to Andy Matuschak for {\field{\*\fldinst{HYPERLINK "http://sparkle.andyma
 \
 Thanks to Dave Batton for {\field{\*\fldinst{HYPERLINK "http://www.mere-mortal-software.com/blog/details.php?d=2007-03-11&c=show"}}{\fldrslt DBPrefsWindowController}}.\
 \
-Thanks to Allan Odgaard for making the "Edit in TextMate" input manager source code available, and also to Chris Eidhof and Eelco Lempsink for modifying it so that it could be used with any ODB capable editor.}
\ No newline at end of file
+Thanks to Allan Odgaard for making the "Edit in TextMate" input manager source code available, and also to Chris Eidhof and Eelco Lempsink for modifying it so that it could be used with any ODB capable editor.\
+\
+Thanks to Rainer Brockerhoff for RBSplitView.\
+\
+Thanks to Chad Weider for CTGradient.}
\ No newline at end of file
diff --git a/src/MacVim/MMAppController.h b/src/MacVim/MMAppController.h
index 2bf7eea..8afb20a 100644
--- a/src/MacVim/MMAppController.h
+++ b/src/MacVim/MMAppController.h
@@ -25,7 +25,10 @@
     NSMenu              *defaultMainMenu;
     NSMenuItem          *appMenuItemTemplate;
     NSMenuItem          *recentFilesMenuItem;
+
+#ifdef MM_ENABLE_PLUGINS
     NSMenuItem          *pluginMenuItem;
+#endif
 }
 
 + (MMAppController *)sharedInstance;
@@ -36,8 +39,10 @@
 - (void)windowControllerWillOpen:(MMWindowController *)windowController;
 - (void)setMainMenu:(NSMenu *)mainMenu;
 
+#ifdef MM_ENABLE_PLUGINS
 - (void)addItemToPluginMenu:(NSMenuItem *)item;
 - (void)removeItemFromPluginMenu:(NSMenuItem *)item;
+#endif
 
 - (IBAction)newWindow:(id)sender;
 - (IBAction)fileOpen:(id)sender;
diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m
index 8055749..a6fb327 100644
--- a/src/MacVim/MMAppController.m
+++ b/src/MacVim/MMAppController.m
@@ -43,7 +43,11 @@
 #import "MMWindowController.h"
 #import "Miscellaneous.h"
 #import "MMPreferenceController.h"
+
+#ifdef MM_ENABLE_PLUGINS
 #import "MMPlugInManager.h"
+#endif
+
 #import <unistd.h>
 
 
@@ -101,8 +105,11 @@ static int executeInLoginShell(NSString *path, NSArray *args);
 - (NSMutableDictionary *)extractArgumentsFromOdocEvent:
     (NSAppleEventDescriptor *)desc;
 - (void)passArguments:(NSDictionary *)args toVimController:(MMVimController*)vc;
+
+#ifdef MM_ENABLE_PLUGINS
 - (void)removePluginMenu;
 - (void)addPluginMenuToMenu:(NSMenu *)mainMenu;
+#endif
 @end
 
 
@@ -152,12 +159,14 @@ static int executeInLoginShell(NSString *path, NSArray *args);
         vimControllers = [NSMutableArray new];
         pidArguments = [NSMutableDictionary new];
 
+#ifdef MM_ENABLE_PLUGINS
         pluginMenuItem = [[NSMenuItem alloc] initWithTitle:@"Plugin"
                                                     action:NULL
                                              keyEquivalent:@""];
         NSMenu *submenu = [[NSMenu alloc] initWithTitle:@"Plugin"];
         [pluginMenuItem setSubmenu:submenu];
         [submenu release];
+#endif
 
         // NOTE: Do not use the default connection since the Logitech Control
         // Center (LCC) input manager steals and this would cause MacVim to
@@ -199,7 +208,9 @@ static int executeInLoginShell(NSString *path, NSArray *args);
     [openSelectionString release];  openSelectionString = nil;
     [recentFilesMenuItem release];  recentFilesMenuItem = nil;
     [defaultMainMenu release];  defaultMainMenu = nil;
+#ifdef MM_ENABLE_PLUGINS
     [pluginMenuItem release];  pluginMenuItem = nil;
+#endif
     [appMenuItemTemplate release];  appMenuItemTemplate = nil;
 
     [super dealloc];
@@ -257,7 +268,9 @@ static int executeInLoginShell(NSString *path, NSArray *args);
 - (void)applicationDidFinishLaunching:(NSNotification *)notification
 {
     [NSApp setServicesProvider:self];
+#ifdef MM_ENABLE_PLUGINS
     [[MMPlugInManager sharedManager] loadAllPlugIns];
+#endif
 }
 
 - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
@@ -515,7 +528,9 @@ static int executeInLoginShell(NSString *path, NSArray *args);
 
 - (void)applicationWillTerminate:(NSNotification *)notification
 {
+#ifdef MM_ENABLE_PLUGINS
     [[MMPlugInManager sharedManager] unloadAllPlugIns];
+#endif
 
 #if MM_HANDLE_XCODE_MOD_EVENT
     [[NSAppleEventManager sharedAppleEventManager]
@@ -681,11 +696,14 @@ static int executeInLoginShell(NSString *path, NSArray *args);
     }
     [NSApp setWindowsMenu:windowsMenu];
 
+#ifdef MM_ENABLE_PLUGINS
     // Move plugin menu from old to new main menu.
     [self removePluginMenu];
     [self addPluginMenuToMenu:mainMenu];
+#endif
 }
 
+#ifdef MM_ENABLE_PLUGINS
 - (void)addItemToPluginMenu:(NSMenuItem *)item
 {
     NSMenu *menu = [pluginMenuItem submenu];
@@ -701,6 +719,7 @@ static int executeInLoginShell(NSString *path, NSArray *args);
     if ([menu numberOfItems] == 0)
         [self removePluginMenu];
 }
+#endif
 
 - (IBAction)newWindow:(id)sender
 {
@@ -1277,6 +1296,7 @@ static int executeInLoginShell(NSString *path, NSArray *args);
         [vc addVimInput:buildSearchTextCommand(searchText)];
 }
 
+#ifdef MM_ENABLE_PLUGINS
 - (void)removePluginMenu
 {
     if ([pluginMenuItem menu])
@@ -1297,6 +1317,7 @@ static int executeInLoginShell(NSString *path, NSArray *args);
         }
     }
 }
+#endif
 
 @end // MMAppController (Private)
 
diff --git a/src/MacVim/MMPlugInManager.m b/src/MacVim/MMPlugInManager.m
index 93a4b98..2c9a184 100644
--- a/src/MacVim/MMPlugInManager.m
+++ b/src/MacVim/MMPlugInManager.m
@@ -8,6 +8,19 @@
  * See README.txt for an overview of the Vim source code.
  */
 
+/* 
+ * MMPlugInManager
+ *
+ * This class is responsible for finding MacVim plugins at startup, loading
+ * them, and keeping track of them.
+ *
+ * Author: Matt Tolton
+ */
+
+#import "MacVim.h"
+
+#ifdef MM_ENABLE_PLUGINS
+
 #import "MMPlugInManager.h"
 #import "PlugInInterface.h"
 #import "PlugInImpl.h"
@@ -35,6 +48,12 @@ static MMPlugInManager *plugInManager = nil;
     return self;
 }
 
+- (void)dealloc
+{
+    [plugInClasses release]; plugInClasses = nil;
+    [super dealloc];
+}
+
 - (NSArray *)plugInClasses;
 {
     return plugInClasses;
@@ -104,7 +123,7 @@ static MMPlugInManager *plugInManager = nil;
             if(currPrincipalClass && [self plugInClassIsValid:currPrincipalClass]) {
                 if ([currPrincipalClass initializePlugIn:
                     [MMPlugInAppMediator sharedAppMediator]]) {
-                    NSLog(@"Plug-in initialized: %@", currPath);
+                    //NSLog(@"Plug-in initialized: %@", currPath);
                     [plugInClasses addObject:currPrincipalClass];
                 } else {
                     NSLog(@"Plug-in failed to initialize: %@", currPath);
@@ -126,3 +145,5 @@ static MMPlugInManager *plugInManager = nil;
 }
 
 @end
+
+#endif
diff --git a/src/MacVim/MMVimController.h b/src/MacVim/MMVimController.h
index 23814be..397970e 100644
--- a/src/MacVim/MMVimController.h
+++ b/src/MacVim/MMVimController.h
@@ -10,7 +10,10 @@
 
 #import <Cocoa/Cocoa.h>
 #import "MacVim.h"
+
+#ifdef MM_ENABLE_PLUGINS
 #import "PlugInImpl.h"
+#endif
 
 
 @class MMWindowController;
@@ -32,7 +35,9 @@
     int                 pid;
     NSString            *serverName;
     NSDictionary        *vimState;
+#ifdef MM_ENABLE_PLUGINS
     MMPlugInInstanceMediator *instanceMediator;
+#endif
 }
 
 - (id)initWithBackend:(id)backend pid:(int)processIdentifier;
@@ -54,5 +59,7 @@
 - (void)addVimInput:(NSString *)string;
 - (NSString *)evaluateVimExpression:(NSString *)expr;
 - (id)evaluateVimExpressionCocoa:(NSString *)expr errorString:(NSString **)errstr;
+#ifdef MM_ENABLE_PLUGINS
 - (MMPlugInInstanceMediator *)instanceMediator;
+#endif
 @end
diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m
index e3a1485..8e61cf0 100644
--- a/src/MacVim/MMVimController.m
+++ b/src/MacVim/MMVimController.m
@@ -31,7 +31,9 @@
 #import "MMWindowController.h"
 #import "Miscellaneous.h"
 
+#ifdef MM_ENABLE_PLUGINS
 #import "MMPlugInManager.h"
+#endif
 
 static NSString *MMDefaultToolbarImageName = @"Attention";
 static int MMAlertTextFieldHeight = 22;
@@ -139,9 +141,11 @@ static BOOL isUnsafeMessage(int msgid);
 
         [mainMenu addItem:appMenuItem];
 
-        isInitialized = YES;
-        
+#ifdef MM_ENABLE_PLUGINS
         instanceMediator = [[MMPlugInInstanceMediator alloc] initWithVimController:self];
+#endif
+
+        isInitialized = YES;
     }
 
     return self;
@@ -151,10 +155,13 @@ static BOOL isUnsafeMessage(int msgid);
 {
     //NSLog(@"%@ %s", [self className], _cmd);
 
-    [instanceMediator release]; instanceMediator = nil;
 
     isInitialized = NO;
 
+#ifdef MM_ENABLE_PLUGINS
+    [instanceMediator release]; instanceMediator = nil;
+#endif
+
     [serverName release];  serverName = nil;
     [backendProxy release];  backendProxy = nil;
     [sendQueue release];  sendQueue = nil;
@@ -176,10 +183,12 @@ static BOOL isUnsafeMessage(int msgid);
     return windowController;
 }
 
+#ifdef MM_ENABLE_PLUGINS
 - (MMPlugInInstanceMediator *)instanceMediator
 {
     return instanceMediator;
 }
+#endif
 
 - (NSDictionary *)vimState
 {
diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h
index 6532919..1e92210 100644
--- a/src/MacVim/MacVim.h
+++ b/src/MacVim/MacVim.h
@@ -10,6 +10,7 @@
 
 #import <Cocoa/Cocoa.h>
 
+#define MM_ENABLE_PLUGINS
 
 
 
diff --git a/src/MacVim/PlugInGUI.m b/src/MacVim/PlugInGUI.m
index d296fcd..d5f18d2 100644
--- a/src/MacVim/PlugInGUI.m
+++ b/src/MacVim/PlugInGUI.m
@@ -8,6 +8,27 @@
  * See README.txt for an overview of the Vim source code.
  */
 
+/* 
+ * MMPlugInViewHeader
+ *
+ * Essentially just a title bar for a plugin view.  Handles drawing the
+ * drag-and-drop line where a new plugin view will be inserted.
+ *
+ * MMPlugInView
+ *
+ * This contains a single view added by a plugin.  
+ *
+ * MMPlugInViewContainer
+ *
+ * This contains multiple MMPlugInViews.  It handles the drag and drop aspects
+ * of the views, as well.
+ *
+ * Author: Matt Tolton
+ */
+#import "MacVim.h"
+
+#ifdef MM_ENABLE_PLUGINS
+
 #import "PlugInGUI.h"
 #import "CTGradient.h"
 
@@ -304,4 +325,4 @@ NSString *MMPlugInViewPboardType = @"MMPlugInViewPboardType";
 
 @end
 
-
+#endif
diff --git a/src/MacVim/PlugInImpl.m b/src/MacVim/PlugInImpl.m
index 2f3bee4..9a85276 100644
--- a/src/MacVim/PlugInImpl.m
+++ b/src/MacVim/PlugInImpl.m
@@ -8,6 +8,24 @@
  * See README.txt for an overview of the Vim source code.
  */
 
+/*
+ * MMPlugInInstanceMediator
+ *
+ * Implementation of the PlugInInstanceMediator protocol.  One of these is
+ * created per vim instance.  It manages all of the plugin instances for that
+ * vim instance.
+ *
+ * MMPlugInAppMediator
+ *
+ * Implementation of the PlugInAppMediator protocol.  Singleton class.
+ *
+ * Author: Matt Tolton
+ */
+
+#import "MacVim.h"
+
+#ifdef MM_ENABLE_PLUGINS
+
 #import "PlugInImpl.h"
 #import "PlugInGUI.h"
 #import "MMPlugInManager.h"
@@ -164,3 +182,4 @@ MMPlugInAppMediator *sharedAppMediator = nil;
 
 @end
 
+#endif
diff --git a/src/MacVim/PlugInInterface.h b/src/MacVim/PlugInInterface.h
index c8de34d..e1f97c2 100644
--- a/src/MacVim/PlugInInterface.h
+++ b/src/MacVim/PlugInInterface.h
@@ -11,6 +11,24 @@
 // This header file should include everything that a plug-in will need so that
 // it is all we need to distribute for plug-in developers.
 
+/* 
+ * PlugInAppMediator
+ *
+ * The interface that the plugin may use to interact with the MacVim
+ * application.
+ *
+ * PlugInInstanceMediator
+ *
+ * The interface that a plugin may use to interact with a specific vim instance
+ * within MacVim.
+ *
+ * PlugInProtocol
+ *
+ * The protocol which the principal class of the plugin must conform to.
+ *
+ * Author: Matt Tolton
+ *
+ */
 
 @protocol PlugInAppMediator
 
-- 
1.5.5.1

