forked from pieter/gitx
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new cell class for the source view items
The new cell handles: - showing contextual menus - drawing a badge for the checked out branch Needed to add the reference to the ref controller to the history controller.
- Loading branch information
1 parent
64f4276
commit 90f80f0
Showing
11 changed files
with
285 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// PBSourceViewBadge.h | ||
// GitX | ||
// | ||
// Created by Nathan Kinsinger on 2/13/10. | ||
// Copyright 2010 Nathan Kinsinger. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface PBSourceViewBadge : NSObject { | ||
|
||
} | ||
|
||
+ (NSImage *) checkedOutBadgeForCell:(NSTextFieldCell *)cell; | ||
+ (NSImage *) numericBadge:(NSInteger)number forCell:(NSTextFieldCell *)cell; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// | ||
// PBSourceViewBadge.m | ||
// GitX | ||
// | ||
// Created by Nathan Kinsinger on 2/13/10. | ||
// Copyright 2010 Nathan Kinsinger. All rights reserved. | ||
// | ||
|
||
#import "PBSourceViewBadge.h" | ||
#import "PBSourceViewCell.h" | ||
|
||
|
||
@implementation PBSourceViewBadge | ||
|
||
|
||
+ (NSColor *) badgeHighlightColor | ||
{ | ||
return [NSColor colorWithCalibratedHue:0.612 saturation:0.275 brightness:0.735 alpha:1.000]; | ||
} | ||
|
||
|
||
+ (NSColor *) badgeBackgroundColor | ||
{ | ||
return [NSColor colorWithCalibratedWhite:0.6 alpha:1.00]; | ||
} | ||
|
||
|
||
+ (NSColor *) badgeColorForCell:(NSTextFieldCell *)cell | ||
{ | ||
if ([cell isHighlighted]) | ||
return [NSColor whiteColor]; | ||
|
||
if ([[[cell controlView] window] isMainWindow]) | ||
return [self badgeHighlightColor]; | ||
|
||
return [self badgeBackgroundColor]; | ||
} | ||
|
||
|
||
+ (NSColor *) badgeTextColorForCell:(NSTextFieldCell *)cell | ||
{ | ||
if (![cell isHighlighted]) | ||
return [NSColor whiteColor]; | ||
|
||
if (![[[cell controlView] window] isKeyWindow]) | ||
if ([[[cell controlView] window] isMainWindow]) | ||
return [self badgeHighlightColor]; | ||
else | ||
return [self badgeBackgroundColor]; | ||
|
||
if ([[[cell controlView] window] firstResponder] == [cell controlView]) | ||
return [self badgeHighlightColor]; | ||
|
||
return [self badgeBackgroundColor]; | ||
} | ||
|
||
|
||
+ (NSMutableDictionary *) badgeTextAttributes | ||
{ | ||
NSMutableDictionary *badgeTextAttributes = nil; | ||
if (!badgeTextAttributes) { | ||
NSMutableParagraphStyle *centerStyle = [[NSMutableParagraphStyle alloc] init]; | ||
[centerStyle setAlignment:NSCenterTextAlignment]; | ||
|
||
badgeTextAttributes = [NSMutableDictionary dictionary]; | ||
[badgeTextAttributes setObject:[NSFont fontWithName:@"Helvetica-Bold" size:[NSFont systemFontSize] - 2] forKey:NSFontAttributeName]; | ||
[badgeTextAttributes setObject:centerStyle forKey:NSParagraphStyleAttributeName]; | ||
} | ||
|
||
return badgeTextAttributes; | ||
} | ||
|
||
|
||
|
||
#pragma mark - | ||
#pragma mark badges | ||
|
||
+ (NSImage *) badge:(NSString *)badge forCell:(NSTextFieldCell *)cell | ||
{ | ||
NSColor *badgeColor = [self badgeColorForCell:cell]; | ||
|
||
NSColor *textColor = [self badgeTextColorForCell:cell]; | ||
NSMutableDictionary *badgeTextAttributes = [self badgeTextAttributes]; | ||
[badgeTextAttributes setObject:textColor forKey:NSForegroundColorAttributeName]; | ||
NSAttributedString *badgeString = [[NSAttributedString alloc] initWithString:badge attributes:badgeTextAttributes]; | ||
|
||
float imageHeight = ceilf([badgeString size].height); | ||
float radius = ceilf(imageHeight / 4) * 2; | ||
float minWidth = ceilf(radius * 2.5); | ||
|
||
float imageWidth = ceilf([badgeString size].width + radius); | ||
if (imageWidth < minWidth) | ||
imageWidth = minWidth; | ||
NSRect badgeRect = NSMakeRect(0, 0, imageWidth, imageHeight); | ||
|
||
NSBezierPath *badgePath = [NSBezierPath bezierPathWithRoundedRect:badgeRect xRadius:radius yRadius:radius]; | ||
|
||
NSImage *badgeImage = [[NSImage alloc] initWithSize:badgeRect.size]; | ||
[badgeImage lockFocus]; | ||
|
||
[badgeColor set]; | ||
[badgePath fill]; | ||
|
||
[badgeString drawInRect:badgeRect]; | ||
|
||
[badgeImage unlockFocus]; | ||
|
||
return badgeImage; | ||
} | ||
|
||
+ (NSImage *) checkedOutBadgeForCell:(NSTextFieldCell *)cell | ||
{ | ||
return [self badge:@"✔" forCell:cell]; | ||
} | ||
|
||
+ (NSImage *) numericBadge:(NSInteger)number forCell:(NSTextFieldCell *)cell | ||
{ | ||
return [self badge:[NSString stringWithFormat:@"%d", number] forCell:cell]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// PBSourceViewCell.h | ||
// GitX | ||
// | ||
// Created by Nathan Kinsinger on 1/7/10. | ||
// Copyright 2010 Nathan Kinsinger. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import "PBIconAndTextCell.h" | ||
|
||
|
||
@interface PBSourceViewCell : PBIconAndTextCell { | ||
BOOL isCheckedOut; | ||
} | ||
|
||
@property (assign) BOOL isCheckedOut; | ||
|
||
@end |
Oops, something went wrong.