Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 138 lines (111 sloc) 3.006 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 131 132 133 134 135 136 137 138
//
// PBSourceViewItem.m
// GitX
//
// Created by Pieter de Bie on 9/8/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "PBSourceViewItem.h"
#import "PBSourceViewItems.h"
#import "PBGitRef.h"

@implementation PBSourceViewItem
@synthesize parent, title, isGroupItem, children, revSpecifier, isUncollapsible;
@dynamic icon;

- (id)init
{
if (!(self = [super init]))
return nil;

children = [NSMutableArray array];
return self;
}

+ (id)itemWithTitle:(NSString *)title
{
PBSourceViewItem *item = [[[self class] alloc] init];
item.title = title;
return item;
}

+ (id)groupItemWithTitle:(NSString *)title
{
PBSourceViewItem *item = [self itemWithTitle:[title uppercaseString]];
item.isGroupItem = YES;
return item;
}

+ (id)itemWithRevSpec:(PBGitRevSpecifier *)revSpecifier
{
PBGitRef *ref = [revSpecifier ref];

if ([ref isTag])
return [PBGitSVTagItem tagItemWithRevSpec:revSpecifier];
else if ([ref isBranch])
return [PBGitSVBranchItem branchItemWithRevSpec:revSpecifier];
else if ([ref isRemoteBranch])
return [PBGitSVRemoteBranchItem remoteBranchItemWithRevSpec:revSpecifier];

return [PBGitSVOtherRevItem otherItemWithRevSpec:revSpecifier];
}

- (void)addChild:(PBSourceViewItem *)child
{
if (!child)
return;

[self.children addObject:child];
child.parent = self;
[self.children sortUsingDescriptors:[NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]]];
}

- (void)removeChild:(PBSourceViewItem *)child
{
if (!child)
return;

[self.children removeObject:child];
if (!self.isGroupItem && ([self.children count] == 0))
[self.parent removeChild:self];
}

- (void)addRev:(PBGitRevSpecifier *)theRevSpecifier toPath:(NSArray *)path
{
if ([path count] == 1) {
PBSourceViewItem *item = [PBSourceViewItem itemWithRevSpec:theRevSpecifier];
[self addChild:item];
return;
}

NSString *firstTitle = [path objectAtIndex:0];
PBSourceViewItem *node = nil;
for (PBSourceViewItem *child in [self children])
if ([child.title isEqualToString:firstTitle])
node = child;

if (!node) {
if ([firstTitle isEqualToString:[[theRevSpecifier ref] remoteName]])
node = [PBGitSVRemoteItem remoteItemWithTitle:firstTitle];
else
node = [PBGitSVFolderItem folderItemWithTitle:firstTitle];
[self addChild:node];
}

[node addRev:theRevSpecifier toPath:[path subarrayWithRange:NSMakeRange(1, [path count] - 1)]];
}

- (PBSourceViewItem *)findRev:(PBGitRevSpecifier *)rev
{
if (rev == revSpecifier)
return self;

PBSourceViewItem *item = nil;
for (PBSourceViewItem *child in children)
if (item = [child findRev:rev])
return item;

return nil;
}

- (NSImage *) icon
{
return nil;
}

- (NSString *)title
{
if (title)
return title;

return [[revSpecifier description] lastPathComponent];
}

- (NSString *) stringValue
{
return self.title;
}

- (PBGitRef *) ref
{
if (self.revSpecifier)
return [self.revSpecifier ref];

return nil;
}

@end
Something went wrong with that request. Please try again.