mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
SideBar: Add branches as children
This makes a nice tree, which should be more readable than the existing list. The local branches are expanded by default.
This commit is contained in:
@@ -78,14 +78,17 @@
|
||||
|
||||
for (PBGitRevSpecifier *rev in repository.branches)
|
||||
{
|
||||
if (![rev isSimpleRef])
|
||||
if (![rev isSimpleRef]) {
|
||||
[custom addChild:[PBSourceViewItem itemWithRevSpec:rev]];
|
||||
else if ([[rev simpleRef] hasPrefix:@"refs/heads/"])
|
||||
[branches addChild:[PBSourceViewItem itemWithRevSpec:rev]];
|
||||
continue;
|
||||
}
|
||||
NSArray *pathComponents = [[rev simpleRef] componentsSeparatedByString:@"/"];
|
||||
if ([[pathComponents objectAtIndex:1] isEqualToString:@"heads"])
|
||||
[branches addRev:rev toPath:[pathComponents subarrayWithRange:NSMakeRange(2, [pathComponents count] - 2)]];
|
||||
else if ([[rev simpleRef] hasPrefix:@"refs/tags/"])
|
||||
[tags addChild:[PBSourceViewItem itemWithRevSpec:rev]];
|
||||
[tags addRev:rev toPath:[pathComponents subarrayWithRange:NSMakeRange(2, [pathComponents count] - 2)]];
|
||||
else if ([[rev simpleRef] hasPrefix:@"refs/remotes/"])
|
||||
[remotes addChild:[PBSourceViewItem itemWithRevSpec:rev]];
|
||||
[remotes addRev:rev toPath:[pathComponents subarrayWithRange:NSMakeRange(2, [pathComponents count] - 2)]];
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,15 @@
|
||||
|
||||
+ (PBSourceViewItem *)groupItemWithTitle:(NSString *)title;
|
||||
+ (PBSourceViewItem *)itemWithRevSpec:(PBGitRevSpecifier *)revSpecifier;
|
||||
+ (PBSourceViewItem *)itemWithTitle:(NSString *)title;
|
||||
|
||||
- (void)addChild:(PBSourceViewItem *)child;
|
||||
|
||||
// This adds the ref to the path, which should match the item's title,
|
||||
// so "refs/heads/pu/pb/sidebar" would have the path [@"pu", @"pb", @"sidebare"]
|
||||
// to the 'local' branch thing
|
||||
- (void)addRev:(PBGitRevSpecifier *)revSpecifier toPath:(NSArray *)path;
|
||||
|
||||
@property(retain) NSString *title;
|
||||
@property(readonly) NSMutableArray *children;
|
||||
@property(assign) BOOL isGroupItem;
|
||||
|
||||
+30
-1
@@ -37,17 +37,46 @@
|
||||
return item;
|
||||
}
|
||||
|
||||
+ (PBSourceViewItem *)itemWithTitle:(NSString *)title;
|
||||
{
|
||||
PBSourceViewItem *item = [[PBSourceViewItem alloc] init];
|
||||
item.title = title;
|
||||
return item;
|
||||
}
|
||||
|
||||
- (void)addChild:(PBSourceViewItem *)child
|
||||
{
|
||||
[self.children addObject:child];
|
||||
}
|
||||
|
||||
- (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) {
|
||||
node = [PBSourceViewItem itemWithTitle:firstTitle];
|
||||
[self addChild:node];
|
||||
}
|
||||
|
||||
[node addRev:theRevSpecifier toPath:[path subarrayWithRange:NSMakeRange(1, [path count] - 1)]];
|
||||
}
|
||||
|
||||
- (NSString *)title
|
||||
{
|
||||
if (title)
|
||||
return title;
|
||||
|
||||
return [revSpecifier description];
|
||||
return [[revSpecifier description] lastPathComponent];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user