I've been rewriting my tree logic and it's much cleaner and
shorter now.
I subclass TopicItem < FXTreeItem and TopicTree < FXTreeList --
then I override addItemLast to create a TopicItem; and then call super
with that item; and then return the item.
But I'm getting an error every time I click a tree item (see
subject line). The object id differs.
Partial code below. (For the whole thing, see tycho.rubyforge.org
and run mkdata.rb first.)
However, it all works fine besides the error message, EXCEPT
that it segfaults when I hit the Quit button.
Ideas???
Thanks,
Hal
class TopicItem < FXTreeItem
attr_accessor :dir, :path, :title, :notes
def initialize(dir,path,title)
super(title)
@dir, @path = dir, path
@notes = []
end
end
####################################################
class TopicTree < FXTreeList
Index = "index.yaml"
def addItemLast(parent,dir,path,title)
item = TopicItem.new(dir,path,title)
super(parent,item)
item
end
def expand
self.expandTree(@treetop)
end
def initialize(contain,root_dir)
tree_opts =
FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|
LAYOUT_RIGHT|TREELIST_SHOWS_LINES|TREELIST_SHOWS_BOXES|
TREELIST_ROOT_BOXES|TREELIST_EXTENDEDSELECT
super(contain, 0, nil, 0, tree_opts)
@treetop = nil
load(nil,root_dir)
end
def load(parent,root)
current = nil
Dir.chdir(root) do
# Load index for this dir
info = File.open(Index) {|f| ::YAML.load(f) } # error if not there
title = info[0]['title']
current = self.addItemLast(parent,root,Dir.pwd,title)
@treetop = current if @treetop.nil?
# Load all files as notes
files = Dir.all_files - [Index]
current.notes = files.map {|x| Note.new(x) }
# Recurse and load directories as topics
Dir.all_dirs.each {|dir| load(current,dir) }
end
end
end
|