Skip to content

Instantly share code, notes, and snippets.

@chandlerkent
Created December 8, 2009 00:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chandlerkent/251323 to your computer and use it in GitHub Desktop.
Save chandlerkent/251323 to your computer and use it in GitHub Desktop.
/*
* 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