[Fxruby-users] Treelist -- can't add new items with data.
Status: Inactive
Brought to you by:
lyle
From: Hugh S. S. E. E. <hg...@dm...> - 2003-08-12 16:28:43
|
I think I am being terminally stupid here or something. I have been fiddling with this thing for far longer than I care to mention. I have a tree list, which is supposed to hold a cross platform directory structure: thus it maps names with spaces onto numbers expressed as base 36 codes. When I add a name on its own, I can add to the tree, but if I put the data in, the item doesn't get added to the tree. I've missed something, but I've been staring at this so long I can't see what it is. The thing isn't happening when the "add category" button is pressed. The crucial code is here. @treeview = Hash.new() @treeview[""] = FXTreeList.new(contents, 10) treelist = @treeview[""] treelist.listStyle |= TREELIST_SHOWS_LINES | TREELIST_SHOWS_BOXES | TREELIST_ROOT_BOXES treelist.layoutHints |= LAYOUT_FILL_X|LAYOUT_FILL_Y @treeview["#{$equipdir}"] = treelist.addItemLast(nil, "equipment",nil, # openIcon nil, # closedIcon TreeData.new(treelist, "#{$equipdir}" ) # data ) # If an item is doubleclicked, we want to expand or contract # it as appropriate treelist.connect(SEL_DOUBLECLICKED) { |sender, selector, data| # puts "data is #{data.inspect} : #{data.class}" puts "data.data is #{data.data.inspect} : #{data.data.class}" treelist.selectItem(data) if treelist.itemOpened?(data) # true if open treelist.collapseTree(data) treelist.closeItem(data) else # false if closed treelist.openItem(data) treelist.expandTree(data) obtain_tree_entry(data.data) end } ops_panel = FXVerticalFrame.new(contents) @add_cat_btn = FXButton.new(ops_panel, "add Category") @add_cat_btn.connect(SEL_COMMAND) { data = EntryData.new(ops_panel,"New Category") result = NameEntryDialog.new(data).execute unless result.zero? newname = data.value.value #Which item was selected from the tree... if treelist.currentItem path = File.join(treelist.currentItem.full_path, Base36code.new($freelist.next).representation) @treeview[path] = treelist.addItemLast(treelist.currentItem, newname, nil, nil, TreeData.new(treelist, path)) else ; # raise "No item selected." end end } I know that an item is selected, because when I had bugs in that branch of the code the thing crashed. Do I need to fire off some kind of event, or something, to see the change to the tree? When I just did treelist.additem(treelist.current, "name") name got added. Hugh |