Flushing a tree

Discuss GUI programming with the RapaGUI plugin here
Post Reply
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Flushing a tree

Post by p-OS »

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 ?
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Flushing a tree

Post by airsoftsoftwair »

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...
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Re: Flushing a tree

Post by p-OS »

My real Scenario is more complex, but I stripped it down to a simple example:

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>
main program

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
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.
Error in line 8 (main.hws): ID "Node_1_Node_1" already used by this application!
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Re: Flushing a tree

Post by p-OS »

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..
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Flushing a tree

Post by airsoftsoftwair »

Thanks for the code. I'll investigate into this soon.
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Re: Flushing a tree

Post by p-OS »

Did you have a look at it ? At least an idea, if it is a bug or an error in my code ?
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Flushing a tree

Post by airsoftsoftwair »

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.
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Flushing a tree

Post by airsoftsoftwair »

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
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Flushing a tree

Post by airsoftsoftwair »

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 
Post Reply