Flushing a tree
Flushing a tree
Hello,
Imagine you have filled a treeview with your data. Then you'd like to update the complete tree.
I wonder how I can flush the contents (all nodes and leafs) most easily, before i fill it again ?
Tried several ways to remove all childs of Root, but each resulted in another Problem. Before explaining in more Detail, I ask:
What happens , if I remove an item from a treeview ? Will it only be detached or also disposed (FreeObject...) ?
What happens to all childs if I remove a node ?
Imagine you have filled a treeview with your data. Then you'd like to update the complete tree.
I wonder how I can flush the contents (all nodes and leafs) most easily, before i fill it again ?
Tried several ways to remove all childs of Root, but each resulted in another Problem. Before explaining in more Detail, I ask:
What happens , if I remove an item from a treeview ? Will it only be detached or also disposed (FreeObject...) ?
What happens to all childs if I remove a node ?
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Flushing a tree
If you remove a node or a leaf, it is automatically disposed. If it is a node, then all children will be disposed as well. If that is not the case, then we have a bug here....
I think you have stumbled across a missing feature... I think we need something like a Treeview.Clear() method or a special ALL parameter for Treeview.Remove() ... I‘ll think about it...
I think you have stumbled across a missing feature... I think we need something like a Treeview.Clear() method or a special ALL parameter for Treeview.Remove() ... I‘ll think about it...
Re: Flushing a tree
My real Scenario is more complex, but I stripped it down to a simple example:
gui.xml
main program
filltree creates two nodes, the first one has a child node, too.
emptytree deletes all nodes, that are direct child of Root node.
At least none is visible any more.
Referring to your last post, removing Node_1 will also dispose ist child Node_1_Node_1
But when I call filltree again (with the same IDs as used before), Node_1 is created , ist child Node_1_Node_1 however can't.
gui.xml
Code: Select all
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
<window height="400">
<vgroup>
<treeview id="tv">
<column/>
</treeview>
</vgroup>
</window>
</application>
Code: Select all
@DISPLAY {hidden=True}
@REQUIRE "RapaGUI"
filltree=Function(tree)
Wait(150)
moai.DoMethod(tree,"InsertNode", "Node_1" , "Root" ,"Tail", "Node_1")
Wait(150)
moai.DoMethod(tree,"InsertNode", "Node_1_Node_1" , "Node_1" ,"Tail", "Node_1_Node_1")
Wait(150)
moai.DoMethod(tree,"InsertNode", "Node_2" , "Root" ,"Tail", "Node_2")
EndFunction
emptytree=Function(tree)
Local found
Local tab
found,tab = moai.DoMethod(tree, "GetEntry", "Root" , "Head")
While found
Wait(150)
moai.DoMethod(tree,"remove",tab.id)
found,tab = moai.DoMethod("tv", "GetEntry", "Root" , "Head")
Wend
EndFunction
Function rpg(msg)
;NOP
EndFunction
;main()
moai.CreateApp(FileToString("gui.xml"))
InstallEventHandler({RapaGUI = rpg})
filltree("tv")
Wait(150)
moai.DoMethod("tv", "open", "Root", True)
Wait(150)
emptytree("tv")
Wait(150)
filltree("tv")
Repeat
WaitEvent
Forever
emptytree deletes all nodes, that are direct child of Root node.
At least none is visible any more.
Referring to your last post, removing Node_1 will also dispose ist child Node_1_Node_1
But when I call filltree again (with the same IDs as used before), Node_1 is created , ist child Node_1_Node_1 however can't.
Error in line 8 (main.hws): ID "Node_1_Node_1" already used by this application!
Re: Flushing a tree
BTW, after a call to emptytree() Trials to Access Node_1_Node_1 will result in an error, that this Obejct is not known -> hint that it is actually disposed..
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Flushing a tree
Thanks for the code. I'll investigate into this soon.
Re: Flushing a tree
Did you have a look at it ? At least an idea, if it is a bug or an error in my code ?
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Flushing a tree
It's definitely a RapaGUI bug. Treeview.Remove() currently doesn't kill all entries it should kill internally. That's why you get the error. I need to fix this in RapaGUI.
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Flushing a tree
Code: Select all
- New: Added special "Root" parameter for Treeview.Remove(); if "Root" is passed in item$, all items
in the treeview will be removed so that the treeview will be empty
- Fix: Treeview.Remove() didn't correctly adapt lots of internal state values which could lead to
the problem that certain MOAI IDs weren't released correctly
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Flushing a tree
Code: Select all
- New: Added Treeview.Clear() method; this removes all items from a treeview widget; this does the
same as calling Treeview.Remove() with the special "Root" keyword