From: Tim P. <he...@ti...> - 2007-11-27 10:04:33
|
Hey all Having a slight puzzler here - i wrote a sample for RubyCocoa.com a long time ago which demonstrated how to programatically use your own data-source for an outline view (link: http://www.rubycocoa.com/files/outline-views/OutlineMeRuby.zip) . Thats all fine and dandy, but I am in the situation where I now need multiple root nodes and im not quite sure how to get there! Its been a while since I've done any RC programming so just trying to work my way around once again. In that other outline view example, I had a single root node defined by @@rootNode, and it is root because oh its initial nil value. What I am confused about however is how to add another nil value element onto the outline view? I've been looking at the DragNDropOutlineView supplied by apple, which I understand, but they load there data from dictionary, so its not clear how that translates... Can anyone point me in the right direction to create multiple root nodes? Cheers Tim FYI - heres the code for the app controller data-source require 'osx/cocoa' class OLDataSource < OSX::NSObject include OSX # IB outlets ib_outlets :outlineView # configure root node @@rootNode = nil # (id) def init super_init @@rootNode = Node.alloc.init @@rootNode.setItemName('Root') #newnode = Node.alloc.init #newnode.setItemName('Badger') return self end # (IBAction) def addChild(sender) selectedRow = @outlineView.selectedRow # is nothing selected if selectedRow < 0 NSBeep() return end # which node is that? selectedItem = @outlineView.itemAtRow(selectedRow) # create a new child newNode = Node.alloc.init newNode.setItemName('New Child') selectedItem.addChild(newNode) #newNode.release @outlineView.reloadItem_reloadChildren(@@rootNode, true) end # datasource mehods for outlineView # (id) def outlineView_child_ofItem(outlineView, index, item) item ? item.childAtIndex(index) : @@rootNode end # (bool) def outlineView_isItemExpandable(outlineView, item) return item.expandable end # (bool) def outlineView_numberOfChildrenOfItem(outlineView, item) item == nil ? 1 : item.childrenCount() end # (id) def outlineView_objectValueForTableColumn_byItem(outlineView, tableColumn, item) identifier = tableColumn.identifier NSLog(identifier.to_s) if identifier.to_s == "itemSum" return item.sum else return item.itemName end end # (void) delegate method def outlineView_setObjectValue_forTableColumn_byItem(outlineView, object, tableColoumn, item) item.setItemName(object) outlineView.reloadItem_reloadChildren(@@rootNode, true) end # (void) def dealloc @@rootNode = nil super_dealloc end end |