Skip to content

Instantly share code, notes, and snippets.

@joachimhs
Created November 22, 2011 22:52
Show Gist options
  • Save joachimhs/1387311 to your computer and use it in GitHub Desktop.
Save joachimhs/1387311 to your computer and use it in GitHub Desktop.
Objective-J CPOutlineView
/*
* AppController.j
* nibapptest
*
* Created by You on November 20, 2011.
* Copyright 2011, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@import <AppKit/CPOutlineView.j>
@implementation TreeStructure : CPObject
{
CPDictionary rootItems = [[CPDictionary alloc] init];
CPDictionary treeItems = [[CPDictionary alloc] init];
}
- (void)updateItems:(JSObject)jsObject
{
rootItems = [[CPDictionary alloc] init];
treeItems = [[CPDictionary alloc] init];
for (var i = 0; i < jsObject.instrumentationMenu.length; i++)
{
if (jsObject.instrumentationMenu[i].parentPath == nil)
{
[rootItems setObject:jsObject.instrumentationMenu[i] forKey:jsObject.instrumentationMenu[i].guiPath];
}
[treeItems setObject:jsObject.instrumentationMenu[i] forKey:jsObject.instrumentationMenu[i].guiPath];
}
CPLog("Dict set");
}
- (id)outlineView:(CPOutlineView)outlineView child:(int)index ofItem:(id)item
{
CPLog("outlineView:%@ child:%@ ofItem:%@", outlineView, index, item);
if (item === nil)
{
var keys = [rootItems allKeys];
var objectAtIdx = [keys objectAtIndex:index];
console.log("keys: %@", objectAtIdx);
return [keys objectAtIndex:index];
}
else
{
var childItems = [[CPDictionary alloc] init];
var rootItem = [treeItems objectForKey:item];
for (var i = 0; i < rootItem.childrenNodes.length; i++) {
var childItem = [treeItems objectForKey:rootItem.childrenNodes[i]];
[childItems setObject:childItem forKey:childItem.guiPath];
}
console.log("child:ofItem: %@", childItems);
var keys = [childItems allKeys];
return [keys objectAtIndex:index];
}
}
- (BOOL)outlineView:(CPOutlineView)outlineView isItemExpandable:(id)item
{
CPLog("outlineView:%@ isItemExpandable:%@", outlineView, item);
var values = [treeItems objectForKey:item];
console.log(values);
console.log(values.hasChildren);
//return ([values count] > 0);
return values.hasChildren;
}
- (int)outlineView:(CPOutlineView)outlineView numberOfChildrenOfItem:(id)item
{
CPLog("outlineView:%@ numberOfChildrenOfItem:%@", outlineView, item);
if (item === nil)
{
console.log([rootItems count]);
return [rootItems count];
}
else
{
var rootItem = [treeItems objectForKey:item];
var numChildren = rootItem.childrenNodes.length;
console.log("numberOfChildrenOfItem: $@", numChildren);
return numChildren;
}
}
- (id)outlineView:(CPOutlineView)outlineView objectValueForTableColumn:(CPTableColumn)tableColumn byItem:(id)item
{
CPLog("outlineView:%@ objectValueForTableColumn:%@ byItem:%@", outlineView, tableColumn, item);
var it = [treeItems objectForKey:item];
return it.name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment