Skip to content
Snippets Groups Projects
Commit 0af54e14 authored by George Nachman's avatar George Nachman
Browse files

Add off-by-default smart truncation for tab titles.

parent fcccdbe7
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -49,6 +49,7 @@
@property(nonatomic, readonly) float minimumWidthOfCell;
@property(nonatomic, readonly) float desiredWidthOfCell;
@property(nonatomic, readonly) id<PSMTabStyle> style;
@property(nonatomic, assign) NSLineBreakMode truncationStyle; // How to truncate title.
 
// creation/destruction
- (id)initWithControlView:(PSMTabBarControl *)controlView;
Loading
Loading
Loading
Loading
@@ -91,6 +91,7 @@ static NSTimeInterval kHighlightAnimationDuration = 0.5;
_indicator.light = controlView.style.useLightControls;
_hasCloseButton = YES;
_modifierString = [@"" copy];
_truncationStyle = NSLineBreakByTruncatingTail;
}
return self;
}
Loading
Loading
@@ -119,6 +120,7 @@ static NSTimeInterval kHighlightAnimationDuration = 0.5;
_count = 0;
_tabColor = nil;
_modifierString = [@"" copy];
_truncationStyle = NSLineBreakByTruncatingTail;
if (value) {
[self setCurrentStep:(kPSMTabDragAnimationSteps - 1)];
} else {
Loading
Loading
Loading
Loading
@@ -169,6 +169,10 @@ enum {
@property(nonatomic, assign) BOOL automaticallyAnimates;
@property(nonatomic, assign) int tabLocation;
 
// If off (the default) always ellipsize the ends of tab titles that don't fit.
// Of on, ellipsize the start if more tabs share a prefix than a suffix.
@property(nonatomic, assign) BOOL smartTruncation;
@property(nonatomic, retain) IBOutlet NSTabView *tabView;
@property(nonatomic, assign) id<PSMTabBarControlDelegate> delegate;
@property(nonatomic, retain) id partnerView;
Loading
Loading
Loading
Loading
@@ -367,9 +367,41 @@ const NSInteger kPSMStartResizeAnimation = 0;
#pragma mark -
#pragma mark Functionality
 
- (NSLineBreakMode)truncationStyle {
if (_cells.count <= 1 || !self.smartTruncation) {
return NSLineBreakByTruncatingTail;
}
NSCountedSet *prefixCounts = [[[NSCountedSet alloc] init] autorelease];
NSCountedSet *suffixCounts = [[[NSCountedSet alloc] init] autorelease];
NSMutableSet *uniqueTitles = [NSMutableSet set];
static NSInteger const kPrefixOrSuffixLength = 5;
for (PSMTabBarCell *cell in _cells) {
NSString *title = [cell title];
if (title.length < kPrefixOrSuffixLength) {
continue;
}
[uniqueTitles addObject:title];
NSString *prefix = [title substringToIndex:kPrefixOrSuffixLength];
NSString *suffix = [title substringFromIndex:(NSInteger)title.length - kPrefixOrSuffixLength];
[prefixCounts addObject:prefix];
[suffixCounts addObject:suffix];
}
if (uniqueTitles.count == 0) {
return NSLineBreakByTruncatingTail;
}
if (prefixCounts.count >= suffixCounts.count) {
return NSLineBreakByTruncatingTail;
} else {
return NSLineBreakByTruncatingHead;
}
}
- (void)addTabViewItem:(NSTabViewItem *)item atIndex:(NSUInteger)i {
// create cell
PSMTabBarCell *cell = [[PSMTabBarCell alloc] initWithControlView:self];
cell.truncationStyle = [self truncationStyle];
[cell setRepresentedObject:item];
[cell setModifierString:[self _modifierString]];
 
Loading
Loading
@@ -723,8 +755,11 @@ const NSInteger kPSMStartResizeAnimation = 0;
currentOrigin = [[self style] topMarginForTabBarControl];
}
 
NSLineBreakMode truncationStyle = [self truncationStyle];
for (i = 0; i < cellCount; i++) {
PSMTabBarCell *cell = [_cells objectAtIndex:i];
cell.truncationStyle = truncationStyle;
cell.hasCloseButton = _hasCloseButton;
[cell updateForStyle];
float width;
Loading
Loading
Loading
Loading
@@ -760,6 +760,7 @@ static PSMTabDragAssistant *sharedDragAssistant = nil;
// replace dragged cell with a placeholder, and clean up surrounding cells
int cellIndex = [[control cells] indexOfObject:cell];
PSMTabBarCell *pc = [[[PSMTabBarCell alloc] initPlaceholderWithFrame:[[self draggedCell] frame] expanded:YES inControlView:control] autorelease];
pc.truncationStyle = cell.truncationStyle;
[[control cells] replaceObjectAtIndex:cellIndex withObject:pc];
[[control cells] removeObjectAtIndex:(cellIndex + 1)];
[[control cells] removeObjectAtIndex:(cellIndex - 1)];
Loading
Loading
@@ -771,17 +772,22 @@ static PSMTabDragAssistant *sharedDragAssistant = nil;
int i, numVisibleTabs = [control numberOfVisibleTabs];
PSMTabBarCell *draggedCell = [self draggedCell];
NSRect draggedCellFrame;
NSLineBreakMode truncationStyle;
if (draggedCell) {
draggedCellFrame = [draggedCell frame];
truncationStyle = draggedCell.truncationStyle;
} else {
draggedCellFrame = [[[control cells] objectAtIndex:0] frame];
truncationStyle = [[[control cells] objectAtIndex:0] truncationStyle];
}
for(i = 0; i < numVisibleTabs; i++) {
PSMTabBarCell *pc = [[[PSMTabBarCell alloc] initPlaceholderWithFrame:draggedCellFrame expanded:NO inControlView:control] autorelease];
pc.truncationStyle = truncationStyle;
[[control cells] insertObject:pc atIndex:(2 * i)];
}
 
PSMTabBarCell *pc = [[[PSMTabBarCell alloc] initPlaceholderWithFrame:draggedCellFrame expanded:NO inControlView:control] autorelease];
pc.truncationStyle = truncationStyle;
if ([[control cells] count] > (2 * numVisibleTabs)) {
[[control cells] insertObject:pc atIndex:(2 * numVisibleTabs)];
} else {
Loading
Loading
Loading
Loading
@@ -307,13 +307,12 @@
range:range];
 
// Paragraph Style for Truncating Long Text
static NSMutableParagraphStyle *truncatingTailParagraphStyle = nil;
if (!truncatingTailParagraphStyle) {
truncatingTailParagraphStyle =
[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[truncatingTailParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[truncatingTailParagraphStyle setAlignment:NSCenterTextAlignment];
}
NSMutableParagraphStyle *truncatingTailParagraphStyle = nil;
truncatingTailParagraphStyle =
[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
[truncatingTailParagraphStyle setLineBreakMode:[cell truncationStyle]];
[truncatingTailParagraphStyle setAlignment:NSCenterTextAlignment];
[attrStr addAttribute:NSParagraphStyleAttributeName
value:truncatingTailParagraphStyle
range:range];
Loading
Loading
Loading
Loading
@@ -124,5 +124,6 @@
 
+ (BOOL)hideFromDockAndAppSwitcher;
+ (BOOL)hotkeyWindowIgnoresSpotlight;
+ (BOOL)tabTitlesUseSmartTruncation;
 
@end
Loading
Loading
@@ -54,6 +54,7 @@ DEFINE_BOOL(navigatePanesInReadingOrder, YES, @"Tabs: Next Pane and Previous Pan
DEFINE_BOOL(eliminateCloseButtons, NO, @"Tabs: Eliminate close buttons from tabs, even on mouse-over.");
DEFINE_FLOAT(tabAutoShowHoldTime, 1.0, @"Tabs: How long in seconds to show tabs in fullscreen.\nThe tab bar appears briefly in fullscreen when the number of tabs changes or you switch tabs. This setting gives the time in seconds for it to remain visible.");
DEFINE_BOOL(allowDragOfTabIntoNewWindow, YES, @"Tabs: Allow a tab to be dragged and dropped outside any existing tab bar to create a new window.");
DEFINE_BOOL(tabTitlesUseSmartTruncation, NO, @"Tabs: Use “smart truncation” for tab titles.\nIf a tab‘s title is too long to fit, ellipsize the start of the title if more tabs have unique suffixes than prefixes in a given window.");
 
#pragma mark Mouse
DEFINE_BOOL(alternateMouseScroll, NO, @"Mouse: Scroll wheel sends arrow keys when in alternate screen mode.");
Loading
Loading
Loading
Loading
@@ -395,7 +395,8 @@ static const CGFloat kMaximumToolbeltSizeAsFractionOfWindow = 0.5;
}
[self.tabBarControl setSizeCellsToFit:[iTermAdvancedSettingsModel useUnevenTabs]];
[self.tabBarControl setCellOptimumWidth:[iTermAdvancedSettingsModel optimumTabWidth]];
self.tabBarControl.smartTruncation = [iTermAdvancedSettingsModel tabTitlesUseSmartTruncation];
DLog(@"repositionWidgets - redraw view");
// Note: this used to call setNeedsDisplay on each session in the current tab.
[self setNeedsDisplay:YES];
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment