diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 0c8a29fd77..8c27807e23 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -142,6 +142,9 @@ static int executeInLoginShell(NSString *path, NSArray *args); @"", MMLoginShellCommandKey, @"", MMLoginShellArgumentKey, [NSNumber numberWithBool:YES], MMDialogsTrackPwdKey, +#ifdef MM_ENABLE_PLUGINS + [NSNumber numberWithBool:YES], MMShowLeftPlugInContainerKey, +#endif nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dict]; diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h index f25786240f..07c5037341 100644 --- a/src/MacVim/Miscellaneous.h +++ b/src/MacVim/Miscellaneous.h @@ -10,7 +10,7 @@ #import - +#import "MacVim.h" // NSUserDefaults keys @@ -39,6 +39,10 @@ extern NSString *MMLoginShellCommandKey; extern NSString *MMLoginShellArgumentKey; extern NSString *MMDialogsTrackPwdKey; +#ifdef MM_ENABLE_PLUGINS +extern NSString *MMShowLeftPlugInContainerKey; +#endif + // Enum for MMUntitledWindowKey enum { MMUntitledWindowNever = 0, diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index f2f8d8fe95..c8aae51003 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -40,6 +40,9 @@ NSString *MMLoginShellCommandKey = @"MMLoginShellCommand"; NSString *MMLoginShellArgumentKey = @"MMLoginShellArgument"; NSString *MMDialogsTrackPwdKey = @"MMDialogsTrackPwd"; +#ifdef MM_ENABLE_PLUGINS +NSString *MMShowLeftPlugInContainerKey = @"MMShowLeftPlugInContainer"; +#endif diff --git a/src/MacVim/PlugInImpl.m b/src/MacVim/PlugInImpl.m index 53587534fe..ef13dc536a 100644 --- a/src/MacVim/PlugInImpl.m +++ b/src/MacVim/PlugInImpl.m @@ -22,7 +22,7 @@ * Author: Matt Tolton */ -#import "MacVim.h" +#import "Miscellaneous.h" #ifdef MM_ENABLE_PLUGINS @@ -47,7 +47,7 @@ NSSize contentSize = [drawer contentSize]; // XXX memory management for this - MMPlugInViewContainer * containerView = [[MMPlugInViewContainer alloc] + MMPlugInViewContainer *containerView = [[MMPlugInViewContainer alloc] initWithFrame:NSMakeRect(0, 0, contentSize.width, contentSize.height)]; [drawer setContentView:containerView]; @@ -55,7 +55,15 @@ [containerView release]; [drawer setParentWindow:[[vimController windowController] window]]; +} +- (void)toggleDrawer +{ + [drawer toggle:nil]; + [[NSUserDefaults standardUserDefaults] + setBool:[drawer state] == NSDrawerOpenState + || [drawer state] == NSDrawerOpeningState + forKey:MMShowLeftPlugInContainerKey]; } - (void)initializeInstances @@ -117,8 +125,11 @@ { //NSLog(@"%@ %s", [self className], _cmd); - // For now, just always open the drawer when adding a plugin view - [drawer open]; + // Do this here so that the drawer is never opened automatically when there + // are no plugin views. + if ([[NSUserDefaults standardUserDefaults] + boolForKey:MMShowLeftPlugInContainerKey] && [plugInViews count] == 0) + [drawer open]; MMPlugInViewController *newView = [[MMPlugInViewController alloc] initWithView:view title:title]; @@ -161,6 +172,34 @@ MMPlugInAppMediator *sharedAppMediator = nil; return sharedAppMediator; } +- (id)init +{ + if ((self = [super init]) == nil) return nil; + + NSString *title = NSLocalizedString(@"Toggle Left Drawer", + @"Toggle Left Drawer menu title"); + NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:title + action:@selector(toggleLeftDrawer:) + keyEquivalent:@""] autorelease]; + [item setTarget:self]; + [self addPlugInMenuItem:item]; + [self addPlugInMenuItem:[NSMenuItem separatorItem]]; + + return self; +} + +- (void)toggleLeftDrawer:(id)sender +{ + MMVimController *c = [[MMAppController sharedInstance] keyVimController]; + + [[c instanceMediator] toggleDrawer]; +} + +- (BOOL)validateMenuItem:(NSMenuItem *)item +{ + return [[MMAppController sharedInstance] keyVimController] != nil; +} + - (void)addPlugInMenuItem:(NSMenuItem *)menuItem { NSAssert(menuItem, @"menuItem cannot be nil");