public
Fork of Caged/gitnub
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/eventualbuddha/gitnub.git
Search Repo:
Cleaned up the image and text cell so it's not insane
benstiglitz (author)
Wed Mar 12 15:45:28 -0700 2008
commit  88e9717531fef063bf68056e3a65bc62e206b4cf
tree    13defdac7ee1308bee0fb3e6676f271b220f0a23
parent  41487b0d312fba88728433a2c4ebd44457c05e74
...
12
13
14
15
 
16
17
18
19
...
43
44
45
46
 
47
48
49
50
51
...
12
13
14
 
15
16
17
18
19
...
43
44
45
 
46
47
 
48
49
50
0
@@ -12,7 +12,7 @@
0
 require 'grit/lib/grit'
0
 require 'InfoWindowController'
0
 
0
-OSX.ns_import 'ImageTextCell'
0
+OSX.ns_import 'CommitSummaryCell'
0
 include OSX
0
 
0
 REPOSITORY_LOCATION = ENV['PWD'].nil? ? '' : ENV['PWD']
0
0
@@ -43,9 +43,8 @@
0
     
0
     @window.delegate = self
0
     column = @commits_table.tableColumns[0]
0
- cell = ImageTextCell.alloc.init
0
+ cell = CommitSummaryCell.alloc.init
0
     column.dataCell = cell
0
- cell.dataDelegate = @commits_controller
0
     
0
     @main_view.setFrameSize(@main_canvas.frame.size)
0
     @main_canvas.addSubview(@main_view)
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
@@ -1 +1,22 @@
0
+//
0
+// CommitSummaryCell.h
0
+// GitNub
0
+//
0
+// Created by local22 on 3/12/08.
0
+// Copyright 2008 __MyCompanyName__. All rights reserved.
0
+//
0
+
0
+#import <Cocoa/Cocoa.h>
0
+
0
+
0
+@interface CommitSummaryCell : NSTextFieldCell {
0
+ NSTextFieldCell *titleCell;
0
+ NSTextFieldCell *subtitleCell;
0
+ NSImageCell *gravatarCell;
0
+}
0
+
0
+- (void)setGravatarImage:(NSImage *)image;
0
+- (void)setSubtitle:(NSString *)string;
0
+
0
+@end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,114 @@
0
+//
0
+// CommitSummaryCell.m
0
+// GitNub
0
+//
0
+// Created by local22 on 3/12/08.
0
+// Copyright 2008 __MyCompanyName__. All rights reserved.
0
+//
0
+
0
+#import "CommitSummaryCell.h"
0
+
0
+#define PADDING (2.0)
0
+#define GRAVATAR_WIDTH (36.0)
0
+
0
+@implementation CommitSummaryCell
0
+- (void)dealloc {
0
+ [titleCell release];
0
+ [subtitleCell release];
0
+ [gravatarCell release];
0
+
0
+ [super dealloc];
0
+}
0
+
0
+- (id)init {
0
+ self = [super init];
0
+ if(self) {
0
+ titleCell = [[NSTextFieldCell alloc] init];
0
+ [titleCell setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
0
+ [titleCell setLineBreakMode:NSLineBreakByTruncatingTail];
0
+
0
+ subtitleCell = [[NSTextFieldCell alloc] init];
0
+ [subtitleCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
0
+ [subtitleCell setLineBreakMode:NSLineBreakByTruncatingTail];
0
+
0
+ gravatarCell = [[NSImageCell alloc] init];
0
+ }
0
+ return self;
0
+}
0
+
0
+- (id)copyWithZone:(NSZone *)zone {
0
+ CommitSummaryCell *copy = [super copyWithZone:zone];
0
+ if(copy) {
0
+ copy->titleCell = [titleCell copyWithZone:zone];
0
+ copy->subtitleCell = [subtitleCell copyWithZone:zone];
0
+ copy->gravatarCell = [gravatarCell copyWithZone:zone];
0
+ }
0
+ return copy;
0
+}
0
+
0
+- (void)setGravatarImage:(NSImage *)image {
0
+ [gravatarCell setImage:image];
0
+}
0
+
0
+- (void)setSubtitle:(NSString *)string {
0
+ [subtitleCell setStringValue:string];
0
+}
0
+
0
+- (void)setObjectValue:(id)object {
0
+ [titleCell setObjectValue:object];
0
+}
0
+
0
+- (void)setBackgroundStyle:(NSBackgroundStyle)style {
0
+ [super setBackgroundStyle:style];
0
+
0
+ [titleCell setBackgroundStyle:style];
0
+
0
+ [subtitleCell setBackgroundStyle:style];
0
+ [subtitleCell setTextColor:(style == NSBackgroundStyleLight) ? [NSColor disabledControlTextColor] : [NSColor controlTextColor]];
0
+}
0
+
0
+- (NSRect)expansionFrameWithFrame:(NSRect)cellFrame inView:(NSView *)view {
0
+ NSSize fullSize = [[titleCell attributedStringValue] size];
0
+ fullSize.width += PADDING + GRAVATAR_WIDTH;
0
+
0
+ if(fullSize.width > NSWidth(cellFrame)) {
0
+ cellFrame.size.width = fullSize.width;
0
+ } else {
0
+ cellFrame = NSZeroRect;
0
+ }
0
+
0
+ return cellFrame;
0
+}
0
+
0
+- (NSRect)titleRectForBounds:(NSRect)theRect {
0
+ NSRect imageRect, titleRect;
0
+ theRect = NSInsetRect(theRect, PADDING, PADDING);
0
+ NSDivideRect(theRect, &imageRect, &titleRect, GRAVATAR_WIDTH + 4, NSMinXEdge);
0
+ NSSize stringSize = [[titleCell attributedStringValue] size];
0
+ //titleRect.origin.y += (NSHeight(titleRect) - stringSize.height)/2.0;
0
+ titleRect.origin.x += PADDING;
0
+ titleRect.size.height = stringSize.height;
0
+
0
+ return titleRect;
0
+}
0
+
0
+- (NSRect)subtitleRectForBounds:(NSRect)theRect {
0
+ theRect = [self titleRectForBounds:theRect];
0
+ theRect.origin.y += NSHeight(theRect) + PADDING;
0
+ return theRect;
0
+}
0
+
0
+- (NSRect)gravatarRectForBounds:(NSRect)theRect {
0
+ NSRect imageRect, titleRect;
0
+ theRect = NSInsetRect(theRect, PADDING, PADDING);
0
+ NSDivideRect(theRect, &imageRect, &titleRect, GRAVATAR_WIDTH + 4, NSMinXEdge);
0
+ return imageRect;
0
+}
0
+
0
+- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)view {
0
+ [titleCell drawInteriorWithFrame:[self titleRectForBounds:cellFrame] inView:view];
0
+ [subtitleCell drawInteriorWithFrame:[self subtitleRectForBounds:cellFrame] inView:view];
0
+ [gravatarCell drawInteriorWithFrame:[self gravatarRectForBounds:cellFrame] inView:view];
0
+}
0
+@end
...
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
...
87
88
89
 
 
90
 
 
91
92
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
95
96
97
98
99
100
101
0
@@ -87,28 +87,15 @@
0
     @commits ? @commits.size : 0
0
   end
0
   
0
- # There is something fishy with ImageTextCell and this method so
0
- # we set the commit object to be used in dataElementForCell and return nil
0
   def tableView_objectValueForTableColumn_row(table_view, table_column, row)
0
- @commit = @commits[row]
0
- return nil
0
+ @commits[row].message.gsub(/\n/, ' ').to_s
0
   end
0
   
0
- # ImageTextCell data methods
0
- def primaryTextForCell_data(cell, data)
0
- data.message.gsub(/\n/, ' ').to_s
0
- end
0
-
0
- def secondaryTextForCell_data(cell, data)
0
- %(by #{data.committer.name} on #{data.committed_date.strftime("%A, %b %d, %I:%M %p")})
0
- end
0
-
0
- def iconForCell_data(icon, data)
0
- @icons[data.committer.email]
0
- end
0
-
0
- def dataElementForCell(cell)
0
- @commit
0
+ objc_method :tableView_willDisplayCell_forTableColumn_row, 'v@:@@@i'
0
+ def tableView_willDisplayCell_forTableColumn_row(table_view, cell, table_column, row)
0
+ commit = @commits[row]
0
+ cell.subtitle = %(by #{commit.committer.name} on #{commit.committed_date.strftime("%A, %b %d, %I:%M %p")})
0
+ cell.gravatarImage = @icons[commit.committer.email]
0
   end
0
   
0
   def webView_didFinishLoadForFrame(view, frame)
...
8
9
10
11
12
13
14
15
...
28
29
30
 
 
31
32
33
...
50
51
52
53
54
55
56
57
...
73
74
75
 
 
76
77
78
...
99
100
101
 
 
102
103
104
...
157
158
159
160
161
162
163
164
...
202
203
204
205
 
206
207
208
...
297
298
299
300
 
301
302
303
...
8
9
10
 
 
11
12
13
...
26
27
28
29
30
31
32
33
...
50
51
52
 
 
53
54
55
...
71
72
73
74
75
76
77
78
...
99
100
101
102
103
104
105
106
...
159
160
161
 
 
162
163
164
...
202
203
204
 
205
206
207
208
...
297
298
299
 
300
301
302
303
0
@@ -8,8 +8,6 @@
0
 
0
 /* Begin PBXBuildFile section */
0
     285BB47C0D8306C60027980C /* mime-types in Resources */ = {isa = PBXBuildFile; fileRef = 285BB4690D8306C60027980C /* mime-types */; };
0
-    285BB5300D849C890027980C /* ImageTextCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 285BB52D0D849C890027980C /* ImageTextCell.h */; };
0
-    285BB5310D849C890027980C /* ImageTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 285BB52E0D849C890027980C /* ImageTextCell.m */; };
0
     285BB5320D849C890027980C /* TexturedWindow.rb in Resources */ = {isa = PBXBuildFile; fileRef = 285BB52F0D849C890027980C /* TexturedWindow.rb */; };
0
     285BB53D0D849DD20027980C /* added.png in Resources */ = {isa = PBXBuildFile; fileRef = 285BB5380D849DD20027980C /* added.png */; };
0
     285BB53E0D849DD20027980C /* committer.png in Resources */ = {isa = PBXBuildFile; fileRef = 285BB5390D849DD20027980C /* committer.png */; };
0
@@ -28,6 +26,8 @@
0
     288CB41A0D8789DD0092B5CC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 288CB4180D8789DD0092B5CC /* MainMenu.xib */; };
