Refactor cellInfo structure

This makes the PBGitRevisionCell a bit nicer by retrieving all values
from the PBGitCommit object itself, and using another NSTextFieldCell to
draw the text.

This mean that PBGitGrapher now stores its information in the PBGitCommit's,
rather than in a custom grapher array. Also, because we don't need the
grapher to display refs anymore, the ref labels are also displayed when
using path limiting (for example, 'gitx -- Makefile').
This commit is contained in:
Pieter de Bie
2008-09-18 01:27:05 +02:00
parent 48fa140813
commit 6e978dcea4
10 changed files with 92 additions and 88 deletions
+38 -21
View File
@@ -2,13 +2,13 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.02">
<data>
<int key="IBDocument.SystemTarget">1050</int>
<string key="IBDocument.SystemVersion">9E17</string>
<string key="IBDocument.SystemVersion">9F33</string>
<string key="IBDocument.InterfaceBuilderVersion">670</string>
<string key="IBDocument.AppKitVersion">949.33</string>
<string key="IBDocument.AppKitVersion">949.34</string>
<string key="IBDocument.HIToolboxVersion">352.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="11"/>
<integer value="15"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1831,22 +1831,6 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ</bytes>
</object>
<int key="connectionID">84</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: arrangedObjects.subject</string>
<reference key="source" ref="855592717"/>
<reference key="destination" ref="340269780"/>
<object class="NSNibBindingConnector" key="connector">
<reference key="NSSource" ref="855592717"/>
<reference key="NSDestination" ref="340269780"/>
<string key="NSLabel">value: arrangedObjects.subject</string>
<string key="NSBinding">value</string>
<string key="NSKeyPath">arrangedObjects.subject</string>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
<int key="connectionID">85</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: arrangedObjects.author</string>
@@ -2242,6 +2226,26 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ</bytes>
</object>
<int key="connectionID">233</int>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">value: arrangedObjects</string>
<reference key="source" ref="855592717"/>
<reference key="destination" ref="340269780"/>
<object class="NSNibBindingConnector" key="connector">
<reference key="NSSource" ref="855592717"/>
<reference key="NSDestination" ref="340269780"/>
<string key="NSLabel">value: arrangedObjects</string>
<string key="NSBinding">value</string>
<string key="NSKeyPath">arrangedObjects</string>
<object class="NSDictionary" key="NSOptions">
<string key="NS.key.0">NSConditionallySetsEditable</string>
<integer value="1" key="NS.object.0"/>
</object>
<int key="NSNibBindingConnectorVersion">2</int>
</object>
</object>
<int key="connectionID">243</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -3010,7 +3014,7 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ</bytes>
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">233</int>
<int key="maxID">243</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3094,7 +3098,20 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ</bytes>
</object>
<object class="IBPartialClassDescription">
<string key="className">PBGitRevisionCell</string>
<string key="superclassName">NSTextFieldCell</string>
<string key="superclassName">NSCell</string>
<object class="NSMutableDictionary" key="outlets">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>objectValue</string>
<string>value</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">PBGitRevisionCell.h</string>
-14
View File
@@ -160,18 +160,4 @@
int index = [[commitController selectionIndexes] firstIndex];
[commitList scrollRowToVisible: index];
}
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
if (![[aTableColumn identifier] isEqualToString:@"subject"])
return;
PBGitRevisionCell* cell = aCell;
if (self.repository.revisionList.grapher &&
![commitController filterPredicate] &&
[[commitController sortDescriptors] count] == 0) {
PBGitGrapher* g = self.repository.revisionList.grapher;
[cell setCellInfo: [g cellInfoForRow:rowIndex]];
}
}
@end
+4 -1
View File
@@ -16,8 +16,10 @@
NSString* author;
NSString* details;
NSArray* parents;
NSArray* refs;
NSDate* date;
char sign;
id lineInfo;
PBGitRepository* repository;
}
@@ -26,7 +28,7 @@
@property (copy) NSString* sha;
@property (copy) NSString* subject;
@property (copy) NSString* author;
@property (retain) NSArray* parents;
@property (retain) NSArray* parents, *refs;
@property (copy) NSDate* date;
@property (readonly) NSString* dateString;
@property (assign) char sign;
@@ -35,4 +37,5 @@
@property (readonly) PBGitTree* tree;
@property (readonly) NSArray* treeContents;
@property (retain) PBGitRepository* repository;
@property (retain) id lineInfo;
@end
+1 -1
View File
@@ -11,7 +11,7 @@
@implementation PBGitCommit
@synthesize sha, repository, subject, author, date, parents, sign;
@synthesize sha, repository, subject, author, date, parents, sign, lineInfo, refs;
- (NSString *) dateString
-2
View File
@@ -22,12 +22,10 @@ struct PBGitGraphColumn {
@interface PBGitGrapher : NSObject {
PBGraphCellInfo* previous;
NSMutableArray* previousLanes;
NSMutableArray* cellsInfo;
NSDictionary* refs;
PBGitRepository* repository;
}
- (id) initWithRepository: (PBGitRepository*) repo;
- (void) decorateCommit: (PBGitCommit *) commit;
- (PBGraphCellInfo*) cellInfoForRow: (int) row;
@end
+2 -11
View File
@@ -15,9 +15,7 @@
- (id) initWithRepository: (PBGitRepository*) repo
{
refs = repo.refs;
// We don't know how many commits to parse.
cellsInfo = [NSMutableArray arrayWithCapacity:100];
repository = repo;
previousLanes = [NSMutableArray array];
return self;
@@ -119,8 +117,6 @@
previous = [[PBGraphCellInfo alloc] initWithPosition:newPos andLines:lines];
previous.sign = commit.sign;
if (refs && [refs objectForKey:commit.sha])
previous.refs = [refs objectForKey:commit.sha];
// If a parent was added, we have room to not indent.
if (addedParent)
@@ -134,12 +130,7 @@
[currentLanes removeObject:currentLane];
previousLanes = currentLanes;
[cellsInfo addObject: previous];
}
- (PBGraphCellInfo*) cellInfoForRow: (int) row
{
return [cellsInfo objectAtIndex: row];
commit.lineInfo = previous;
}
- (void) finalize
-2
View File
@@ -11,7 +11,6 @@
@interface PBGitRevList : NSObject {
NSArray* commits;
id grapher;
id repository;
NSString* lastSha;
}
@@ -20,6 +19,5 @@
- (void) readCommits;
@property(retain) NSArray* commits;
@property(retain) id grapher;
@end
+6 -3
View File
@@ -14,7 +14,7 @@
@implementation PBGitRevList
@synthesize commits, grapher;
@synthesize commits;
- initWithRepository: (id) repo
{
repository = repo;
@@ -142,6 +142,7 @@ struct decorateParameters {
{
NSMutableArray* revisions = params->revisions;
PBGitRevSpecifier* rev = params->rev;
NSDictionary* refs = [repository refs];
BOOL decorateCommits = ![rev hasPathLimiter];
NSDate* start = [NSDate date];
@@ -150,8 +151,6 @@ struct decorateParameters {
int num = 0;
PBGitGrapher* g = [[PBGitGrapher alloc] initWithRepository: repository];
if (decorateCommits)
[self performSelectorOnMainThread:@selector(setGrapher:) withObject:g waitUntilDone:YES];
while (!([[NSThread currentThread] isCancelled] && [revisions count] == 0)) {
if ([revisions count] == 0)
@@ -166,6 +165,10 @@ struct decorateParameters {
num++;
if (decorateCommits)
[g decorateCommit: commit];
if (refs && [refs objectForKey:commit.sha])
commit.refs = [refs objectForKey:commit.sha];
[allRevisions addObject: commit];
if (num % 1000 == 0 || num == 10)
[self performSelectorOnMainThread:@selector(setCommits:) withObject:allRevisions waitUntilDone:NO];
+6 -4
View File
@@ -8,11 +8,13 @@
#import <Cocoa/Cocoa.h>
#import "PBGitGrapher.h"
#import "PBGraphCellInfo.h"
@interface PBGitRevisionCell : NSTextFieldCell {
PBGraphCellInfo* cellInfo;
BOOL isReady;
@interface PBGitRevisionCell : NSActionCell {
id objectValue;
PBGraphCellInfo* cellInfo;
NSTextFieldCell* textCell;
}
@property(assign) PBGraphCellInfo* cellInfo;
@property(retain) PBGitCommit* objectValue;
@end
+35 -29
View File
@@ -58,19 +58,11 @@
@implementation PBGitRevisionCell
@synthesize cellInfo;
-(void) setCellInfo: (PBGraphCellInfo*) info
{
isReady = YES;
cellInfo = info;
}
- (id) initWithCoder: (id) coder
{
self = [super initWithCoder:coder];
if (self != nil) {
isReady = NO;
}
textCell = [[NSTextFieldCell alloc] initWithCoder:coder];
return self;
}
@@ -196,13 +188,14 @@
static const float ref_padding = 10.0f;
static const float ref_spacing = 2.0f;
NSArray* refs = [self.objectValue refs];
NSRect refRect = (NSRect){rect->origin, rect->size};
[[NSColor blackColor] setStroke];
int index;
for (index = 0; index < [cellInfo.refs count]; ++index) {
PBGitRef* ref = [cellInfo.refs objectAtIndex:index];
for (index = 0; index < [refs count]; ++index) {
PBGitRef* ref = [refs objectAtIndex:index];
NSMutableDictionary* attributes = [self attributesForRefLabelSelected:[self isHighlighted]];
NSSize refSize = [[ref shortName] sizeWithAttributes:attributes];
@@ -231,31 +224,44 @@
- (void) drawWithFrame: (NSRect) rect inView:(NSView *)view
{
if (!isReady)
return [super drawWithFrame:rect inView:view];
cellInfo = [self.objectValue lineInfo];
if (cellInfo) {
float pathWidth = 10 + 10 * cellInfo.numColumns;
float pathWidth = 10 + 10 * cellInfo.numColumns;
NSRect ownRect;
NSDivideRect(rect, &ownRect, &rect, pathWidth, NSMinXEdge);
NSRect ownRect;
NSDivideRect(rect, &ownRect, &rect, pathWidth, NSMinXEdge);
for (PBGitGraphLine* line in cellInfo.lines) {
if (line.upper == 0)
[self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: ownRect.size.height color: line.colorIndex];
else
[self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: 0 color:line.colorIndex];
}
for (PBGitGraphLine* line in cellInfo.lines) {
if (line.upper == 0)
[self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: ownRect.size.height color: line.colorIndex];
if (cellInfo.sign == '<' || cellInfo.sign == '>')
[self drawTriangleInRect: ownRect sign: cellInfo.sign];
else
[self drawLineFromColumn: line.from toColumn: line.to inRect:ownRect offset: 0 color:line.colorIndex];
[self drawCircleInRect: ownRect];
}
if (cellInfo.sign == '<' || cellInfo.sign == '>')
[self drawTriangleInRect: ownRect sign: cellInfo.sign];
else
[self drawCircleInRect: ownRect];
if (cellInfo.refs)
if ([self.objectValue refs])
[self drawRefsInRect:&rect];
[super drawWithFrame:rect inView:view];
isReady = NO;
// Still use this superclass because of hilighting differences
//_contents = [self.objectValue subject];
//[super drawWithFrame:rect inView:view];
[textCell setObjectValue: [self.objectValue subject]];
[textCell setHighlighted: [self isHighlighted]];
[textCell drawWithFrame:rect inView: view];
}
- (void) setObjectValue: (PBGitCommit*)object {
[super setObjectValue:[NSValue valueWithNonretainedObject:object]];
}
- (PBGitCommit*) objectValue {
return [[super objectValue] nonretainedObjectValue];
}
@end