[wxruby-users] GenericDirCtrl#re_create_tree behaviour
Alex Fenton
alex at pressure.to
Fri Nov 14 06:25:31 EST 2008
Mathias Bruce wrote:
> When GenericDirCtrl#re_create_tree is called in order to refresh the
> tree with any possible changes made to the file system since it was
> loaded, it doesn't re-expand all the tree items that were expanded
> prior to calling re_create_tree. I'm working on a solution to note all
> open tree items and after re_create_tree manually expand the items
> that are still present in the tree.
>
> My question: Is there a nice way that I've overlooked to make it
> automagically re-expand previously expanded nodes after recreating the
> tree?
Sorry, but wxWidgets doesn't provide a magic way to do this. As the name
suggests it's a generic control (ie written from the ground up) so it
doesn't benefit from the way that modern OSes update file dialogs etc as
new files and directories are created.
However it's not hard to get a list of the currently open folder names:
tree = dir.tree_ctrl
open = tree.select { | item | tree.expanded?(item) }
open.map! { | item | tree.item_text(item) }
Note that wxRuby creates the tree items as their parent is expanded, so
this will only traverse whatever folders have been shown, not every
possible folder.
I expect you'd also want to use the full paths as the unique keys:
def tree.item_path(item)
return "" if item == root_item
path = item_text(item)
while item = item_parent(item) and item != root_item
path = "#{item_text(item)}/#{path}"
end
path
end
I need to fix TreeCtrl#get_item_data for the trees from GenericDirCtrl
as it currently crashes. It would seem sensible for the item_data to be
or include the paths. So I'd be grateful if you could follow-up with any
problems you encounter in this.
Doing the re-opening is left to you - you'll need to work hierarchically
down the tree.
thanks
alex
More information about the wxruby-users
mailing list