From 4466c5d03dc06b8cc8bfedef3cb0d4ffbddb335e Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Thu, 11 Dec 2008 21:05:06 +0100 Subject: [PATCH] Clean up 'guitabtooltip' patch --- src/MacVim/MMBackend.m | 30 +++++++++------------- src/MacVim/MMVimView.m | 6 ++++- src/MacVim/PSMTabBarControl/source/PSMTabBarCell.h | 3 +++ src/MacVim/PSMTabBarControl/source/PSMTabBarCell.m | 14 ++++++++++ .../PSMTabBarControl/source/PSMTabBarControl.h | 4 --- .../PSMTabBarControl/source/PSMTabBarControl.m | 23 +++++++---------- 6 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 8e9025d8..1f0e727a 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -621,31 +621,25 @@ static NSString *MMSymlinkWarningString = tabpage_T *tp; for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { + // Count the number of windows in the tabpage. + //win_T *wp = tp->tp_firstwin; + //int wincount; + //for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount); + //[data appendBytes:&wincount length:sizeof(int)]; + int tabProp = MMTabInfoCount; [data appendBytes:&tabProp length:sizeof(int)]; for (tabProp = MMTabLabel; tabProp < MMTabInfoCount; ++tabProp) { // This function puts the label of the tab in the global 'NameBuff'. get_tabline_label(tp, (tabProp == MMTabToolTip)); - char_u *s = NameBuff; - int len = STRLEN(s); - if (len <= 0) continue; - -#ifdef FEAT_MBYTE - s = CONVERT_TO_UTF8(s); -#endif + NSString *s = [NSString stringWithVimString:NameBuff]; + int len = [s lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + if (len < 0) + len = 0; - // Count the number of windows in the tabpage. - //win_T *wp = tp->tp_firstwin; - //int wincount; - //for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount); - - //[data appendBytes:&wincount length:sizeof(int)]; [data appendBytes:&len length:sizeof(int)]; - [data appendBytes:s length:len]; - -#ifdef FEAT_MBYTE - CONVERT_TO_UTF8_FREE(s); -#endif + if (len > 0) + [data appendBytes:[s UTF8String] length:len]; } } diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index cb7023dc..97a2aace 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -288,6 +288,8 @@ enum { unsigned i; for (i = 0; i < infoCount; ++i) { int length = *((int*)p); p += sizeof(int); + if (length <= 0) + continue; NSString *val = [[NSString alloc] initWithBytes:(void*)p length:length @@ -304,7 +306,9 @@ enum { ++tabIdx; break; case MMTabToolTip: - [[self tabBarControl] setToolTip:val forTabViewItem:tvi]; + if (tvi) + [[self tabBarControl] setToolTip:val + forTabViewItem:tvi]; break; default: NSLog(@"WARNING: Unknown tab info for index: %d", i); diff --git a/src/MacVim/PSMTabBarControl/source/PSMTabBarCell.h b/src/MacVim/PSMTabBarControl/source/PSMTabBarCell.h index 51717d62..5d98eff3 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMTabBarCell.h +++ b/src/MacVim/PSMTabBarControl/source/PSMTabBarCell.h @@ -31,6 +31,7 @@ BOOL _isCloseButtonSuppressed; BOOL _hasIcon; int _count; + NSString *_toolTip; } // creation/destruction @@ -72,6 +73,8 @@ - (void)setIsPlaceholder:(BOOL)value; - (int)currentStep; - (void)setCurrentStep:(int)value; +- (NSString *)toolTip; +- (void)setToolTip:(NSString *)tip; // component attributes - (NSRect)indicatorRectForFrame:(NSRect)cellFrame; diff --git a/src/MacVim/PSMTabBarControl/source/PSMTabBarCell.m b/src/MacVim/PSMTabBarControl/source/PSMTabBarCell.m index 121912f3..a8269538 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMTabBarCell.m +++ b/src/MacVim/PSMTabBarControl/source/PSMTabBarCell.m @@ -69,6 +69,7 @@ - (void)dealloc { [_indicator release]; + [_toolTip release]; [super dealloc]; } @@ -252,6 +253,19 @@ _currentStep = value; } +- (NSString *)toolTip +{ + return _toolTip; +} + +- (void)setToolTip:(NSString *)tip +{ + if (tip != _toolTip) { + [_toolTip release]; + _toolTip = [tip copy]; + } +} + #pragma mark - #pragma mark Component Attributes diff --git a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h index 3dfb7529..bdf971b2 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h +++ b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.h @@ -71,9 +71,6 @@ enum { BOOL _allowsDragBetweenWindows; BOOL _delegateHandlingDrag; NSDragOperation _delegateInitialDragOperation; - - // tool tips - NSMutableDictionary *_toolTips; // MVC help IBOutlet id delegate; @@ -103,7 +100,6 @@ enum { - (void)setAllowsDragBetweenWindows:(BOOL)flag; // tool tips -- (NSString *)toolTipForTabViewItem:(NSTabViewItem *)tvi; - (void)setToolTip:(NSString *)value forTabViewItem:(NSTabViewItem *)tvi; // accessors diff --git a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m index db7a53df..2c7e45c7 100644 --- a/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m +++ b/src/MacVim/PSMTabBarControl/source/PSMTabBarControl.m @@ -146,10 +146,8 @@ } [_addTabButton setNeedsDisplay:YES]; } - - _toolTips = [[NSMutableDictionary alloc] init]; } - + - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; @@ -171,7 +169,6 @@ [partnerView release]; [_lastMouseDownEvent release]; [style release]; - [_toolTips release]; [delegate release]; [self unregisterDraggedTypes]; @@ -385,15 +382,16 @@ #pragma mark - #pragma mark Tool tips -- (NSString *)toolTipForTabViewItem:(NSTabViewItem *)tvi -{ - return [_toolTips objectForKey:[NSValue valueWithPointer:tvi]]; -} - - (void)setToolTip:(NSString *)value forTabViewItem:(NSTabViewItem *)tvi { - [_toolTips setObject:value forKey:[NSValue valueWithPointer:tvi]]; + int i, cellCount = [_cells count]; + for (i = 0; i < cellCount; i++) { + PSMTabBarCell *cell = [_cells objectAtIndex:i]; + if ([cell representedObject] == tvi) + [cell setToolTip:value]; + } + [self update]; } @@ -476,9 +474,6 @@ [self removeTrackingRect:[cell cellTrackingTag]]; } - // remove tool tip - [_toolTips removeObjectForKey:[NSValue valueWithPointer:[cell representedObject]]]; - // pull from collection [_cells removeObject:cell]; @@ -787,7 +782,7 @@ [cell setEnabled:YES]; // add tool tip - NSString *tt = [self toolTipForTabViewItem:tvi]; + NSString *tt = [cell toolTip]; if (tt && [tt length] > 0) [self addToolTipRect:cellRect owner:tt userData:NULL]; -- 2.11.4.GIT