Skip to content

Commit 018ee0f

Browse files
authored
Merge pull request #1536 from ychin/mmtabs-add-scrollbutton-prefs-other-fixups
Tabs: Expose option to show scroll tab buttons, fix tab scroll behavior, fix memory leaks, cache images and other cleanups
2 parents dffce69 + 18f00e5 commit 018ee0f

18 files changed

+287
-82
lines changed

runtime/doc/gui_mac.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ KEY VALUE ~
290290
*MMDialogsTrackPwd* open/save dialogs track the Vim pwd [bool]
291291
*MMDisableLaunchAnimation* disable launch animation when opening a new
292292
MacVim window [bool]
293+
*MMDisableTablineAnimation* disable animation in GUI tabs [bool]
293294
*MMFontPreserveLineSpacing* use the line-spacing as specified by font [bool]
294295
*MMLoginShell* use login shell for launching Vim [bool]
295296
*MMLoginShellArgument* login shell parameter [string]
@@ -573,8 +574,11 @@ _cycleWindows: Select next window (similar to <D-`>)
573574
_cycleWindowsBackwards: Select previous window (similar to <D-S-`>)
574575
_removeWindowFromStageManagerSet Remove window from a Stage Manager Set. Same
575576
as the "Remove Window from Set" menu item.
576-
joinAllStageManagerSets Window will float among all Stage Manager sets
577-
unjoinAllStageManagerSets Window will only show up in its own set
577+
joinAllStageManagerSets: Window will float among all Stage Manager sets
578+
unjoinAllStageManagerSets: Window will only show up in its own set
579+
scrollToCurrentTab: Scroll to the selected tab in the GUI tab bar
580+
scrollBackwardOneTab: Scroll backward by one tab in the tab bar
581+
scrollForwardOneTab: Scroll forward by one tab in the tab bar
578582

579583
==============================================================================
580584
7. Toolbar *macvim-toolbar*

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5648,6 +5648,7 @@ MMCmdLineAlignBottom gui_mac.txt /*MMCmdLineAlignBottom*
56485648
MMDefaultTablineColors gui_mac.txt /*MMDefaultTablineColors*
56495649
MMDialogsTrackPwd gui_mac.txt /*MMDialogsTrackPwd*
56505650
MMDisableLaunchAnimation gui_mac.txt /*MMDisableLaunchAnimation*
5651+
MMDisableTablineAnimation gui_mac.txt /*MMDisableTablineAnimation*
56515652
MMFontPreserveLineSpacing gui_mac.txt /*MMFontPreserveLineSpacing*
56525653
MMFullScreenFadeTime gui_mac.txt /*MMFullScreenFadeTime*
56535654
MMLoginShell gui_mac.txt /*MMLoginShell*

src/MacVim/Actions.plist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
<string></string>
99
<key>addNewTab:</key>
1010
<string></string>
11+
<key>scrollToCurrentTab:</key>
12+
<string></string>
13+
<key>scrollBackwardOneTab:</key>
14+
<string></string>
15+
<key>scrollForwardOneTab:</key>
16+
<string></string>
1117
<key>arrangeInFront:</key>
1218
<string></string>
1319
<key>clearRecentDocuments:</key>

src/MacVim/Base.lproj/Preferences.xib

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,11 @@
280280
<point key="canvasLocation" x="137.5" y="-17"/>
281281
</customView>
282282
<customView id="hr4-G4-3ZG" userLabel="Appearance">
283-
<rect key="frame" x="0.0" y="0.0" width="483" height="379"/>
283+
<rect key="frame" x="0.0" y="0.0" width="483" height="405"/>
284284
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
285285
<subviews>
286286
<customView id="fw0-VK-Nbz" userLabel="Dark mode selection">
287-
<rect key="frame" x="19" y="201" width="433" height="156"/>
287+
<rect key="frame" x="19" y="227" width="433" height="156"/>
288288
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
289289
<subviews>
290290
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="T40-Os-PUf" userLabel="Dark mode selection">
@@ -345,7 +345,7 @@
345345
</subviews>
346346
</customView>
347347
<customView id="7af-iK-4r7" userLabel="Titlebar appearance">
348-
<rect key="frame" x="19" y="118" width="433" height="75"/>
348+
<rect key="frame" x="19" y="144" width="433" height="75"/>
349349
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
350350
<subviews>
351351
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="9Rk-gT-kVC" userLabel="Titlebar appearance">
@@ -407,6 +407,33 @@
407407
</button>
408408
</subviews>
409409
</customView>
410+
<customView id="C3B-cu-RC2" userLabel="Tabs">
411+
<rect key="frame" x="20" y="118" width="432" height="18"/>
412+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
413+
<subviews>
414+
<button id="rCZ-9B-5RL">
415+
<rect key="frame" x="189" y="-1" width="244" height="18"/>
416+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
417+
<buttonCell key="cell" type="check" title="Show scroll buttons" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="Yqp-j5-BpX">
418+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
419+
<font key="font" metaFont="system"/>
420+
</buttonCell>
421+
<connections>
422+
<action selector="tabsPropertiesChanged:" target="-1" id="5xm-T0-e3B"/>
423+
<binding destination="58" name="value" keyPath="values.MMShowTabScrollButtons" id="KHi-zu-Jz2"/>
424+
</connections>
425+
</button>
426+
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="qMc-Md-UwA" userLabel="Tabs">
427+
<rect key="frame" x="-2" y="0.0" width="187" height="17"/>
428+
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
429+
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Tabs:" id="iUO-3c-iff" userLabel="Tabs:">
430+
<font key="font" metaFont="system"/>
431+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
432+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
433+
</textFieldCell>
434+
</textField>
435+
</subviews>
436+
</customView>
410437
<customView id="BpJ-rH-ona" userLabel="Full Screen">
411438
<rect key="frame" x="19" y="72" width="433" height="38"/>
412439
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
@@ -508,7 +535,7 @@
508535
</subviews>
509536
</customView>
510537
</subviews>
511-
<point key="canvasLocation" x="137.5" y="444.5"/>
538+
<point key="canvasLocation" x="137.5" y="457.5"/>
512539
</customView>
513540
<customView id="Bnq-Nx-GJH" userLabel="Input">
514541
<rect key="frame" x="0.0" y="0.0" width="483" height="110"/>
@@ -595,7 +622,7 @@
595622
</subviews>
596623
</customView>
597624
</subviews>
598-
<point key="canvasLocation" x="137.5" y="705"/>
625+
<point key="canvasLocation" x="138" y="775"/>
599626
</customView>
600627
<customView id="620" userLabel="Advanced">
601628
<rect key="frame" x="0.0" y="0.0" width="483" height="367"/>

src/MacVim/MMAppController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
- (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args;
8585

8686
- (void)refreshAllAppearances;
87+
- (void)refreshAllTabProperties;
8788
- (void)refreshAllFonts;
8889
- (void)refreshAllResizeConstraints;
8990
- (void)refreshAllTextViews;

src/MacVim/MMAppController.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ + (void)registerDefaults
196196
MMUntitledWindowKey,
197197
[NSNumber numberWithBool:NO], MMNoWindowShadowKey,
198198
[NSNumber numberWithBool:NO], MMDisableLaunchAnimationKey,
199+
[NSNumber numberWithBool:NO], MMDisableTablineAnimationKey,
199200
[NSNumber numberWithInt:0], MMAppearanceModeSelectionKey,
200201
[NSNumber numberWithBool:NO], MMNoTitleBarWindowKey,
201202
[NSNumber numberWithBool:NO], MMTitlebarAppearsTransparentKey,
@@ -1229,19 +1230,22 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args
12291230

12301231
- (void)refreshAllAppearances
12311232
{
1232-
const NSUInteger count = [vimControllers count];
1233-
for (unsigned i = 0; i < count; ++i) {
1234-
MMVimController *vc = [vimControllers objectAtIndex:i];
1233+
for (MMVimController *vc in vimControllers) {
12351234
[vc.windowController refreshApperanceMode];
12361235
}
12371236
}
12381237

1238+
- (void)refreshAllTabProperties
1239+
{
1240+
for (MMVimController *vc in vimControllers) {
1241+
[vc.windowController.vimView refreshTabProperties];
1242+
}
1243+
}
1244+
12391245
/// Refresh all Vim text views' fonts.
12401246
- (void)refreshAllFonts
12411247
{
1242-
const NSUInteger count = [vimControllers count];
1243-
for (unsigned i = 0; i < count; ++i) {
1244-
MMVimController *vc = [vimControllers objectAtIndex:i];
1248+
for (MMVimController *vc in vimControllers) {
12451249
[vc.windowController refreshFonts];
12461250
}
12471251
}
@@ -1250,9 +1254,7 @@ - (void)refreshAllFonts
12501254
/// and resize the windows to match the constraints.
12511255
- (void)refreshAllResizeConstraints
12521256
{
1253-
const NSUInteger count = [vimControllers count];
1254-
for (unsigned i = 0; i < count; ++i) {
1255-
MMVimController *vc = [vimControllers objectAtIndex:i];
1257+
for (MMVimController *vc in vimControllers) {
12561258
[vc.windowController updateResizeConstraints:YES];
12571259
}
12581260
}
@@ -1261,9 +1263,7 @@ - (void)refreshAllResizeConstraints
12611263
/// cmdline alignment properties to make sure they are pinned properly.
12621264
- (void)refreshAllTextViews
12631265
{
1264-
const NSUInteger count = [vimControllers count];
1265-
for (unsigned i = 0; i < count; ++i) {
1266-
MMVimController *vc = [vimControllers objectAtIndex:i];
1266+
for (MMVimController *vc in vimControllers) {
12671267
[vc.windowController.vimView.textView updateCmdlineRow];
12681268
vc.windowController.vimView.textView.needsDisplay = YES;
12691269
}

src/MacVim/MMPreferenceController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939

4040
// Appearance pane
4141
- (IBAction)fontPropertiesChanged:(id)sender;
42+
- (IBAction)tabsPropertiesChanged:(id)sender;
4243

4344
@end

src/MacVim/MMPreferenceController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ - (IBAction)fontPropertiesChanged:(id)sender
167167
[[MMAppController sharedInstance] refreshAllFonts];
168168
}
169169

170+
- (IBAction)tabsPropertiesChanged:(id)sender
171+
{
172+
[[MMAppController sharedInstance] refreshAllTabProperties];
173+
}
174+
170175
- (IBAction)smoothResizeChanged:(id)sender
171176
{
172177
[[MMAppController sharedInstance] refreshAllResizeConstraints];

src/MacVim/MMTabline/MMHoverButton.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
@property (nonatomic, retain) NSColor *fgColor;
88

9-
+ (NSImage *)imageNamed:(NSString *)name;
9+
typedef enum : NSUInteger {
10+
MMHoverButtonImageAddTab = 0,
11+
MMHoverButtonImageCloseTab,
12+
MMHoverButtonImageScrollLeft,
13+
MMHoverButtonImageScrollRight,
14+
MMHoverButtonImageCount
15+
} MMHoverButtonImage;
16+
17+
+ (NSImage *)imageFromType:(MMHoverButtonImage)imageType;
1018

1119
@end

src/MacVim/MMTabline/MMHoverButton.m

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,64 @@ @implementation MMHoverButton
66
NSBox *_circle;
77
}
88

9-
+ (NSImage *)imageNamed:(NSString *)name
9+
+ (NSImage *)imageFromType:(MMHoverButtonImage)imageType
1010
{
11-
CGFloat size = [name isEqualToString:@"CloseTabButton"] ? 15 : 17;
12-
return [NSImage imageWithSize:NSMakeSize(size, size) flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
13-
NSBezierPath *p = [NSBezierPath new];
14-
if ([name isEqualToString:@"AddTabButton"]) {
11+
if (imageType >= MMHoverButtonImageCount)
12+
return nil;
13+
14+
CGFloat size = imageType == MMHoverButtonImageCloseTab ? 15 : 17;
15+
16+
static __weak NSImage *imageCache[MMHoverButtonImageCount] = { nil };
17+
if (imageCache[imageType] != nil)
18+
return imageCache[imageType];
19+
20+
BOOL (^drawFuncs[MMHoverButtonImageCount])(NSRect) = {
21+
// AddTab
22+
^BOOL(NSRect dstRect) {
23+
NSBezierPath *p = [NSBezierPath new];
1524
[p moveToPoint:NSMakePoint( 8.5, 4.5)];
1625
[p lineToPoint:NSMakePoint( 8.5, 12.5)];
1726
[p moveToPoint:NSMakePoint( 4.5, 8.5)];
1827
[p lineToPoint:NSMakePoint(12.5, 8.5)];
1928
[p setLineWidth:1.2];
2029
[p stroke];
21-
}
22-
else if ([name isEqualToString:@"CloseTabButton"]) {
30+
return YES;
31+
},
32+
// CloseTab
33+
^BOOL(NSRect dstRect) {
34+
NSBezierPath *p = [NSBezierPath new];
2335
[p moveToPoint:NSMakePoint( 4.5, 4.5)];
2436
[p lineToPoint:NSMakePoint(10.5, 10.5)];
2537
[p moveToPoint:NSMakePoint( 4.5, 10.5)];
2638
[p lineToPoint:NSMakePoint(10.5, 4.5)];
2739
[p setLineWidth:1.2];
2840
[p stroke];
29-
}
30-
else if ([name isEqualToString:@"ScrollLeftButton"]) {
41+
return YES;
42+
},
43+
// ScrollLeft
44+
^BOOL(NSRect dstRect) {
45+
NSBezierPath *p = [NSBezierPath new];
3146
[p moveToPoint:NSMakePoint( 5.0, 8.5)];
3247
[p lineToPoint:NSMakePoint(10.0, 4.5)];
3348
[p lineToPoint:NSMakePoint(10.0, 12.5)];
3449
[p fill];
35-
}
36-
else if ([name isEqualToString:@"ScrollRightButton"]) {
50+
return YES;
51+
},
52+
// ScrollRight
53+
^BOOL(NSRect dstRect) {
54+
NSBezierPath *p = [NSBezierPath new];
3755
[p moveToPoint:NSMakePoint(12.0, 8.5)];
3856
[p lineToPoint:NSMakePoint( 7.0, 4.5)];
3957
[p lineToPoint:NSMakePoint( 7.0, 12.5)];
4058
[p fill];
59+
return YES;
4160
}
42-
return YES;
43-
}];
61+
};
62+
NSImage *img = [NSImage imageWithSize:NSMakeSize(size, size)
63+
flipped:NO
64+
drawingHandler:drawFuncs[imageType]];
65+
imageCache[imageType] = img;
66+
return img;
4467
}
4568

4669
- (instancetype)initWithFrame:(NSRect)frameRect
@@ -70,22 +93,28 @@ - (void)setFgColor:(NSColor *)color
7093
self.image = super.image;
7194
}
7295

73-
- (void)setImage:(NSImage *)image
96+
- (void)setImage:(NSImage *)imageTemplate
7497
{
75-
_circle.cornerRadius = image.size.width / 2.0;
98+
_circle.cornerRadius = imageTemplate.size.width / 2.0;
7699
NSColor *fillColor = self.fgColor ?: NSColor.controlTextColor;
77-
super.image = [NSImage imageWithSize:image.size flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
78-
[image drawInRect:dstRect];
100+
NSImage *image = [NSImage imageWithSize:imageTemplate.size
101+
flipped:NO
102+
drawingHandler:^BOOL(NSRect dstRect) {
103+
[imageTemplate drawInRect:dstRect];
79104
[fillColor set];
80105
NSRectFillUsingOperation(dstRect, NSCompositingOperationSourceAtop);
81106
return YES;
82107
}];
83-
self.alternateImage = [NSImage imageWithSize:image.size flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
108+
NSImage *alternateImage = [NSImage imageWithSize:imageTemplate.size
109+
flipped:NO
110+
drawingHandler:^BOOL(NSRect dstRect) {
84111
[[fillColor colorWithAlphaComponent:0.2] set];
85112
[[NSBezierPath bezierPathWithOvalInRect:dstRect] fill];
86-
[super.image drawInRect:dstRect];
113+
[image drawInRect:dstRect];
87114
return YES;
88115
}];
116+
super.image = image;
117+
self.alternateImage = alternateImage;
89118
}
90119

91120
- (void)setEnabled:(BOOL)enabled

src/MacVim/MMTabline/MMTab.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ - (instancetype)initWithFrame:(NSRect)frameRect tabline:(MMTabline *)tabline
3939
_tabline = tabline;
4040

4141
_closeButton = [MMHoverButton new];
42-
_closeButton.image = [MMHoverButton imageNamed:@"CloseTabButton"];
42+
_closeButton.image = [MMHoverButton imageFromType:MMHoverButtonImageCloseTab];
4343
_closeButton.target = self;
4444
_closeButton.action = @selector(closeTab:);
4545
_closeButton.translatesAutoresizingMaskIntoConstraints = NO;

src/MacVim/MMTabline/MMTabline.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@property (nonatomic) NSInteger minimumTabWidth;
1717
@property (nonatomic) BOOL showsAddTabButton;
1818
@property (nonatomic) BOOL showsTabScrollButtons;
19+
@property (nonatomic) BOOL useAnimation;
1920
@property (nonatomic, readonly) NSInteger numberOfTabs;
2021
@property (nonatomic, retain, readonly) MMHoverButton *addTabButton;
2122
@property (nonatomic, retain) NSColor *tablineBgColor;
@@ -33,6 +34,7 @@
3334
- (NSInteger)addTabAtIndex:(NSInteger)index;
3435

3536
- (void)closeTab:(MMTab *)tab force:(BOOL)force layoutImmediately:(BOOL)layoutImmediately;
37+
- (void)closeAllTabs;
3638

3739
/// Batch update all the tabs using tab tags as unique IDs. Tab line will handle
3840
/// creating / removing tabs as necessary, and moving tabs to their new
@@ -53,6 +55,8 @@
5355
- (void)selectTabAtIndex:(NSInteger)index;
5456
- (MMTab *)tabAtIndex:(NSInteger)index;
5557
- (void)scrollTabToVisibleAtIndex:(NSInteger)index;
58+
- (void)scrollLeftOneTab;
59+
- (void)scrollRightOneTab;
5660
- (void)setTablineSelBackground:(NSColor *)back foreground:(NSColor *)fore;
5761

5862
@end

0 commit comments

Comments
 (0)