Flushing a tree

Discuss GUI programming with the RapaGUI plugin here

Flushing a tree

Postby p-OS » Sun Oct 15, 2017 11:26 pm

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 ?
p-OS
 
Posts: 79
Joined: Tue Nov 02, 2010 12:56 am

Re: Flushing a tree

Postby airsoftsoftwair » Mon Oct 16, 2017 9:27 pm

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

Re: Flushing a tree

Postby p-OS » Wed Oct 18, 2017 1:42 am

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: 79
Joined: Tue Nov 02, 2010 12:56 am

Re: Flushing a tree

Postby p-OS » Wed Oct 18, 2017 2:14 am

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..
p-OS
 
Posts: 79
Joined: Tue Nov 02, 2010 12:56 am

Re: Flushing a tree

Postby airsoftsoftwair » Sun Oct 22, 2017 8:39 pm

Thanks for the code. I'll investigate into this soon.
User avatar
airsoftsoftwair
 
Posts: 2233
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: Flushing a tree

Postby p-OS » Tue Nov 14, 2017 1:47 pm

Did you have a look at it ? At least an idea, if it is a bug or an error in my code ?
p-OS
 
Posts: 79
Joined: Tue Nov 02, 2010 12:56 am

Re: Flushing a tree

Postby airsoftsoftwair » Wed Nov 15, 2017 10:12 pm

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: 2233
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: Flushing a tree

Postby airsoftsoftwair » Sat Nov 18, 2017 6:58 pm

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: 2233
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany


Return to RapaGUI

Who is online

Users browsing this forum: No registered users and 2 guests