diff --git a/MMBackend.m b/MMBackend.m index 2f503b3388..71d5edc069 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -874,6 +874,35 @@ static int specialKeyToNSKey(int key); if (menu) { gui_menu_cb(menu); } + } else if (ToggleToolbarMsgID == msgid) { + char_u go[sizeof(GO_ALL)+2]; + char_u *p; + int len; + + STRCPY(go, p_go); + p = vim_strchr(go, GO_TOOLBAR); + len = STRLEN(go); + + if (p != NULL) { + char_u *end = go + len; + while (p < end) { + p[0] = p[1]; + ++p; + } + } else { + go[len] = GO_TOOLBAR; + go[len+1] = NUL; + } + + set_option_value((char_u*)"guioptions", 0, go, 0); + + // Force screen redraw (does it have to be this complicated?). + redraw_all_later(CLEAR); + update_screen(NOT_VALID); + setcursor(); + out_flush(); + gui_update_cursor(FALSE, FALSE); + gui_mch_flush(); } else if (ScrollbarEventMsgID == msgid) { if (!data) return; const void *bytes = [data bytes]; diff --git a/MMVimController.m b/MMVimController.m index 687dee1604..99e48fda5e 100644 --- a/MMVimController.m +++ b/MMVimController.m @@ -306,10 +306,10 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) [windowController updateTabsWithData:data]; } else if (ShowTabBarMsgID == msgid) { //NSLog(@"Showing tab bar"); - [windowController showTabBar:self]; + [windowController showTabBar:YES]; } else if (HideTabBarMsgID == msgid) { //NSLog(@"Hiding tab bar"); - [windowController hideTabBar:self]; + [windowController showTabBar:NO]; } else if (SetTextDimensionsMsgID == msgid) { const void *bytes = [data bytes]; int rows = *((int*)bytes); bytes += sizeof(int); @@ -409,7 +409,17 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) [toolbar setDisplayMode:NSToolbarDisplayModeIconOnly]; [toolbar setSizeMode:NSToolbarSizeModeSmall]; - [[windowController window] setToolbar:toolbar]; + NSWindow *win = [windowController window]; + [win setToolbar:toolbar]; + + // HACK! Redirect the pill button so that we can ask Vim to + // hide the toolbar. + NSButton *pillButton = [win + standardWindowButton:NSWindowToolbarButton]; + if (pillButton) { + [pillButton setAction:@selector(toggleToolbar:)]; + [pillButton setTarget:windowController]; + } } } else if (title) { [self addMenuWithTag:tag parent:parentTag title:title atIndex:idx]; @@ -518,9 +528,7 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) int size = flags & ToolbarSizeRegularFlag ? NSToolbarSizeModeRegular : NSToolbarSizeModeSmall; - [toolbar setSizeMode:size]; - [toolbar setDisplayMode:mode]; - [toolbar setVisible:enable]; + [windowController showToolbar:enable size:size mode:mode]; } else if (CreateScrollbarMsgID == msgid) { const void *bytes = [data bytes]; long ident = *((long*)bytes); bytes += sizeof(long); diff --git a/MMWindowController.h b/MMWindowController.h index 6c33adc94c..5227c03273 100644 --- a/MMWindowController.h +++ b/MMWindowController.h @@ -56,10 +56,11 @@ - (void)setFont:(NSFont *)font; - (void)processCommandQueueDidFinish; - (void)popupMenu:(NSMenu *)menu atRow:(int)row column:(int)col; +- (void)showTabBar:(BOOL)on; +- (void)showToolbar:(BOOL)on size:(int)size mode:(int)mode; - (IBAction)addNewTab:(id)sender; -- (IBAction)showTabBar:(id)sender; -- (IBAction)hideTabBar:(id)sender; +- (IBAction)toggleToolbar:(id)sender; @end diff --git a/MMWindowController.m b/MMWindowController.m index 445ed9f150..7cd9e93686 100644 --- a/MMWindowController.m +++ b/MMWindowController.m @@ -169,6 +169,8 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) - (void)windowDidLoad { + NSWindow *win = [self window]; + // Called after window nib file is loaded. [tablineSeparator setHidden:NO]; @@ -200,12 +202,12 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) addObserver:vimController selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification - object:[self window]]; + object:win]; [[NSNotificationCenter defaultCenter] addObserver:vimController selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification - object:[self window]]; + object:win]; } - (MMVimController *)vimController @@ -482,49 +484,66 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) [NSMenu popUpContextMenu:menu withEvent:event forView:textView]; } +- (void)showTabBar:(BOOL)on +{ + [tabBarControl setHidden:!on]; + + if (!on) { + NSToolbar *toolbar = [[self window] toolbar]; + [tablineSeparator setHidden:![toolbar isVisible]]; + } else { + [tablineSeparator setHidden:on]; + } + + if (setupDone) + shouldUpdateWindowSize = YES; +} + +- (void)showToolbar:(BOOL)on size:(int)size mode:(int)mode +{ + NSToolbar *toolbar = [[self window] toolbar]; + if (!toolbar) return; + + [toolbar setSizeMode:size]; + [toolbar setDisplayMode:mode]; + [toolbar setVisible:on]; + + if (!on) { + [tablineSeparator setHidden:YES]; + } else { + [tablineSeparator setHidden:![tabBarControl isHidden]]; + } +} + - (IBAction)addNewTab:(id)sender { - // NOTE! This can get called a lot if the user holds down the key - // equivalent for this action, which causes the ports to fill up. If we - // wait for the message to be sent then the app might become unresponsive. - [vimController sendMessage:AddNewTabMsgID data:nil wait:NO]; +// NOTE! This can get called a lot if the user holds down the key +// equivalent for this action, which causes the ports to fill up. If we +// wait for the message to be sent then the app might become unresponsive. +[vimController sendMessage:AddNewTabMsgID data:nil wait:NO]; } -- (IBAction)showTabBar:(id)sender +- (IBAction)toggleToolbar:(id)sender { - [tablineSeparator setHidden:YES]; - [tabBarControl setHidden:NO]; - - if (setupDone) - shouldUpdateWindowSize = YES; +[vimController sendMessage:ToggleToolbarMsgID data:nil wait:NO]; } -- (IBAction)hideTabBar:(id)sender -{ - [tablineSeparator setHidden:NO]; - [tabBarControl setHidden:YES]; - - if (setupDone) - shouldUpdateWindowSize = YES; -} - - // -- PSMTabBarControl delegate ---------------------------------------------- - (void)tabView:(NSTabView *)theTabView didSelectTabViewItem: - (NSTabViewItem *)tabViewItem + (NSTabViewItem *)tabViewItem { - // HACK! There seem to be a bug in NSTextView which results in the first - // responder not being set to the view of the tab item so it is done - // manually here. - [[self window] makeFirstResponder:[tabViewItem view]]; +// HACK! There seem to be a bug in NSTextView which results in the first +// responder not being set to the view of the tab item so it is done +// manually here. +[[self window] makeFirstResponder:[tabViewItem view]]; - // HACK! The selection message should not be propagated to the VimTask if - // the VimTask selected the tab (e.g. as opposed the user clicking the - // tab). The delegate method has no way of knowing who initiated the +// HACK! The selection message should not be propagated to the VimTask if +// the VimTask selected the tab (e.g. as opposed the user clicking the +// tab). The delegate method has no way of knowing who initiated the // selection so a flag is set when the VimTask initiated the selection. if (!vimTaskSelectedTab) { // Propagate the selection message to the VimTask. @@ -688,9 +707,10 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) size.width += [textView textContainerOrigin].x + right; size.height += [textView textContainerOrigin].y + bot; - // A one pixel high separator is shown if tabline is hidden. - if ([tabBarControl isHidden]) ++size.height; - else size.height += [tabBarControl frame].size.height; + if (![tablineSeparator isHidden]) + ++size.height; + if (![tabBarControl isHidden]) + size.height += [tabBarControl frame].size.height; if (![ud boolForKey:MMStatuslineOffKey]) size.height += StatusLineHeight; @@ -709,9 +729,10 @@ NSMutableArray *buildMenuAddress(NSMenu *menu) { NSRect rect = { 0, 0, contentSize.width, contentSize.height }; - // A one pixel high separator is shown if tabline is hidden. - if ([tabBarControl isHidden]) --rect.size.height; - else rect.size.height -= [tabBarControl frame].size.height; + if (![tablineSeparator isHidden]) + --rect.size.height; + if (![tabBarControl isHidden]) + rect.size.height -= [tabBarControl frame].size.height; if (![[NSUserDefaults standardUserDefaults] boolForKey:MMStatuslineOffKey]) { diff --git a/MacVim.h b/MacVim.h index a4e80cf3ee..71affc1279 100644 --- a/MacVim.h +++ b/MacVim.h @@ -92,6 +92,7 @@ enum { EnableMenuItemMsgID, ExecuteMenuMsgID, ShowToolbarMsgID, + ToggleToolbarMsgID, CreateScrollbarMsgID, DestroyScrollbarMsgID, ShowScrollbarMsgID,