Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* AppController.j
* OutlineView
*
* Created by Chandler Kent on December 7, 2009.
* Copyright 2009, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@import <AppKit/CPOutlineView.j>
@implementation AppController : CPObject
{
CPDictionary items;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
CPLogRegister(CPLogConsole);
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, CGRectGetHeight([contentView bounds]))];
[scrollView setBackgroundColor:[CPColor colorWithHexString:@"e0ecfa"]];
[scrollView setAutohidesScrollers:YES];
var outlineView = [[CPOutlineView alloc] initWithFrame:[[scrollView contentView] bounds]];
var textColumn = [[CPTableColumn alloc] initWithIdentifier:@"TextColumn"];
[textColumn setWidth:200.0];
[outlineView setHeaderView:nil];
[outlineView setCornerView:nil];
[outlineView addTableColumn:textColumn];
[outlineView setOutlineTableColumn:textColumn];
[scrollView setDocumentView:outlineView];
[contentView addSubview:scrollView];
items = [CPDictionary dictionaryWithObjects:[[@"glossary 1"], [@"proj 1", @"proj 2", @"proj 3"]] forKeys:[@"Glossaries", @"Projects"]];
[outlineView setDataSource:self];
[theWindow orderFront:self];
}
- (id)outlineView:(CPOutlineView)outlineView child:(int)index ofItem:(id)item
{
CPLog("outlineView:%@ child:%@ ofItem:%@", outlineView, index, item);
if (item === nil)
{
var keys = [items allKeys];
console.log([keys objectAtIndex:index]);
return [keys objectAtIndex:index];
}
else
{
var values = [items objectForKey:item];
console.log([values objectAtIndex:index]);
return [values objectAtIndex:index];
}
}
- (BOOL)outlineView:(CPOutlineView)outlineView isItemExpandable:(id)item
{
CPLog("outlineView:%@ isItemExpandable:%@", outlineView, item);
var values = [items objectForKey:item];
console.log(([values count] > 0));
return ([values count] > 0);
}
- (int)outlineView:(CPOutlineView)outlineView numberOfChildrenOfItem:(id)item
{
CPLog("outlineView:%@ numberOfChildrenOfItem:%@", outlineView, item);
if (item === nil)
{
console.log([items count]);
return [items count];
}
else
{
var values = [items objectForKey:item];
console.log([values count]);
return [values count];
}
}
- (id)outlineView:(CPOutlineView)outlineView objectValueForTableColumn:(CPTableColumn)tableColumn byItem:(id)item
{
CPLog("outlineView:%@ objectValueForTableColumn:%@ byItem:%@", outlineView, tableColumn, item);
console.log(item);
return item;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment