Skip to content

Commit

Permalink
show a different close icon in tabs for modified documents, don't app…
Browse files Browse the repository at this point in the history
…end a silly asterisk to the document title

fixes http://help.vicoapp.com/ideas/changes-indicator-in-tabs
  • Loading branch information
martinh committed Jul 8, 2012
1 parent 4ac35d1 commit 6b644e1
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 149 deletions.
Binary file added Images/TabCloseModified_Front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/TabCloseModified_Front_Pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/TabCloseModified_Front_Rollover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/TabNewMetal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/TabNewMetalPressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Images/TabNewMetalRollover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ IMAGES = \
Images/TabClose_Front.tif \
Images/TabClose_Front_Pressed.tif \
Images/TabClose_Front_Rollover.tif \
Images/TabCloseModified_Front.png \
Images/TabCloseModified_Front_Pressed.png \
Images/TabCloseModified_Front_Rollover.png \
Images/TabNewMetal.png \
Images/TabNewMetalPressed.png \
Images/TabNewMetalRollover.png \
Expand Down
2 changes: 0 additions & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* group by attribute != grouped display string
* can't assume ack's output is in newline chunks
* don't overwrite read-only files!
* show baseURL in window title!
* explorer spinner is hidden by new path control
=> move it, where!? auto-hide something else?

Expand Down Expand Up @@ -39,7 +38,6 @@
* convert horizontal split to vertical and vice versa
* @kamens: Any way to resize splits w/ key bindings? Like <c-w>_ or <c-w>+

* less lame notification of modified documents in tabs (don't append * in title!)
* bring back explorer / folder bookmarks
* ctags should present menu for duplicate tags
* draw marks in gutter view
Expand Down
3 changes: 3 additions & 0 deletions app/PSMMetalTabStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
NSImage *_metalCloseButton;
NSImage *_metalCloseButtonDown;
NSImage *_metalCloseButtonOver;
NSImage *_metalCloseModifiedButton;
NSImage *_metalCloseModifiedButtonDown;
NSImage *_metalCloseModifiedButtonOver;
NSImage *_addTabButtonImage;
NSImage *_addTabButtonPressedImage;
NSImage *_addTabButtonRolloverImage;
Expand Down
184 changes: 98 additions & 86 deletions app/PSMMetalTabStyle.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ - (NSString *)name

- (id) init
{
if((self = [super init]))
{
_metalCloseButton = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front"]];
_metalCloseButtonDown = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front_Pressed"]];
_metalCloseButtonOver = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front_Rollover"]];

_addTabButtonImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabNewMetal"]];
_addTabButtonPressedImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabNewMetalPressed"]];
_addTabButtonRolloverImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabNewMetalRollover"]];
}
return self;
if ((self = [super init])) {
_metalCloseButton = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front"]];
_metalCloseButtonDown = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front_Pressed"]];
_metalCloseButtonOver = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabClose_Front_Rollover"]];

_metalCloseModifiedButton = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabCloseModified_Front"]];
_metalCloseModifiedButtonDown = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabCloseModified_Front_Pressed"]];
_metalCloseModifiedButtonOver = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabCloseModified_Front_Rollover"]];

_addTabButtonImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabNewMetal"]];
_addTabButtonPressedImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabNewMetalPressed"]];
_addTabButtonRolloverImage = [[NSImage alloc] initByReferencingFile:[[PSMTabBarControl bundle] pathForImageResource:@"TabNewMetalRollover"]];
}
return self;
}

- (void)dealloc
Expand All @@ -45,6 +48,9 @@ - (void)dealloc
[_metalCloseButton release];
[_metalCloseButtonDown release];
[_metalCloseButtonOver release];
[_metalCloseModifiedButton release];
[_metalCloseModifiedButtonDown release];
[_metalCloseModifiedButtonOver release];
[_addTabButtonImage release];
[_addTabButtonPressedImage release];
[_addTabButtonRolloverImage release];
Expand Down Expand Up @@ -368,81 +374,87 @@ - (void)drawTabCell:(PSMTabBarCell *)cell

- (void)drawInteriorWithTabCell:(PSMTabBarCell *)cell inView:(NSView*)controlView
{
NSRect cellFrame = [cell frame];
float labelPosition = cellFrame.origin.x + MARGIN_X;

// close button
if ([cell hasCloseButton] && ![cell isCloseButtonSuppressed]) {
NSSize closeButtonSize = NSZeroSize;
NSRect closeButtonRect = [cell closeButtonRectForFrame:cellFrame];
NSImage * closeButton = nil;

closeButton = _metalCloseButton;
if ([cell closeButtonOver]) closeButton = _metalCloseButtonOver;
if ([cell closeButtonPressed]) closeButton = _metalCloseButtonDown;

closeButtonSize = [closeButton size];
if ([controlView isFlipped]) {
closeButtonRect.origin.y += closeButtonRect.size.height;
}

[closeButton compositeToPoint:closeButtonRect.origin operation:NSCompositeSourceOver fraction:1.0];

// scoot label over
labelPosition += closeButtonSize.width + kPSMTabBarCellPadding;
}

// icon
if([cell hasIcon]){
NSRect iconRect = [self iconRectForTabCell:cell];
NSImage *icon = [[[[cell representedObject] identifier] content] icon];
if ([controlView isFlipped]) {
iconRect.origin.y = cellFrame.size.height - iconRect.origin.y;
}
[icon compositeToPoint:iconRect.origin operation:NSCompositeSourceOver fraction:1.0];

// scoot label over
labelPosition += iconRect.size.width + kPSMTabBarCellPadding;
}

// object counter
if([cell count] > 0){
[[NSColor colorWithCalibratedWhite:0.3 alpha:0.6] set];
NSBezierPath *path = [NSBezierPath bezierPath];
NSRect myRect = [self objectCounterRectForTabCell:cell];
if([cell state] == NSOnState)
myRect.origin.y -= 1.0;
[path moveToPoint:NSMakePoint(myRect.origin.x + kPSMMetalObjectCounterRadius, myRect.origin.y)];
[path lineToPoint:NSMakePoint(myRect.origin.x + myRect.size.width - kPSMMetalObjectCounterRadius, myRect.origin.y)];
[path appendBezierPathWithArcWithCenter:NSMakePoint(myRect.origin.x + myRect.size.width - kPSMMetalObjectCounterRadius, myRect.origin.y + kPSMMetalObjectCounterRadius) radius:kPSMMetalObjectCounterRadius startAngle:270.0 endAngle:90.0];
[path lineToPoint:NSMakePoint(myRect.origin.x + kPSMMetalObjectCounterRadius, myRect.origin.y + myRect.size.height)];
[path appendBezierPathWithArcWithCenter:NSMakePoint(myRect.origin.x + kPSMMetalObjectCounterRadius, myRect.origin.y + kPSMMetalObjectCounterRadius) radius:kPSMMetalObjectCounterRadius startAngle:90.0 endAngle:270.0];
[path fill];

// draw attributed string centered in area
NSRect counterStringRect;
NSAttributedString *counterString = [self attributedObjectCountValueForTabCell:cell];
counterStringRect.size = [counterString size];
counterStringRect.origin.x = myRect.origin.x + ((myRect.size.width - counterStringRect.size.width) / 2.0) + 0.25;
counterStringRect.origin.y = myRect.origin.y + ((myRect.size.height - counterStringRect.size.height) / 2.0) + 0.5;
[counterString drawInRect:counterStringRect];
}

// label rect
NSRect labelRect;
labelRect.origin.x = labelPosition;
labelRect.size.width = cellFrame.size.width - (labelRect.origin.x - cellFrame.origin.x) - kPSMTabBarCellPadding;
labelRect.size.height = cellFrame.size.height;
labelRect.origin.y = cellFrame.origin.y + MARGIN_Y;

if(![[cell indicator] isHidden])
labelRect.size.width -= (kPSMTabBarIndicatorWidth + kPSMTabBarCellPadding);

if([cell count] > 0)
labelRect.size.width -= ([self objectCounterRectForTabCell:cell].size.width + kPSMTabBarCellPadding);

// label
[[cell attributedStringValue] drawInRect:labelRect];
NSRect cellFrame = [cell frame];
float labelPosition = cellFrame.origin.x + MARGIN_X;

// close button
if ([cell hasCloseButton] && ![cell isCloseButtonSuppressed]) {
NSSize closeButtonSize = NSZeroSize;
NSRect closeButtonRect = [cell closeButtonRectForFrame:cellFrame];
NSImage * closeButton = nil;

if (cell.isModified) {
closeButton = _metalCloseModifiedButton;
if ([cell closeButtonOver]) closeButton = _metalCloseModifiedButtonOver;
if ([cell closeButtonPressed]) closeButton = _metalCloseModifiedButtonDown;
} else {
closeButton = _metalCloseButton;
if ([cell closeButtonOver]) closeButton = _metalCloseButtonOver;
if ([cell closeButtonPressed]) closeButton = _metalCloseButtonDown;
}

closeButtonSize = [closeButton size];
if ([controlView isFlipped]) {
closeButtonRect.origin.y += closeButtonRect.size.height;
}

[closeButton compositeToPoint:closeButtonRect.origin operation:NSCompositeSourceOver fraction:1.0];

// scoot label over
labelPosition += closeButtonSize.width + kPSMTabBarCellPadding;
}

// icon
if([cell hasIcon]){
NSRect iconRect = [self iconRectForTabCell:cell];
NSImage *icon = [[[[cell representedObject] identifier] content] icon];
if ([controlView isFlipped]) {
iconRect.origin.y = cellFrame.size.height - iconRect.origin.y;
}
[icon compositeToPoint:iconRect.origin operation:NSCompositeSourceOver fraction:1.0];

// scoot label over
labelPosition += iconRect.size.width + kPSMTabBarCellPadding;
}

// object counter
if([cell count] > 0){
[[NSColor colorWithCalibratedWhite:0.3 alpha:0.6] set];
NSBezierPath *path = [NSBezierPath bezierPath];
NSRect myRect = [self objectCounterRectForTabCell:cell];
if([cell state] == NSOnState)
myRect.origin.y -= 1.0;
[path moveToPoint:NSMakePoint(myRect.origin.x + kPSMMetalObjectCounterRadius, myRect.origin.y)];
[path lineToPoint:NSMakePoint(myRect.origin.x + myRect.size.width - kPSMMetalObjectCounterRadius, myRect.origin.y)];
[path appendBezierPathWithArcWithCenter:NSMakePoint(myRect.origin.x + myRect.size.width - kPSMMetalObjectCounterRadius, myRect.origin.y + kPSMMetalObjectCounterRadius) radius:kPSMMetalObjectCounterRadius startAngle:270.0 endAngle:90.0];
[path lineToPoint:NSMakePoint(myRect.origin.x + kPSMMetalObjectCounterRadius, myRect.origin.y + myRect.size.height)];
[path appendBezierPathWithArcWithCenter:NSMakePoint(myRect.origin.x + kPSMMetalObjectCounterRadius, myRect.origin.y + kPSMMetalObjectCounterRadius) radius:kPSMMetalObjectCounterRadius startAngle:90.0 endAngle:270.0];
[path fill];

// draw attributed string centered in area
NSRect counterStringRect;
NSAttributedString *counterString = [self attributedObjectCountValueForTabCell:cell];
counterStringRect.size = [counterString size];
counterStringRect.origin.x = myRect.origin.x + ((myRect.size.width - counterStringRect.size.width) / 2.0) + 0.25;
counterStringRect.origin.y = myRect.origin.y + ((myRect.size.height - counterStringRect.size.height) / 2.0) + 0.5;
[counterString drawInRect:counterStringRect];
}

// label rect
NSRect labelRect;
labelRect.origin.x = labelPosition;
labelRect.size.width = cellFrame.size.width - (labelRect.origin.x - cellFrame.origin.x) - kPSMTabBarCellPadding;
labelRect.size.height = cellFrame.size.height;
labelRect.origin.y = cellFrame.origin.y + MARGIN_Y;

if(![[cell indicator] isHidden])
labelRect.size.width -= (kPSMTabBarIndicatorWidth + kPSMTabBarCellPadding);

if([cell count] > 0)
labelRect.size.width -= ([self objectCounterRectForTabCell:cell].size.width + kPSMTabBarCellPadding);

// label
[[cell attributedStringValue] drawInRect:labelRect];
}

- (void)drawTabBar:(PSMTabBarControl *)bar inRect:(NSRect)rect
Expand Down
3 changes: 3 additions & 0 deletions app/PSMTabBarCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
BOOL _isCloseButtonSuppressed;
BOOL _hasIcon;
int _count;
BOOL _modified;
}

@property (readwrite,getter=isModified) BOOL modified;

// creation/destruction
- (id)initWithControlView:(PSMTabBarControl *)controlView;
- (id)initPlaceholderWithFrame:(NSRect)frame expanded:(BOOL)value inControlView:(PSMTabBarControl *)controlView;
Expand Down
5 changes: 5 additions & 0 deletions app/PSMTabBarCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
#import "PSMTabStyle.h"
#import "PSMProgressIndicator.h"
#import "PSMTabDragAssistant.h"
#include "logging.h"


@implementation PSMTabBarCell

@synthesize modified = _modified;

#pragma mark -
#pragma mark Creation/Destruction

- (id)initWithControlView:(PSMTabBarControl *)controlView
{
self = [super init];
Expand All @@ -29,6 +33,7 @@ - (id)initWithControlView:(PSMTabBarControl *)controlView
_indicator = [[PSMProgressIndicator alloc] initWithFrame:NSMakeRect(0.0,0.0,kPSMTabBarIndicatorWidth,kPSMTabBarIndicatorWidth)];
[_indicator setStyle:NSProgressIndicatorSpinningStyle];
[_indicator setAutoresizingMask:NSViewMinYMargin];
[_indicator setControlSize:NSSmallControlSize];
_hasCloseButton = YES;
_isCloseButtonSuppressed = NO;
_count = 0;
Expand Down
Loading

0 comments on commit 6b644e1

Please sign in to comment.