-
Notifications
You must be signed in to change notification settings - Fork 62
/
GNTreeDataSource.m
68 lines (51 loc) · 2.19 KB
/
GNTreeDataSource.m
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
#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