mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Sidebar: populate with branches
This is far from perfect, but should indicate which direction this is going in
This commit is contained in:
+108
-1
@@ -9,6 +9,12 @@
|
||||
#import "PBGitSidebarController.h"
|
||||
#import "PBSourceViewItem.h"
|
||||
|
||||
@interface PBGitSidebarController ()
|
||||
|
||||
- (void)populateList;
|
||||
|
||||
@end
|
||||
|
||||
@implementation PBGitSidebarController
|
||||
@synthesize items;
|
||||
|
||||
@@ -17,13 +23,114 @@
|
||||
self = [super initWithRepository:theRepository superController:controller];
|
||||
[sourceView setDelegate:self];
|
||||
items = [NSMutableArray array];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
window.contentView = self.view;
|
||||
[super awakeFromNib];
|
||||
window.contentView = self.view;
|
||||
[self populateList];
|
||||
}
|
||||
|
||||
#pragma mark NSOutlineView delegate methods
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
|
||||
{
|
||||
return [item isGroupItem];
|
||||
}
|
||||
|
||||
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
|
||||
{
|
||||
if ([item isGroupItem])
|
||||
[cell setImage:nil];
|
||||
else
|
||||
[cell setImage:[NSImage imageNamed:@"new_file"]];
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
|
||||
{
|
||||
return ![item isGroupItem];
|
||||
}
|
||||
|
||||
//
|
||||
// The next two methods are necessary to hide the triangle for uncollapsible items
|
||||
// That is, items which should always be displayed, such as the action items.
|
||||
//
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:(id)item
|
||||
{
|
||||
return !([item isUncollapsible]);
|
||||
}
|
||||
|
||||
- (void)outlineView:(NSOutlineView *)outlineView willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
|
||||
{
|
||||
[cell setTransparent:[item isUncollapsible]];
|
||||
}
|
||||
|
||||
- (void)populateList
|
||||
{
|
||||
PBSourceViewItem *actions = [PBSourceViewItem groupItemWithTitle:@"Actions"];
|
||||
|
||||
PBSourceViewItem *branches = [PBSourceViewItem groupItemWithTitle:@"Branches"];
|
||||
PBSourceViewItem *remotes = [PBSourceViewItem groupItemWithTitle:@"Remotes"];
|
||||
PBSourceViewItem *tags = [PBSourceViewItem groupItemWithTitle:@"Tags"];
|
||||
PBSourceViewItem *custom = [PBSourceViewItem groupItemWithTitle:@"Custom"];
|
||||
|
||||
for (PBGitRevSpecifier *rev in repository.branches)
|
||||
{
|
||||
if (![rev isSimpleRef])
|
||||
[custom addChild:[PBSourceViewItem itemWithRevSpec:rev]];
|
||||
else if ([[rev simpleRef] hasPrefix:@"refs/heads/"])
|
||||
[branches addChild:[PBSourceViewItem itemWithRevSpec:rev]];
|
||||
else if ([[rev simpleRef] hasPrefix:@"refs/tags/"])
|
||||
[tags addChild:[PBSourceViewItem itemWithRevSpec:rev]];
|
||||
else if ([[rev simpleRef] hasPrefix:@"refs/remotes/"])
|
||||
[remotes addChild:[PBSourceViewItem itemWithRevSpec:rev]];
|
||||
|
||||
}
|
||||
|
||||
[items addObject:actions];
|
||||
|
||||
[items addObject:branches];
|
||||
[items addObject:remotes];
|
||||
[items addObject:tags];
|
||||
[items addObject:custom];
|
||||
|
||||
[sourceView reloadData];
|
||||
[sourceView expandItem:branches expandChildren:YES];
|
||||
[sourceView expandItem:actions];
|
||||
|
||||
NSAssert(actions == [sourceView itemAtRow:0], @"First item is not the Action");
|
||||
[sourceView reloadItem:nil reloadChildren:YES];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark NSOutlineView Datasource methods
|
||||
|
||||
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
|
||||
{
|
||||
if (!item)
|
||||
return [items objectAtIndex:index];
|
||||
|
||||
return [[(PBSourceViewItem *)item children] objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
|
||||
{
|
||||
return [[(PBSourceViewItem *)item children] count];
|
||||
}
|
||||
|
||||
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
|
||||
{
|
||||
if (!item)
|
||||
return [items count];
|
||||
|
||||
return [[(PBSourceViewItem *)item children] count];
|
||||
}
|
||||
|
||||
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
|
||||
{
|
||||
return [(PBSourceViewItem *)item title];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
+16
-4
@@ -8,13 +8,25 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class PBGitRevSpecifier;
|
||||
|
||||
@interface PBSourceViewItem : NSObject {
|
||||
NSString *name;
|
||||
NSMutableArray *children;
|
||||
|
||||
NSString *title;
|
||||
PBGitRevSpecifier *revSpecifier;
|
||||
|
||||
BOOL isGroupItem;
|
||||
}
|
||||
|
||||
- (id)initWithName:(NSString *)name;
|
||||
+ (PBSourceViewItem *)groupItemWithTitle:(NSString *)title;
|
||||
+ (PBSourceViewItem *)itemWithRevSpec:(PBGitRevSpecifier *)revSpecifier;
|
||||
|
||||
- (void)addChild:(PBSourceViewItem *)child;
|
||||
|
||||
@property(retain) NSString *title;
|
||||
@property(readonly) NSMutableArray *children;
|
||||
@property(assign) BOOL isGroupItem;
|
||||
@property(retain) PBGitRevSpecifier *revSpecifier;
|
||||
|
||||
@property(retain) NSString *name;
|
||||
@property(readonly) NSArray *children;
|
||||
@end
|
||||
|
||||
+31
-7
@@ -7,23 +7,47 @@
|
||||
//
|
||||
|
||||
#import "PBSourceViewItem.h"
|
||||
|
||||
#import "PBGitRevSpecifier.h"
|
||||
|
||||
@implementation PBSourceViewItem
|
||||
@synthesize name;
|
||||
@dynamic children;
|
||||
@synthesize title, isGroupItem, children, revSpecifier;
|
||||
|
||||
- (id)initWithName:(NSString *)aName
|
||||
- (id)init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
name = aName;
|
||||
children = [NSMutableArray array];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSArray *)children
|
||||
+ (PBSourceViewItem *)groupItemWithTitle:(NSString *)title
|
||||
{
|
||||
return [NSArray array];
|
||||
PBSourceViewItem *item = [[PBSourceViewItem alloc] init];
|
||||
item.title = title;
|
||||
item.isGroupItem = YES;
|
||||
return item;
|
||||
}
|
||||
|
||||
+ (PBSourceViewItem *)itemWithRevSpec:(PBGitRevSpecifier *)revSpecifier
|
||||
{
|
||||
PBSourceViewItem *item = [[PBSourceViewItem alloc] init];
|
||||
item.revSpecifier = revSpecifier;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
- (void)addChild:(PBSourceViewItem *)child
|
||||
{
|
||||
[self.children addObject:child];
|
||||
}
|
||||
|
||||
- (NSString *)title
|
||||
{
|
||||
if (title)
|
||||
return title;
|
||||
|
||||
return [revSpecifier description];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user