public
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/Caged/gitnub.git
Click here to lend your support to: gitnub and make a donation at www.pledgie.com !
gitnub / GNTreeDataSource.m
100644 69 lines (51 sloc) 2.247 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
#import "GNTreeDataSource.h"
#import "GNFileSystemItem.h"
 
@implementation GNTreeDataSource
 
// Data Source methods
 
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
    return (item == nil) ? 1 : [item numberOfChildren];
}
 
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
    return (item == nil) ? YES : ([item numberOfChildren] != -1);
}
 
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
    return (item == nil) ? [GNFileSystemItem rootItem] : [(GNFileSystemItem *)item childAtIndex:index];
}
 
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
    return (item == nil) ? @"/" : (id)[item relativePath];
}
 
- (NSImage *)outlineView: (NSOutlineView *)outlineView iconOfItem: (id)item
{
    // Note: -observedObject is needed here due to use of Bindings and the
    // mess surrounding NSTreeController (described at the URL above).
    // If you avoid Bindings and use a normal dataSource, you can simply
    // return [item icon] here, as the actual item will be passed in.
 
    return [item icon];
}
 
// Delegate methods
- (BOOL)outlineView:(NSOutlineView *)sender isGroupItem:(id)item {
    return [item isHeading];
}
 
- (void)outlineView:(NSOutlineView *)sender willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
    if ([item isHeading]) {
    NSMutableAttributedString *newTitle = [[cell attributedStringValue] mutableCopy];
    [newTitle replaceCharactersInRange:NSMakeRange(0,[newTitle length]) withString:[[newTitle string] uppercaseString]];
    [cell setAttributedStringValue:newTitle];
    [newTitle release];
 }
}
 
- (NSCell *)outlineView:(NSOutlineView *)sender dataCellForTableColumn:(id)cell item:(id)item
{
    if([item isHeading])
        return [[[NSTextFieldCell alloc] init] autorelease];
        
   return nil;
}
 
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
{
    BOOL isDir;
    [[NSFileManager defaultManager] fileExistsAtPath:[item fullPath] isDirectory:&isDir];
    
    if([item isHeading] || isDir)
        return NO;
        
    return YES;
}
 
@end