0
     288CB41D0D878A1C0092B5CC /* Info.xib in Resources */ = {isa = PBXBuildFile; fileRef = 288CB41C0D878A1C0092B5CC /* Info.xib */; };
0
     28DA55180D84C3A600D39FBF /* refresh.png in Resources */ = {isa = PBXBuildFile; fileRef = 28DA55170D84C3A600D39FBF /* refresh.png */; };
0
+    4D922CA80D8889DB002A5539 /* CommitSummaryCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D922CA60D8889DB002A5539 /* CommitSummaryCell.h */; };
0
+    4D922CA90D8889DB002A5539 /* CommitSummaryCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D922CA70D8889DB002A5539 /* CommitSummaryCell.m */; };
0
     4DDCA7070ACC9A6100E082CE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
0
     4DDCA7080ACC9A6100E082CE /* rb_main.rb in Resources */ = {isa = PBXBuildFile; fileRef = E8F5E25803AEB7C803A81C6F /* rb_main.rb */; };
0
     4DDCA70A0ACC9A6100E082CE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
0
@@ -50,8 +50,6 @@
0
     1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
0
     284B71470D7CDE340075DA6C /* nub.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = nub.xcodeproj; path = nub/nub.xcodeproj; sourceTree = "<group>"; };
0
     285BB4690D8306C60027980C /* mime-types */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "mime-types"; sourceTree = "<group>"; };
0
-    285BB52D0D849C890027980C /* ImageTextCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageTextCell.h; sourceTree = "<group>"; };
0
-    285BB52E0D849C890027980C /* ImageTextCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageTextCell.m; sourceTree = "<group>"; };
0
     285BB52F0D849C890027980C /* TexturedWindow.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = TexturedWindow.rb; sourceTree = "<group>"; };
0
     285BB5380D849DD20027980C /* added.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = added.png; sourceTree = "<group>"; };
0
     285BB5390D849DD20027980C /* committer.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = committer.png; sourceTree = "<group>"; };
0
@@ -73,6 +71,8 @@
0
     29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
0
     29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
0
     29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
0
+    4D922CA60D8889DB002A5539 /* CommitSummaryCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommitSummaryCell.h; sourceTree = "<group>"; };
0
+    4D922CA70D8889DB002A5539 /* CommitSummaryCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommitSummaryCell.m; sourceTree = "<group>"; };
0
     4DDCA7110ACC9A6100E082CE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; };
0
     4DDCA7120ACC9A6100E082CE /* GitNub.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GitNub.app; sourceTree = BUILT_PRODUCTS_DIR; };
0
     E8F5E24E03AEB6EC03A81C6F /* RubyCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RubyCocoa.framework; path = /Library/Frameworks/RubyCocoa.framework; sourceTree = "<absolute>"; };
0
@@ -99,6 +99,8 @@
0
         285BB5450D849EA60027980C /* ApplicationController.rb */,
0
         285BB5460D849EA60027980C /* CommitsController.rb */,
0
         285BB5470D849EA60027980C /* InfoWindowController.rb */,
0
+        4D922CA60D8889DB002A5539 /* CommitSummaryCell.h */,
0
+        4D922CA70D8889DB002A5539 /* CommitSummaryCell.m */,
0
       );
0
       name = Classes;
0
       sourceTree = "<group>";
0
@@ -157,8 +159,6 @@
0
     29B97315FDCFA39411CA2CEA /* Other Sources */ = {
0
       isa = PBXGroup;
0
       children = (
0
-        285BB52D0D849C890027980C /* ImageTextCell.h */,
0
-        285BB52E0D849C890027980C /* ImageTextCell.m */,
0
         285BB52F0D849C890027980C /* TexturedWindow.rb */,
0
         285BB4690D8306C60027980C /* mime-types */,
0
         288854540D7E352C00862D67 /* grit */,
0
@@ -202,7 +202,7 @@
0
       isa = PBXHeadersBuildPhase;
0
       buildActionMask = 2147483647;
0
       files = (
0
-        285BB5300D849C890027980C /* ImageTextCell.h in Headers */,
0
+        4D922CA80D8889DB002A5539 /* CommitSummaryCell.h in Headers */,
0
       );
0
       runOnlyForDeploymentPostprocessing = 0;
0
     };
0
@@ -297,7 +297,7 @@
0
       buildActionMask = 2147483647;
0
       files = (
0
         4DDCA70A0ACC9A6100E082CE /* main.m in Sources */,
0
-        285BB5310D849C890027980C /* ImageTextCell.m in Sources */,
0
+        4D922CA90D8889DB002A5539 /* CommitSummaryCell.m in Sources */,
0
       );
0
       runOnlyForDeploymentPostprocessing = 0;
0
     };
...
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
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,43 +1 @@
0
-//
0
-// ImageTextCell.h
0
-// SofaControl
0
-//
0
-// Created by Martin Kahr on 10.10.06.
0
-// Copyright 2006 CASE Apps. All rights reserved.
0
-//
0
-
0
-#import <Cocoa/Cocoa.h>
0
-
0
-
0
-@interface ImageTextCell : NSTextFieldCell {
0
-  NSObject* delegate;
0
-  NSString* iconKeyPath;
0
-  NSString* primaryTextKeyPath;
0
-  NSString* secondaryTextKeyPath;
0
-}
0
-
0
-- (void) setDataDelegate: (NSObject*) aDelegate;
0
-
0
-- (void) setIconKeyPath: (NSString*) path;
0
-- (void) setPrimaryTextKeyPath: (NSString*) path;
0
-- (void) setSecondaryTextKeyPath: (NSString*) path;
0
-
0
-@end
0
-
0
-@interface NSObject(ImageTextCellDelegate)
0
-
0
-- (NSImage*) iconForCell: (ImageTextCell*) cell data: (NSObject*) data;
0
-- (NSString*) primaryTextForCell: (ImageTextCell*) cell data: (NSObject*) data;
0
-- (NSString*) secondaryTextForCell: (ImageTextCell*) cell data: (NSObject*) data;
0
-
0
-// optional: give the delegate a chance to set a different data object
0
-// This is especially useful for those cases where you do not want that NSCell creates copies of your data objects (e.g. Core Data objects).
0
-// In this case you bind a value to the NSTableColumn that enables you to retrieve the correct data object. You retrieve the objects
0
-// in the method dataElementForCell
0
-- (NSObject*) dataElementForCell: (ImageTextCell*) cell;
0
-
0
-// optional
0
-- (BOOL) disabledForCell: (ImageTextCell*) cell data: (NSObject*) data;
0
-
0
-@end
...
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
131
132
133
134
135
136
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,137 +1 @@
0
-//
0
-// ImageTextCell.m
0
-// SofaControl
0
-//
0
-// Created by Martin Kahr on 10.10.06.
0
-// Copyright 2006 CASE Apps. All rights reserved.
0
-//
0
-
0
-#import "ImageTextCell.h"
0
-
0
-@implementation ImageTextCell
0
-
0
-- (void)dealloc {
0
-  [self setDataDelegate: nil];
0
-  [self setIconKeyPath: nil];
0
-  [self setPrimaryTextKeyPath: nil];
0
-  [self setSecondaryTextKeyPath: nil];
0
- [super dealloc];
0
-}
0
-
0
-- copyWithZone:(NSZone *)zone {
0
-  ImageTextCell *cell = (ImageTextCell *)[super copyWithZone:zone];
0
-  cell->delegate = nil;
0
-  [cell setDataDelegate: delegate];
0
- return cell;
0
-}
0
-
0
-- (void) setIconKeyPath: (NSString*) path {
0
-  [iconKeyPath autorelease];
0
-  iconKeyPath = [path retain];
0
-}
0
-- (void) setPrimaryTextKeyPath: (NSString*) path {
0
-  [primaryTextKeyPath autorelease];
0
-  primaryTextKeyPath = [path retain];  
0
-}
0
-- (void) setSecondaryTextKeyPath: (NSString*) path {
0
-  [secondaryTextKeyPath autorelease];
0
-  secondaryTextKeyPath = [path retain];  
0
-}
0
-
0
-- (void) setDataDelegate: (NSObject*) aDelegate {
0
-  [aDelegate retain];  
0
-  [delegate autorelease];
0
-  delegate = aDelegate;  
0
-}
0
-
0
-- (id) dataDelegate {
0
-  if (delegate) return delegate;
0
-  return self; // in case there is no delegate we try to resolve values by using key paths
0
-}
0
-
0
-- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
0
-  [self setTextColor:[NSColor blackColor]];
0
-  
0
-  NSObject* data = [self objectValue];
0
-  
0
-  // give the delegate a chance to set a different data object
0
-  if ([[self dataDelegate] respondsToSelector: @selector(dataElementForCell:)]) {
0
-    data = [[self dataDelegate] dataElementForCell:self];
0
-  }
0
-    
0
-  //TODO: Selection with gradient and selection color in white with shadow
0
-  // check out http://www.cocoadev.com/index.pl?NSTableView
0
-  
0
-  BOOL elementDisabled = NO;  
0
-  if ([[self dataDelegate] respondsToSelector: @selector(disabledForCell:data:)]) {
0
-    elementDisabled = [[self dataDelegate] disabledForCell: self data: data];
0
-  }
0
-  
0
-  NSColor* primaryColor = [self isHighlighted] ? [NSColor alternateSelectedControlTextColor] : (elementDisabled? [NSColor disabledControlTextColor] : [NSColor textColor]);
0
-  NSString* primaryText = [[self dataDelegate] primaryTextForCell:self data: data];
0
- NSMutableParagraphStyle* style = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
0
- [style setLineBreakMode:NSLineBreakByTruncatingTail];
0
-
0
-  NSDictionary* primaryTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
0
-   primaryColor, NSForegroundColorAttributeName,
0
-    [NSFont systemFontOfSize:12], NSFontAttributeName,
0
-    style, NSParagraphStyleAttributeName,
0
-    nil];  
0
-  [primaryText drawAtPoint:NSMakePoint(cellFrame.origin.x+cellFrame.size.height+9, cellFrame.origin.y) withAttributes:primaryTextAttributes];
0
-  
0
-  NSColor* secondaryColor = [self isHighlighted] ? [NSColor alternateSelectedControlTextColor] : [NSColor disabledControlTextColor];
0
-  NSString* secondaryText = [[self dataDelegate] secondaryTextForCell:self data: data];
0
-  NSDictionary* secondaryTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: secondaryColor, NSForegroundColorAttributeName,
0
-    [NSFont systemFontOfSize:10], NSFontAttributeName, nil];  
0
-  [secondaryText drawAtPoint:NSMakePoint(cellFrame.origin.x+cellFrame.size.height+9, cellFrame.origin.y+cellFrame.size.height/2.2)
0
-        withAttributes:secondaryTextAttributes];
0
-  
0
-  
0
-  [[NSGraphicsContext currentContext] saveGraphicsState];
0
-  float yOffset = cellFrame.origin.y;
0
-  if ([controlView isFlipped]) {
0
-    NSAffineTransform* xform = [NSAffineTransform transform];
0
-    [xform translateXBy:0.0 yBy: cellFrame.size.height];
0
-    [xform scaleXBy:1.0 yBy:-1.0];
0
-    [xform concat];    
0
-    yOffset = 0-cellFrame.origin.y;
0
-  }  
0
-  NSImage* icon = [[self dataDelegate] iconForCell:self data: data];  
0
-  
0
-  NSImageInterpolation interpolation = [[NSGraphicsContext currentContext] imageInterpolation];
0
-  [[NSGraphicsContext currentContext] setImageInterpolation: NSImageInterpolationHigh];  
0
-  
0
-  [icon drawInRect:NSMakeRect(cellFrame.origin.x+3,yOffset+3,cellFrame.size.height-6, cellFrame.size.height-6)
0
-      fromRect:NSMakeRect(0,0,[icon size].width, [icon size].height)
0
-     operation:NSCompositeSourceOver
0
-      fraction:1.0];
0
-  
0
-  [[NSGraphicsContext currentContext] setImageInterpolation: interpolation];
0
-  
0
-  [[NSGraphicsContext currentContext] restoreGraphicsState];  
0
-}
0
-
0
-#pragma mark -
0
-#pragma mark Delegate methods
0
-
0
-- (NSImage*) iconForCell: (ImageTextCell*) cell data: (NSObject*) data {
0
-  if (iconKeyPath) {
0
-    return [data valueForKeyPath: iconKeyPath];
0
-  }
0
-  return nil;
0
-}
0
-- (NSString*) primaryTextForCell: (ImageTextCell*) cell data: (NSObject*) data {
0
-  if (primaryTextKeyPath) {
0
-    return [data valueForKeyPath: primaryTextKeyPath];
0
-  }
0
-  return nil;  
0
-}
0
-- (NSString*) secondaryTextForCell: (ImageTextCell*) cell data: (NSObject*) data {
0
-  if (primaryTextKeyPath) {
0
-    return [data valueForKeyPath: secondaryTextKeyPath];
0
-  }
0
-  return nil;    
0
-}
0
-
0
-@end

Comments

    No one has commented yet.