Skip to content

Commit

Permalink
Merge pull request #1536 from ychin/mmtabs-add-scrollbutton-prefs-oth…
Browse files Browse the repository at this point in the history
…er-fixups

Tabs: Expose option to show scroll tab buttons, fix tab scroll behavior, fix memory leaks, cache images and other cleanups
  • Loading branch information
ychin authored Jan 29, 2025
2 parents dffce69 + 18f00e5 commit 018ee0f
Show file tree
Hide file tree
Showing 18 changed files with 287 additions and 82 deletions.
8 changes: 6 additions & 2 deletions runtime/doc/gui_mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ KEY VALUE ~
*MMDialogsTrackPwd* open/save dialogs track the Vim pwd [bool]
*MMDisableLaunchAnimation* disable launch animation when opening a new
MacVim window [bool]
*MMDisableTablineAnimation* disable animation in GUI tabs [bool]
*MMFontPreserveLineSpacing* use the line-spacing as specified by font [bool]
*MMLoginShell* use login shell for launching Vim [bool]
*MMLoginShellArgument* login shell parameter [string]
Expand Down Expand Up @@ -573,8 +574,11 @@ _cycleWindows: Select next window (similar to <D-`>)
_cycleWindowsBackwards: Select previous window (similar to <D-S-`>)
_removeWindowFromStageManagerSet Remove window from a Stage Manager Set. Same
as the "Remove Window from Set" menu item.
joinAllStageManagerSets Window will float among all Stage Manager sets
unjoinAllStageManagerSets Window will only show up in its own set
joinAllStageManagerSets: Window will float among all Stage Manager sets
unjoinAllStageManagerSets: Window will only show up in its own set
scrollToCurrentTab: Scroll to the selected tab in the GUI tab bar
scrollBackwardOneTab: Scroll backward by one tab in the tab bar
scrollForwardOneTab: Scroll forward by one tab in the tab bar

