public this repo is viewable by everyone
Description: A Gitk-like application written in RubyCocoa that looks like it belongs on a Mac. See the wiki for downloads and screenshots.
Homepage: http://alternateidea.com
Clone URL: git://github.com/Caged/gitnub.git
Click here to lend your support to: gitnub and make a donation at www.pledgie.com !
dustin (author)
22 days ago
Caged (committer)
22 days ago
commit  f7b3f6bb486c211ed4419560d52125b14b979087
tree    cf0bd79b8f9d41a601f6fa542baafa99fe7cb014
parent  a033963b118ffa6e81a908e5e773801aa4199f04
gitnub / CommitSummaryCell.m
100644 130 lines (107 sloc) 4.15 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// CommitSummaryCell.m
// GitNub
//
// Created by local22 on 3/12/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
 
#import "CommitSummaryCell.h"
 
#define PADDING (2.0)
#define GRAVATAR_WIDTH (36.0)
 
@implementation CommitSummaryCell
- (void)dealloc {
    [titleCell release];
    [subtitleCell release];
    [gravatarCell release];
    
    [super dealloc];
}
 
- (id)init {
    self = [super init];
    if(self) {
        titleCell = [[NSTextFieldCell alloc] init];
        [titleCell setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
        [titleCell setLineBreakMode:NSLineBreakByTruncatingTail];
        
        subtitleCell = [[NSTextFieldCell alloc] init];
        [subtitleCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
        [subtitleCell setLineBreakMode:NSLineBreakByTruncatingTail];
        
        gravatarCell = [[NSImageCell alloc] init];
    }
    return self;
}
 
- (id)copyWithZone:(NSZone *)zone {
    CommitSummaryCell *copy = [super copyWithZone:zone];
    if(copy) {
        copy->titleCell = [titleCell copyWithZone:zone];
        copy->subtitleCell = [subtitleCell copyWithZone:zone];
        copy->gravatarCell = [gravatarCell copyWithZone:zone];
    }
    return copy;
}
 
- (void)setGravatarImage:(NSImage *)image {
    [gravatarCell setImage:image];
}
 
- (void)setSubtitle:(NSString *)string {
    [subtitleCell setStringValue:string];
}
 
- (void)setObjectValue:(id)object {
    [titleCell setObjectValue:object];
}
 
- (void)setBackgroundStyle:(NSBackgroundStyle)style {
    [super setBackgroundStyle:style];
    
    [titleCell setBackgroundStyle:style];
    
    [subtitleCell setBackgroundStyle:style];
    [subtitleCell setTextColor:(style == NSBackgroundStyleLight) ? [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
}
 
- (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView *)view {
    NSSize fullSize = [[titleCell attributedStringValue] size];
    fullSize.width += PADDING + GRAVATAR_WIDTH;
    
    if(fullSize.width > NSWidth(cellFrame)) {
        cellFrame.size.width = fullSize.width;
    } else {
        cellFrame = NSZeroRect;
    }
    
    return cellFrame;
}
 
- (NSRect)titleRectForBounds:(NSRect)theRect {
    NSRect imageRect, titleRect;
    theRect = NSInsetRect(theRect, PADDING, PADDING);
    NSDivideRect(theRect, &imageRect, &titleRect, GRAVATAR_WIDTH + 4, NSMinXEdge);
    NSSize stringSize = [[titleCell attributedStringValue] size];
    //titleRect.origin.y += (NSHeight(titleRect) - stringSize.height)/2.0;
    titleRect.origin.x += PADDING;
    titleRect.size.height = stringSize.height;
    
    return titleRect;
}
 
- (NSRect)subtitleRectForBounds:(NSRect)theRect {
    theRect = [self titleRectForBounds:theRect];
    theRect.origin.y += NSHeight(theRect) + PADDING;
    return theRect;
}
 
- (NSRect)gravatarRectForBounds:(NSRect)theRect {
    NSRect imageRect, titleRect;
    theRect = NSInsetRect(theRect, PADDING, PADDING);
    NSDivideRect(theRect, &imageRect, &titleRect, GRAVATAR_WIDTH + 4, NSMinXEdge);
    return imageRect;
}
 
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)view {
    [titleCell drawInteriorWithFrame:[self titleRectForBounds:cellFrame] inView:view];
    [subtitleCell drawInteriorWithFrame:[self subtitleRectForBounds:cellFrame] inView:view];
    [gravatarCell drawInteriorWithFrame:[self gravatarRectForBounds:cellFrame] inView:view];
}
 
- (void)drawWithExpansionFrame:(NSRect)cellFrame inView:(NSView *)view {
  // oddly, the title cell seems to end up with an attributed string when selected
  // so lets fix that
  NSColor *titleColor = [titleCell textColor];
  NSColor *subtitleColor = [subtitleCell textColor];
  NSAttributedString *titleAttStr = [titleCell attributedStringValue];
  if (titleAttStr)
    [titleCell setStringValue:[titleAttStr string]];
  [titleCell setTextColor:[NSColor blackColor]];
  [subtitleCell setTextColor:[NSColor blackColor]];
  [self drawWithFrame:cellFrame inView:view];
  if (titleAttStr)
    [titleCell setAttributedStringValue:titleAttStr];
  [titleCell setTextColor:titleColor];
  [subtitleCell setTextColor:subtitleColor];
}
@end