Skip to content

Commit 90714ff

Browse files
committed
MMTabline: a new tabline for MacVim
1 parent f40fc7d commit 90714ff

File tree

132 files changed

+1255
-9356
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+1255
-9356
lines changed

runtime/doc/gui_mac.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ KEY VALUE ~
310310
*MMSmoothResize* allow smooth resizing of MacVim window [bool]
311311
*MMShareFindPboard* share search text to Find Pasteboard [bool]
312312
*MMShowAddTabButton* enable "add tab" button on tabline [bool]
313-
*MMTabMaxWidth* maximum width of a tab [int]
313+
*MMShowTabScrollButtons* enable tab scroll buttons on tabline [bool]
314314
*MMTabMinWidth* minimum width of a tab [int]
315315
*MMTabOptimumWidth* default width of a tab [int]
316316
*MMTextInsetBottom* text area offset in pixels [int]

runtime/doc/tags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5650,9 +5650,9 @@ MMRendererClipToRow gui_mac.txt /*MMRendererClipToRow*
56505650
MMScrollOneDirectionOnly gui_mac.txt /*MMScrollOneDirectionOnly*
56515651
MMShareFindPboard gui_mac.txt /*MMShareFindPboard*
56525652
MMShowAddTabButton gui_mac.txt /*MMShowAddTabButton*
5653+
MMShowTabScrollButtons gui_mac.txt /*MMShowTabScrollButtons*
56535654
MMShowWhatsNewOnStartup gui_mac.txt /*MMShowWhatsNewOnStartup*
56545655
MMSmoothResize gui_mac.txt /*MMSmoothResize*
5655-
MMTabMaxWidth gui_mac.txt /*MMTabMaxWidth*
56565656
MMTabMinWidth gui_mac.txt /*MMTabMinWidth*
56575657
MMTabOptimumWidth gui_mac.txt /*MMTabOptimumWidth*
56585658
MMTextInsetBottom gui_mac.txt /*MMTextInsetBottom*

src/MacVim/MMAppController.m

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,30 +172,14 @@ @implementation MMAppController
172172
/// persisted user settings to have a clean environment.
173173
+ (void)registerDefaults
174174
{
175-
int tabMinWidthKey;
176-
int tabMaxWidthKey;
177-
int tabOptimumWidthKey;
178-
if (shouldUseYosemiteTabBarStyle()) {
179-
tabMinWidthKey = 120;
180-
tabMaxWidthKey = 0;
181-
tabOptimumWidthKey = 0;
182-
} else {
183-
tabMinWidthKey = 64;
184-
tabMaxWidthKey = 6*64;
185-
tabOptimumWidthKey = 132;
186-
}
187-
188175
NSUserDefaults *ud = NSUserDefaults.standardUserDefaults;
189176

190177
NSDictionary *macvimDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
191178
[NSNumber numberWithBool:NO], MMNoWindowKey,
192-
[NSNumber numberWithInt:tabMinWidthKey],
193-
MMTabMinWidthKey,
194-
[NSNumber numberWithInt:tabMaxWidthKey],
195-
MMTabMaxWidthKey,
196-
[NSNumber numberWithInt:tabOptimumWidthKey],
197-
MMTabOptimumWidthKey,
179+
[NSNumber numberWithInt:120], MMTabMinWidthKey,
180+
[NSNumber numberWithInt:200], MMTabOptimumWidthKey,
198181
[NSNumber numberWithBool:YES], MMShowAddTabButtonKey,
182+
[NSNumber numberWithBool:NO], MMShowTabScrollButtonsKey,
199183
[NSNumber numberWithInt:2], MMTextInsetLeftKey,
200184
[NSNumber numberWithInt:1], MMTextInsetRightKey,
201185
[NSNumber numberWithInt:1], MMTextInsetTopKey,

src/MacVim/MMFullScreenWindow.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
NSWindow *target;
1919
MMVimView *view;
2020
NSPoint oldPosition;
21-
NSString *oldTabBarStyle;
2221
int options;
2322
int state;
2423

src/MacVim/MMFullScreenWindow.m

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#import "MMVimView.h"
3030
#import "MMWindowController.h"
3131
#import "Miscellaneous.h"
32-
#import <PSMTabBarControl/PSMTabBarControl.h>
3332

3433
// These have to be the same as in option.h
3534
#define FUOPT_MAXVERT 0x001
@@ -169,12 +168,6 @@ - (void)enterFullScreen
169168
// make target's window controller believe that it's now controlling us
170169
[[target windowController] setWindow:self];
171170

172-
oldTabBarStyle = [[view tabBarControl] styleName];
173-
174-
NSString *style =
175-
shouldUseYosemiteTabBarStyle() ? (shouldUseMojaveTabBarStyle() ? @"Mojave" : @"Yosemite") : @"Unified";
176-
[[view tabBarControl] setStyleNamed:style];
177-
178171
// add text view
179172
oldPosition = [view frame].origin;
180173

@@ -268,8 +261,6 @@ - (void)leaveFullScreen
268261
[self retain]; // NSWindowController releases us once
269262
[[self windowController] setWindow:target];
270263

271-
[[view tabBarControl] setStyleNamed:oldTabBarStyle];
272-
273264
// fix delegate
274265
id delegate = [self delegate];
275266
[self setDelegate:nil];

src/MacVim/MMTabline/MMHoverButton.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import <Cocoa/Cocoa.h>
2+
3+
// A button that fades in a circular background when hovered.
4+
5+
@interface MMHoverButton : NSButton
6+
7+
@property (nonatomic, retain) NSColor *fgColor;
8+
9+
+ (NSImage *)imageNamed:(NSString *)name;
10+
11+
@end

src/MacVim/MMTabline/MMHoverButton.m

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#import "MMHoverButton.h"
2+
3+
@implementation MMHoverButton
4+
{
5+
NSTrackingArea *_trackingArea;
6+
NSBox *_circle;
7+
}
8+
9+
+ (NSImage *)imageNamed:(NSString *)name
10+
{
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"]) {
15+
[p moveToPoint:NSMakePoint( 8.5, 4.5)];
16+
[p lineToPoint:NSMakePoint( 8.5, 12.5)];
17+
[p moveToPoint:NSMakePoint( 4.5, 8.5)];
18+
[p lineToPoint:NSMakePoint(12.5, 8.5)];
19+
[p setLineWidth:1.2];
20+
[p stroke];
21+
}
22+
else if ([name isEqualToString:@"CloseTabButton"]) {
23+
[p moveToPoint:NSMakePoint( 4.5, 4.5)];
24+
[p lineToPoint:NSMakePoint(10.5, 10.5)];
25+
[p moveToPoint:NSMakePoint( 4.5, 10.5)];
26+
[p lineToPoint:NSMakePoint(10.5, 4.5)];
27+
[p setLineWidth:1.2];
28+
[p stroke];
29+
}
30+
else if ([name isEqualToString:@"ScrollLeftButton"]) {
31+
[p moveToPoint:NSMakePoint( 5.0, 8.5)];
32+
[p lineToPoint:NSMakePoint(10.0, 4.5)];
33+
[p lineToPoint:NSMakePoint(10.0, 12.5)];
34+
[p fill];
35+
}
36+
else if ([name isEqualToString:@"ScrollRightButton"]) {
37+
[p moveToPoint:NSMakePoint(12.0, 8.5)];
38+
[p lineToPoint:NSMakePoint( 7.0, 4.5)];
39+
[p lineToPoint:NSMakePoint( 7.0, 12.5)];
40+
[p fill];
41+
}
42+
return YES;
43+
}];
44+
}
45+
46+
- (instancetype)initWithFrame:(NSRect)frameRect
47+
{
48+
self = [super initWithFrame:frameRect];
49+
if (self) {
50+
self.buttonType = NSButtonTypeMomentaryChange;
51+
self.bordered = NO;
52+
self.imagePosition = NSImageOnly;
53+
54+
// This view will fade in/out when hovered.
55+
_circle = [NSBox new];
56+
_circle.boxType = NSBoxCustom;
57+
_circle.borderWidth = 0;
58+
_circle.alphaValue = 0.16;
59+
_circle.fillColor = NSColor.clearColor;
60+
_circle.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
61+
_circle.frame = self.bounds;
62+
[self addSubview:_circle positioned:NSWindowBelow relativeTo:nil];
63+
}
64+
return self;
65+
}
66+
67+
- (void)setFgColor:(NSColor *)color
68+
{
69+
_fgColor = color;
70+
self.image = super.image;
71+
}
72+
73+
- (void)setImage:(NSImage *)image
74+
{
75+
_circle.cornerRadius = image.size.width / 2.0;
76+
NSColor *fillColor = self.fgColor ?: NSColor.controlTextColor;
77+
super.image = [NSImage imageWithSize:image.size flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
78+
[image drawInRect:dstRect];
79+
[fillColor set];
80+
NSRectFillUsingOperation(dstRect, NSCompositingOperationSourceAtop);
81+
return YES;
82+
}];
83+
self.alternateImage = [NSImage imageWithSize:image.size flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
84+
[[fillColor colorWithAlphaComponent:0.2] set];
85+
[[NSBezierPath bezierPathWithOvalInRect:dstRect] fill];
86+
[super.image drawInRect:dstRect];
87+
return YES;
88+
}];
89+
}
90+
91+
- (void)setEnabled:(BOOL)enabled
92+
{
93+
[super setEnabled:enabled];
94+
[self evaluateHover];
95+
}
96+
97+
- (void)updateTrackingAreas
98+
{
99+
[self removeTrackingArea:_trackingArea];
100+
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow) owner:self userInfo:nil];
101+
[self addTrackingArea:_trackingArea];
102+
[self evaluateHover];
103+
[super updateTrackingAreas];
104+
}
105+
106+
- (void)backgroundCircleShouldHighlight:(BOOL)shouldHighlight
107+
{
108+
NSColor *fillColor = NSColor.clearColor;
109+
if (shouldHighlight) {
110+
fillColor = self.fgColor ?: NSColor.controlTextColor;
111+
}
112+
[NSAnimationContext beginGrouping];
113+
[[NSAnimationContext currentContext] setDuration:0.1];
114+
_circle.animator.fillColor = fillColor;
115+
[NSAnimationContext endGrouping];
116+
}
117+
118+
- (void)evaluateHover
119+
{
120+
NSPoint mouseLocation = [self.window mouseLocationOutsideOfEventStream];
121+
mouseLocation = [self convertPoint:mouseLocation fromView:nil];
122+
if (NSPointInRect(mouseLocation, self.bounds)) {
123+
if (self.enabled) [self backgroundCircleShouldHighlight:YES];
124+
else [self backgroundCircleShouldHighlight:NO];
125+
} else {
126+
[self backgroundCircleShouldHighlight:NO];
127+
}
128+
}
129+
130+
- (void)mouseEntered:(NSEvent *)event
131+
{
132+
if (self.enabled) [self backgroundCircleShouldHighlight:YES];
133+
}
134+
135+
- (void)mouseExited:(NSEvent *)event
136+
{
137+
[self backgroundCircleShouldHighlight:NO];
138+
}
139+
140+
@end

src/MacVim/MMTabline/MMTab.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#import <Cocoa/Cocoa.h>
2+
3+
// A tab with a close button and title.
4+
5+
#define MMTabShadowBlurRadius (2)
6+
7+
typedef enum : NSInteger {
8+
MMTabStateSelected,
9+
MMTabStateUnselected,
10+
MMTabStateUnselectedHover,
11+
} MMTabState;
12+
13+
@class MMTabline;
14+
15+
@interface MMTab : NSView
16+
17+
@property (nonatomic, copy) NSString *title;
18+
@property (nonatomic, getter=isCloseButtonHidden) BOOL closeButtonHidden;
19+
@property (nonatomic) MMTabState state;
20+
21+
- (instancetype)initWithFrame:(NSRect)frameRect tabline:(MMTabline *)tabline;
22+
23+
@end

0 commit comments

Comments
 (0)