Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ThirdParty/PSMTabBarControl/source/PSMTabBarControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ typedef NS_ENUM(int, PSMTabPosition) {
PSMTab_LeftTab = 2,
};

extern const CGFloat PSMTabBarProgressBarHeight;

// This view provides a control interface to manage a regular NSTabView. It looks and works like
// the tabbed browsing interface of many popular browsers.
@interface PSMTabBarControl : NSControl<
Expand Down Expand Up @@ -256,6 +258,9 @@ typedef NS_ENUM(int, PSMTabPosition) {

- (void)setIsProcessing:(BOOL)isProcessing forTabWithIdentifier:(id)identifier;
- (void)setProgress:(PSMProgress)progress forTabWithIdentifier:(id)identifier;
- (BOOL)shouldShowCustomProgressBarForTabCell:(PSMTabBarCell *)cell;
- (nullable NSView *)customProgressBarViewForTabCell:(PSMTabBarCell *)cell;
- (void)configureCustomProgressBarView:(NSView *)view forTabCell:(PSMTabBarCell *)cell;
- (void)setIcon:(NSImage *)icon forTabWithIdentifier:(id)identifier;
- (void)setObjectCount:(NSInteger)objectCount forTabWithIdentifier:(id)identifier;
- (void)graphicDidChangeForTabWithIdentifier:(id)identifier;
Expand Down
81 changes: 81 additions & 0 deletions ThirdParty/PSMTabBarControl/source/PSMTabBarControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static os_log_t PSMTabBarLog(void) {
NSString *const PSMTabDragDidEndNotification = @"PSMTabDragDidEndNotification";
NSString *const PSMTabDragDidBeginNotification = @"PSMTabDragDidBeginNotification";
const CGFloat kSPMTabBarCellInternalXMargin = 6;
const CGFloat PSMTabBarProgressBarHeight = 2;

const CGFloat kPSMTabBarCellPadding = 4;
const CGFloat kPSMTabBarCellIconPadding = 4;
Expand Down Expand Up @@ -140,6 +141,8 @@ - (BOOL)isEqual:(id)object {
@end

@interface PSMTabBarControl ()<PSMTabBarControlProtocol, NSMenuItemValidation, NSViewToolTipOwner>
- (void)removeTabProgressBarForCell:(PSMTabBarCell *)cell;
- (void)syncTabProgressBars;
@end

@implementation PSMTabBarControl {
Expand Down Expand Up @@ -177,6 +180,7 @@ @implementation PSMTabBarControl {
BOOL _needsUpdateAnimate;
BOOL _needsUpdate;
NSInteger _preDragSelectedTabIndex; // or NSNotFound
NSMutableDictionary<NSValue *, NSView *> *_tabProgressBars;
NSMutableArray<PSMToolTip *> *_tooltips;
NSInteger _toolTipCoalescing;
}
Expand Down Expand Up @@ -251,6 +255,7 @@ - (id)initWithFrame:(NSRect)frame {
_style = [[PSMYosemiteTabStyle alloc] init];
}
_preDragSelectedTabIndex = NSNotFound;
_tabProgressBars = [[NSMutableDictionary alloc] init];

// the overflow button/menu
[self setupButtons];
Expand Down Expand Up @@ -376,6 +381,10 @@ - (void)dealloc {
[cell release];
}

for (NSView *progressBar in _tabProgressBars.allValues) {
[progressBar removeFromSuperview];
}
[_tabProgressBars release];
[_overflowPopUpButton release];
[_cells release];
[_tabView release];
Expand Down Expand Up @@ -715,11 +724,74 @@ - (void)removeTabForCell:(PSMTabBarCell *)cell {
[cell removeCloseButtonTrackingRectFrom:self];
[cell removeCellTrackingRectFrom:self];
[self removeAllToolTips];
[self removeTabProgressBarForCell:cell];

// pull from collection
[_cells removeObject:cell];
}

- (BOOL)shouldShowCustomProgressBarForTabCell:(PSMTabBarCell *)cell {
return NO;
}

- (NSView *)customProgressBarViewForTabCell:(PSMTabBarCell *)cell {
return nil;
}

- (void)configureCustomProgressBarView:(NSView *)view forTabCell:(PSMTabBarCell *)cell {
}

- (NSValue *)tabProgressBarKeyForCell:(PSMTabBarCell *)cell {
return [NSValue valueWithNonretainedObject:cell];
}

- (void)removeTabProgressBarForCell:(PSMTabBarCell *)cell {
NSValue *key = [self tabProgressBarKeyForCell:cell];
NSView *progressBar = _tabProgressBars[key];
if (!progressBar) {
return;
}
[progressBar removeFromSuperview];
[_tabProgressBars removeObjectForKey:key];
}

- (void)syncTabProgressBars {
NSMutableSet<NSValue *> *visibleKeys = [NSMutableSet set];
for (PSMTabBarCell *cell in _cells) {
if (![self shouldShowCustomProgressBarForTabCell:cell]) {
[self removeTabProgressBarForCell:cell];
continue;
}
NSValue *key = [self tabProgressBarKeyForCell:cell];
[visibleKeys addObject:key];
NSView *progressBar = _tabProgressBars[key];
if (!progressBar) {
progressBar = [self customProgressBarViewForTabCell:cell];
if (!progressBar) {
continue;
}
_tabProgressBars[key] = progressBar;
}
[self configureCustomProgressBarView:progressBar forTabCell:cell];
progressBar.frame = [self.style progressBarRectForTabCell:cell];
progressBar.hidden = NO;
if (progressBar.superview != self) {
[self addSubview:progressBar];
}
cell.indicator.hidden = YES;
cell.indicator.animate = NO;
[cell.indicator removeFromSuperview];
}

for (NSValue *key in [_tabProgressBars allKeys]) {
if (![visibleKeys containsObject:key]) {
NSView *progressBar = _tabProgressBars[key];
[progressBar removeFromSuperview];
[_tabProgressBars removeObjectForKey:key];
}
}
}

- (void)dragDidFinish {
_preDragSelectedTabIndex = NSNotFound;
}
Expand Down Expand Up @@ -1014,6 +1086,7 @@ - (void)drawRect:(NSRect)insaneRect {
clipRect:rect
horizontal:(_orientation == PSMTabBarHorizontalOrientation)
withOverflow:_lainOutWithOverflow];
[self syncTabProgressBars];

#if PSM_DEBUG_DRAG_PERFORMANCE
CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
Expand Down Expand Up @@ -1066,6 +1139,11 @@ - (void)update {
[self update:NO];
}

- (void)setFrame:(NSRect)frame {
[super setFrame:frame];
[self syncTabProgressBars];
}

- (void)update:(BOOL)animate {
// This method handles all of the cell layout, and is called when something changes to require
// the refresh. This method is not called during drag and drop. See the PSMTabDragAssistant's
Expand Down Expand Up @@ -1198,6 +1276,7 @@ - (void)reallyUpdate:(BOOL)animate {
[self finishUpdateWithRegularWidths:newOrigins widthsWithOverflow:newOrigins];
}

[self syncTabProgressBars];
[self setNeedsDisplay:YES];
}

Expand Down Expand Up @@ -1401,6 +1480,7 @@ - (void)computeCellFramesInContainerOfWidth:(CGFloat)containerWidth
- (void)removeCell:(PSMTabBarCell *)cell {
[cell removeCloseButtonTrackingRectFrom:self];
[cell removeCellTrackingRectFrom:self];
[self removeTabProgressBarForCell:cell];
[[self cells] removeObject:cell];
}

Expand Down Expand Up @@ -2521,6 +2601,7 @@ - (void)setIsProcessing:(BOOL)isProcessing forTabWithIdentifier:(id)identifier {
- (void)setProgress:(PSMProgress)progress forTabWithIdentifier:(id)identifier {
PSMTabBarCell *cell = [self cellWithIdentifier:identifier];
cell.progress = progress;
[self syncTabProgressBars];
}

- (void)graphicDidChangeForTabWithIdentifier:(id)identifier {
Expand Down
1 change: 1 addition & 0 deletions ThirdParty/PSMTabBarControl/source/PSMTabStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Protocol to be observed by all style delegate objects. These objects handle the
- (NSRect)dragRectForTabCell:(PSMTabBarCell *)cell orientation:(PSMTabBarOrientation)orientation;
- (NSRect)closeButtonRectForTabCell:(PSMTabBarCell *)cell;
- (NSRect)indicatorRectForTabCell:(PSMTabBarCell *)cell;
- (NSRect)progressBarRectForTabCell:(PSMTabBarCell *)cell;
- (NSRect)objectCounterRectForTabCell:(PSMTabBarCell *)cell;
- (float)minimumWidthOfTabCell:(PSMTabBarCell *)cell;
- (float)desiredWidthOfTabCell:(PSMTabBarCell *)cell;
Expand Down
37 changes: 34 additions & 3 deletions ThirdParty/PSMTabBarControl/source/PSMTahoeTabStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,39 @@ class PSMTahoeTabStyle: NSObject, PSMTabStyle {
frame.size.height = generic.height - 1
return frame
}

private func backgroundRect(for cellFrame: NSRect) -> NSRect {
var rect = cellFrame
rect.origin.y += 2
rect.size.height -= 3
return rect
}

@objc func progressBarRect(forTabCell cell: PSMTabBarCell) -> NSRect {
let cellFrame = cell.frame
let showVerticalProgressBar = (_orientation == .verticalOrientation &&
!iTermAdvancedSettingsModel.leftTabBarProgressBarsAreHorizontal())
if showVerticalProgressBar {
return NSRect(x: cellFrame.origin.x,
y: cellFrame.origin.y,
width: PSMTabBarProgressBarHeight,
height: cellFrame.size.height)
}
guard cell.state == .on else {
return NSRect(x: cellFrame.origin.x,
y: cellFrame.origin.y,
width: cellFrame.size.width,
height: PSMTabBarProgressBarHeight)
}

let pillRect = backgroundRect(for: cellFrame)
let horizontalInset = CGFloat(4)
let verticalInset = CGFloat(1)
return NSRect(x: pillRect.origin.x + horizontalInset,
y: pillRect.maxY - PSMTabBarProgressBarHeight - verticalInset,
width: max(CGFloat(0), pillRect.size.width - horizontalInset * 2),
height: PSMTabBarProgressBarHeight)
}

// MARK: - Drawing

Expand Down Expand Up @@ -789,9 +822,7 @@ class PSMTahoeTabStyle: NSObject, PSMTabStyle {
backgroundColorSelected(selected, highlightAmount: isHighlighted ? 1.0 : 0.0).set()

let radius = barRadius - 2.5
var rect = cellFrame
rect.origin.y += 2
rect.size.height -= 3
let rect = backgroundRect(for: cellFrame)
let path = NSBezierPath(roundedRect: rect, xRadius: radius, yRadius: radius)
path.fill()
if selected {
Expand Down
16 changes: 16 additions & 0 deletions ThirdParty/PSMTabBarControl/source/PSMYosemiteTabStyle.m
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ - (NSRect)indicatorRectForTabCell:(PSMTabBarCell *)cell {
return result;
}

- (NSRect)progressBarRectForTabCell:(PSMTabBarCell *)cell {
NSRect cellFrame = [cell frame];
const BOOL showVerticalProgressBar = (_orientation == PSMTabBarVerticalOrientation &&
![iTermAdvancedSettingsModel leftTabBarProgressBarsAreHorizontal]);
if (showVerticalProgressBar) {
return NSMakeRect(cellFrame.origin.x,
cellFrame.origin.y,
PSMTabBarProgressBarHeight,
cellFrame.size.height);
}
return NSMakeRect(cellFrame.origin.x,
cellFrame.origin.y,
cellFrame.size.width,
PSMTabBarProgressBarHeight);
}

- (NSRect)adjustedCellRect:(NSRect)rect generic:(NSRect)generic {
return rect;
}
Expand Down
1 change: 1 addition & 0 deletions sources/PTYTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extern NSString *const PTYTabArrangementOptionsPendingJumps;
@property(nonatomic, retain) NSImage *icon;
// Aggregated tab status from all sessions (highest-priority wins)
@property(nonatomic, readonly) iTermSessionTabStatus *aggregatedTabStatus;
@property(nonatomic, readonly) VT100ScreenProgress progress;

// Size we should report to fit the current layout
@property(nonatomic, readonly) NSSize tmuxSize;
Expand Down
30 changes: 27 additions & 3 deletions sources/PTYTab.m
Original file line number Diff line number Diff line change
Expand Up @@ -7283,10 +7283,34 @@ - (void)sessionProcessInfoProviderDidChange:(PTYSession *)session {
[self.delegate tabProcessInfoProviderDidChange:self];
}

- (void)session:(PTYSession *)session progressDidChange:(VT100ScreenProgress)progress {
if (session == self.activeSession) {
[self.delegate tab:self progressDidChange:progress];
static BOOL iTermTabProgressIsVisible(VT100ScreenProgress progress) {
if (progress == VT100ScreenProgressError || progress == VT100ScreenProgressIndeterminate) {
return YES;
}
return ((progress >= VT100ScreenProgressSuccessBase && progress <= VT100ScreenProgressSuccessBase + 100) ||
(progress >= VT100ScreenProgressErrorBase && progress <= VT100ScreenProgressErrorBase + 100) ||
(progress >= VT100ScreenProgressWarningBase && progress <= VT100ScreenProgressWarningBase + 100));
}

- (VT100ScreenProgress)progress {
const VT100ScreenProgress activeProgress = self.activeSession.screen.progress;
if (iTermTabProgressIsVisible(activeProgress)) {
return activeProgress;
}
for (PTYSession *session in self.sessions) {
if (session == self.activeSession) {
continue;
}
const VT100ScreenProgress progress = session.screen.progress;
if (iTermTabProgressIsVisible(progress)) {
return progress;
}
}
return VT100ScreenProgressStopped;
}

- (void)session:(PTYSession *)session progressDidChange:(VT100ScreenProgress)progress {
[self.delegate tab:self progressDidChange:self.progress];
}

- (NSScriptObjectSpecifier *)objectSpecifier {
Expand Down
32 changes: 31 additions & 1 deletion sources/PseudoTerminal.m
Original file line number Diff line number Diff line change
Expand Up @@ -6309,6 +6309,7 @@ - (void)updateTabBarControlIsTitlebarAccessory {
DLog(@"tab bar should NOT be accessory, but is on loan.");
[self returnTabBarToContentView];
}
[self updateSessionProgressBarVisibility];
DLog(@"Tab bar state after updateTabBarControlIsTitlebarAccessory: hidden=%@ alpha=%@ frame=%@",
@(_contentView.tabBarControl.isHidden),
@(_contentView.tabBarControl.alphaValue),
Expand Down Expand Up @@ -7284,6 +7285,7 @@ - (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)tabView {
}

[self updateTabColors];
[self updateSessionProgressBarVisibility];
[self updateTabProgress];
[self updateToolbeltAppearance];
[self setNeedsUpdateTabObjectCounts:YES];
Expand Down Expand Up @@ -7758,6 +7760,8 @@ - (void)tabViewDoubleClickTabBar:(NSTabView *)tabView {
- (void)tabView:(NSTabView *)tabView updateStateForTabViewItem:(NSTabViewItem *)tabViewItem {
PTYTab *tab = tabViewItem.identifier;
[_contentView.tabBarControl setIsProcessing:tab.isProcessing forTabWithIdentifier:tab];
[_contentView.tabBarControl setProgress:(PSMProgress)tab.progress
forTabWithIdentifier:tab];
[_contentView.tabBarControl setIcon:tab.icon forTabWithIdentifier:tab];
[_contentView.tabBarControl setObjectCount:tab.objectCount forTabWithIdentifier:tab];
[_contentView.tabBarControl setIsPinned:tab.isPinned forTabViewItem:tabViewItem];
Expand Down Expand Up @@ -7790,9 +7794,34 @@ - (void)updateTabColors {
[_contentView updateTitleAndBorderViews];
}

- (BOOL)tabBarProvidesProgressVisibility {
if (togglingLionFullScreen_ || self.lionFullScreen) {
return self.shouldShowPermanentFullScreenTabBar;
}
return self.tabBarShouldBeVisible;
}

- (BOOL)shouldShowInlineProgressBarForSession:(PTYSession *)session tabBarVisible:(BOOL)tabBarVisible {
PTYTab *tab = [self tabForSession:session];
if (!tab) {
return YES;
}
const BOOL hasSingleTab = (self.numberOfTabs == 1);
const BOOL hasSplitPanes = (tab.sessions.count > 1);
return (hasSingleTab || hasSplitPanes || !tabBarVisible);
}

- (void)updateSessionProgressBarVisibility {
const BOOL tabBarVisible = [self tabBarProvidesProgressVisibility];
for (PTYSession *session in self.allSessions) {
session.view.showInlineProgressBar = [self shouldShowInlineProgressBarForSession:session
tabBarVisible:tabBarVisible];
}
}

- (void)updateTabProgress {
for (PTYTab *tab in [self tabs]) {
[_contentView.tabBarControl setProgress:(PSMProgress)tab.activeSession.screen.progress
[_contentView.tabBarControl setProgress:(PSMProgress)tab.progress
forTabWithIdentifier:tab];
}
}
Expand Down Expand Up @@ -13005,6 +13034,7 @@ - (void)currentSessionWordAtCursorDidBecome:(NSString *)word {
}

- (void)numberOfSessionsDidChangeInTab:(PTYTab *)tab {
[self updateSessionProgressBarVisibility];
if (tab == self.currentTab) {
[self updateUseTransparency];
}
Expand Down
1 change: 1 addition & 0 deletions sources/SessionView.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ typedef NS_ENUM(NSUInteger, iTermSessionViewFindDriver) {
@property (nonatomic, readonly) BOOL isBrowser;
@property (nonatomic) VT100ScreenProgress progress;
@property (nonatomic) BOOL enableProgressBars;
@property (nonatomic) BOOL showInlineProgressBar;
@property (nonatomic) CGFloat progressBarHeight;
@property (nonatomic, copy) NSString *progressBarColorScheme;
@property (nonatomic, readonly) SessionTitleView *title;
Expand Down
Loading