Repository navigation
Expand file tree
/
Copy pathSidebarController.j
More file actions
98 lines (77 loc) · 2.46 KB
/
Copy pathSidebarController.j
File metadata and controls
98 lines (77 loc) · 2.46 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
@import <Foundation/CPObject.j>
@import <AppKit/CPOutlineView.j>
@import "SidebarColorItem.j"
@implementation SidebarController : CPObject
{
@outlet CPScrollView sidebarScrollView;
CPOutlineView outlineView;
CPDictionary items;
}
- (void)awakeFromCib
{
items = [self defaultSidebarItems];
var column = [[CPTableColumn alloc] initWithIdentifier:@"column"];
[column setWidth:400.0];
outlineView = [[CPOutlineView alloc] initWithFrame:[[sidebarScrollView contentView] bounds]];
[outlineView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[outlineView setHeaderView:nil];
[outlineView setCornerView:nil];
[outlineView addTableColumn:column];
[outlineView setOutlineTableColumn:column];
[outlineView setDataSource:self];
[sidebarScrollView setDocumentView:outlineView];
[self expandAllItems];
}
- (void)expandAllItems
{
var allItems = [items allKeys];
for (var i = 0; i < [allItems count]; i++)
{
[outlineView expandItem:[allItems objectAtIndex:i]];
}
}
- (CPDictionary)defaultSidebarItems
{
var redColor = [[SidebarColorItem alloc] initWithName:@"Red" color:[CPColor redColor]];
var blueColor = [[SidebarColorItem alloc] initWithName:@"Blue" color:[CPColor blueColor]];
var greenColor = [[SidebarColorItem alloc] initWithName:@"Green" color:[CPColor greenColor]];
var colorItem = [[SidebarColorItem alloc] initWithName:@"Colors" color:nil];
return [CPDictionary dictionaryWithObjectsAndKeys:[redColor, greenColor, blueColor], colorItem];
}
@end
@implementation SidebarController (CPOutlineViewDataSource)
- (id)outlineView:(CPOutlineView)outlineView child:(int)child ofItem:(id)item
{
if (item === nil)
{
var keys = [items allKeys];
return [keys objectAtIndex:child];
}
else
{
var values = [items objectForKey:item];
return [values objectAtIndex:child];
}
}
- (BOOL)outlineView:(CPOutlineView)outlineView isItemExpandable:(id)item
{
var values = [items objectForKey:item];
return ([values count] > 0);
}
- (int)outlineView:(CPOutlineView)outlineView numberOfChildrenOfItem:(id)item
{
if (item === nil)
{
return [items count];
}
else
{
var values = [items objectForKey:item];
return [values count];
}
}
- (id)outlineView:(CPOutlineView)outlineView objectValueForTableColumn:(CPTableColumn)tableColumn byItem:(id)item
{
return [item name];
}
@end