==============================================================================
7. Toolbar *macvim-toolbar*
Expand Down
1 change: 1 addition & 0 deletions runtime/doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -5648,6 +5648,7 @@ MMCmdLineAlignBottom gui_mac.txt /*MMCmdLineAlignBottom*
MMDefaultTablineColors gui_mac.txt /*MMDefaultTablineColors*
MMDialogsTrackPwd gui_mac.txt /*MMDialogsTrackPwd*
MMDisableLaunchAnimation gui_mac.txt /*MMDisableLaunchAnimation*
MMDisableTablineAnimation gui_mac.txt /*MMDisableTablineAnimation*
MMFontPreserveLineSpacing gui_mac.txt /*MMFontPreserveLineSpacing*
MMFullScreenFadeTime gui_mac.txt /*MMFullScreenFadeTime*
MMLoginShell gui_mac.txt /*MMLoginShell*
Expand Down
6 changes: 6 additions & 0 deletions src/MacVim/Actions.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<string></string>
<key>addNewTab:</key>
<string></string>
<key>scrollToCurrentTab:</key>
<string></string>
<key>scrollBackwardOneTab:</key>
<string></string>
<key>scrollForwardOneTab:</key>
<string></string>
<key>arrangeInFront:</key>
<string></string>
<key>clearRecentDocuments:</key>
Expand Down
37 changes: 32 additions & 5 deletions src/MacVim/Base.lproj/Preferences.xib
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@
<point key="canvasLocation" x="137.5" y="-17"/>
</customView>
<customView id="hr4-G4-3ZG" userLabel="Appearance">
<rect key="frame" x="0.0" y="0.0" width="483" height="379"/>
<rect key="frame" x="0.0" y="0.0" width="483" height="405"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<customView id="fw0-VK-Nbz" userLabel="Dark mode selection">
<rect key="frame" x="19" y="201" width="433" height="156"/>
<rect key="frame" x="19" y="227" width="433" height="156"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="T40-Os-PUf" userLabel="Dark mode selection">
Expand Down Expand Up @@ -345,7 +345,7 @@
</subviews>
</customView>
<customView id="7af-iK-4r7" userLabel="Titlebar appearance">
<rect key="frame" x="19" y="118" width="433" height="75"/>
<rect key="frame" x="19" y="144" width="433" height="75"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="9Rk-gT-kVC" userLabel="Titlebar appearance">
Expand Down Expand Up @@ -407,6 +407,33 @@
</button>
</subviews>
</customView>
<customView id="C3B-cu-RC2" userLabel="Tabs">
<rect key="frame" x="20" y="118" width="432" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button id="rCZ-9B-5RL">
<rect key="frame" x="189" y="-1" width="244" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Show scroll buttons" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="Yqp-j5-BpX">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="tabsPropertiesChanged:" target="-1" id="5xm-T0-e3B"/>
<binding destination="58" name="value" keyPath="values.MMShowTabScrollButtons" id="KHi-zu-Jz2"/>
</connections>
</button>
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="qMc-Md-UwA" userLabel="Tabs">
<rect key="frame" x="-2" y="0.0" width="187" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Tabs:" id="iUO-3c-iff" userLabel="Tabs:">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</customView>
<customView id="BpJ-rH-ona" userLabel="Full Screen">
<rect key="frame" x="19" y="72" width="433" height="38"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
Expand Down Expand Up @@ -508,7 +535,7 @@
</subviews>
</customView>
</subviews>
<point key="canvasLocation" x="137.5" y="444.5"/>
<point key="canvasLocation" x="137.5" y="457.5"/>
</customView>
<customView id="Bnq-Nx-GJH" userLabel="Input">
<rect key="frame" x="0.0" y="0.0" width="483" height="110"/>
Expand Down Expand Up @@ -595,7 +622,7 @@
</subviews>
</customView>
</subviews>
<point key="canvasLocation" x="137.5" y="705"/>
<point key="canvasLocation" x="138" y="775"/>
</customView>
<customView id="620" userLabel="Advanced">
<rect key="frame" x="0.0" y="0.0" width="483" height="367"/>
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMAppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
- (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args;

- (void)refreshAllAppearances;
- (void)refreshAllTabProperties;
- (void)refreshAllFonts;
- (void)refreshAllResizeConstraints;
- (void)refreshAllTextViews;
Expand Down
24 changes: 12 additions & 12 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ + (void)registerDefaults
MMUntitledWindowKey,
[NSNumber numberWithBool:NO], MMNoWindowShadowKey,
[NSNumber numberWithBool:NO], MMDisableLaunchAnimationKey,
[NSNumber numberWithBool:NO], MMDisableTablineAnimationKey,
[NSNumber numberWithInt:0], MMAppearanceModeSelectionKey,
[NSNumber numberWithBool:NO], MMNoTitleBarWindowKey,
[NSNumber numberWithBool:NO], MMTitlebarAppearsTransparentKey,
Expand Down Expand Up @@ -1229,19 +1230,22 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args

- (void)refreshAllAppearances
{
const NSUInteger count = [vimControllers count];
for (unsigned i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
for (MMVimController *vc in vimControllers) {
[vc.windowController refreshApperanceMode];
}
}

- (void)refreshAllTabProperties
{
for (MMVimController *vc in vimControllers) {
[vc.windowController.vimView refreshTabProperties];
}
}

/// Refresh all Vim text views' fonts.
- (void)refreshAllFonts
{
const NSUInteger count = [vimControllers count];
for (unsigned i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
for (MMVimController *vc in vimControllers) {
[vc.windowController refreshFonts];
}
}
Expand All @@ -1250,9 +1254,7 @@ - (void)refreshAllFonts
/// and resize the windows to match the constraints.
- (void)refreshAllResizeConstraints
{
const NSUInteger count = [vimControllers count];
for (unsigned i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
for (MMVimController *vc in vimControllers) {
[vc.windowController updateResizeConstraints:YES];
}
}
Expand All @@ -1261,9 +1263,7 @@ - (void)refreshAllResizeConstraints
/// cmdline alignment properties to make sure they are pinned properly.
- (void)refreshAllTextViews
{
const NSUInteger count = [vimControllers count];
for (unsigned i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
for (MMVimController *vc in vimControllers) {
[vc.windowController.vimView.textView updateCmdlineRow];
vc.windowController.vimView.textView.needsDisplay = YES;
}
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMPreferenceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@

// Appearance pane
- (IBAction)fontPropertiesChanged:(id)sender;
- (IBAction)tabsPropertiesChanged:(id)sender;

@end
5 changes: 5 additions & 0 deletions src/MacVim/MMPreferenceController.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ - (IBAction)fontPropertiesChanged:(id)sender
[[MMAppController sharedInstance] refreshAllFonts];
}

- (IBAction)tabsPropertiesChanged:(id)sender
{
[[MMAppController sharedInstance] refreshAllTabProperties];
}

- (IBAction)smoothResizeChanged:(id)sender
{
[[MMAppController sharedInstance] refreshAllResizeConstraints];
Expand Down
10 changes: 9 additions & 1 deletion src/MacVim/MMTabline/MMHoverButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

@property (nonatomic, retain) NSColor *fgColor;

+ (NSImage *)imageNamed:(NSString *)name;
typedef enum : NSUInteger {
MMHoverButtonImageAddTab = 0,
MMHoverButtonImageCloseTab,
MMHoverButtonImageScrollLeft,
MMHoverButtonImageScrollRight,
MMHoverButtonImageCount
} MMHoverButtonImage;

+ (NSImage *)imageFromType:(MMHoverButtonImage)imageType;

@end
67 changes: 48 additions & 19 deletions src/MacVim/MMTabline/MMHoverButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,64 @@ @implementation MMHoverButton
NSBox *_circle;
}

+ (NSImage *)imageNamed:(NSString *)name
+ (NSImage *)imageFromType:(MMHoverButtonImage)imageType
{
CGFloat size = [name isEqualToString:@"CloseTabButton"] ? 15 : 17;
return [NSImage imageWithSize:NSMakeSize(size, size) flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
NSBezierPath *p = [NSBezierPath new];
if ([name isEqualToString:@"AddTabButton"]) {
if (imageType >= MMHoverButtonImageCount)
return nil;

CGFloat size = imageType == MMHoverButtonImageCloseTab ? 15 : 17;

static __weak NSImage *imageCache[MMHoverButtonImageCount] = { nil };
if (imageCache[imageType] != nil)
return imageCache[imageType];

BOOL (^drawFuncs[MMHoverButtonImageCount])(NSRect) = {
// AddTab
^BOOL(NSRect dstRect) {
NSBezierPath *p = [NSBezierPath new];
[p moveToPoint:NSMakePoint( 8.5, 4.5)];
[p lineToPoint:NSMakePoint( 8.5, 12.5)];
[p moveToPoint:NSMakePoint( 4.5, 8.5)];
[p lineToPoint:NSMakePoint(12.5, 8.5)];
[p setLineWidth:1.2];
[p stroke];
}
else if ([name isEqualToString:@"CloseTabButton"]) {
return YES;
},
// CloseTab
^BOOL(NSRect dstRect) {
NSBezierPath *p = [NSBezierPath new];
[p moveToPoint:NSMakePoint( 4.5, 4.5)];
[p lineToPoint:NSMakePoint(10.5, 10.5)];
[p moveToPoint:NSMakePoint( 4.5, 10.5)];
[p lineToPoint:NSMakePoint(10.5, 4.5)];
[p setLineWidth:1.2];
[p stroke];
}
else if ([name isEqualToString:@"ScrollLeftButton"]) {
return YES;
},
// ScrollLeft
^BOOL(NSRect dstRect) {
NSBezierPath *p = [NSBezierPath new];
[p moveToPoint:NSMakePoint( 5.0, 8.5)];
[p lineToPoint:NSMakePoint(10.0, 4.5)];
[p lineToPoint:NSMakePoint(10.0, 12.5)];
[p fill];
}
else if ([name isEqualToString:@"ScrollRightButton"]) {
return YES;
},
// ScrollRight
^BOOL(NSRect dstRect) {
NSBezierPath *p = [NSBezierPath new];
[p moveToPoint:NSMakePoint(12.0, 8.5)];
[p lineToPoint:NSMakePoint( 7.0, 4.5)];
[p lineToPoint:NSMakePoint( 7.0, 12.5)];
[p fill];
return YES;
}
return YES;
}];
};
NSImage *img = [NSImage imageWithSize:NSMakeSize(size, size)
flipped:NO
drawingHandler:drawFuncs[imageType]];
imageCache[imageType] = img;
return img;
}

- (instancetype)initWithFrame:(NSRect)frameRect
Expand Down Expand Up @@ -70,22 +93,28 @@ - (void)setFgColor:(NSColor *)color
self.image = super.image;
}

- (void)setImage:(NSImage *)image
- (void)setImage:(NSImage *)imageTemplate
{
_circle.cornerRadius = image.size.width / 2.0;
_circle.cornerRadius = imageTemplate.size.width / 2.0;
NSColor *fillColor = self.fgColor ?: NSColor.controlTextColor;
super.image = [NSImage imageWithSize:image.size flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
[image drawInRect:dstRect];
NSImage *image = [NSImage imageWithSize:imageTemplate.size
flipped:NO
drawingHandler:^BOOL(NSRect dstRect) {
[imageTemplate drawInRect:dstRect];
[fillColor set];
NSRectFillUsingOperation(dstRect, NSCompositingOperationSourceAtop);
return YES;
}];
self.alternateImage = [NSImage imageWithSize:image.size flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
NSImage *alternateImage = [NSImage imageWithSize:imageTemplate.size
flipped:NO
drawingHandler:^BOOL(NSRect dstRect) {
[[fillColor colorWithAlphaComponent:0.2] set];
[[NSBezierPath bezierPathWithOvalInRect:dstRect] fill];
[super.image drawInRect:dstRect];
[image drawInRect:dstRect];
return YES;
}];
super.image = image;
self.alternateImage = alternateImage;
}

- (void)setEnabled:(BOOL)enabled
Expand Down
2 changes: 1 addition & 1 deletion src/MacVim/MMTabline/MMTab.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (instancetype)initWithFrame:(NSRect)frameRect tabline:(MMTabline *)tabline
_tabline = tabline;

_closeButton = [MMHoverButton new];
_closeButton.image = [MMHoverButton imageNamed:@"CloseTabButton"];
_closeButton.image = [MMHoverButton imageFromType:MMHoverButtonImageCloseTab];
_closeButton.target = self;
_closeButton.action = @selector(closeTab:);
_closeButton.translatesAutoresizingMaskIntoConstraints = NO;
Expand Down
4 changes: 4 additions & 0 deletions src/MacVim/MMTabline/MMTabline.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@property (nonatomic) NSInteger minimumTabWidth;
@property (nonatomic) BOOL showsAddTabButton;
@property (nonatomic) BOOL showsTabScrollButtons;
@property (nonatomic) BOOL useAnimation;
@property (nonatomic, readonly) NSInteger numberOfTabs;
@property (nonatomic, retain, readonly) MMHoverButton *addTabButton;
@property (nonatomic, retain) NSColor *tablineBgColor;
Expand All @@ -33,6 +34,7 @@
- (NSInteger)addTabAtIndex:(NSInteger)index;

- (void)closeTab:(MMTab *)tab force:(BOOL)force layoutImmediately:(BOOL)layoutImmediately;
- (void)closeAllTabs;

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

@end
Expand Down
Loading

0 comments on commit 018ee0f

Please sign in to comment.