How do I adding items to Listtree gadet

Discuss GUI programming with the MUI Royale plugin here
Post Reply
User avatar
Redlion
Posts: 96
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

How do I adding items to Listtree gadet

Post by Redlion »

Hi all,

I have been playing with Royale a bit, and wanted to implement a ListTree gadget. I have read the documentation but am stumped as how to add items(leaves) to my list.

Here is the simple test program I have sofar. ( I have used the Drive directory as an example so that I dont have to supply lots of data )

Code: Select all

@VERSION 6,0
@REQUIRE "MUIRoyale"
@APPTITLE ""
@APPVERSION "$VER: 1.0 (01.01.15)"
@APPCOPYRIGHT "©2015, George Leo den Hollander"
@APPAUTHOR "Leo den Hollander"
@APPDESCRIPTION "Program"

@DISPLAY {Hidden = True}

devices = {}
harddisks = {}
optical = {}
usb = {}
ram = {}
Devs = {}

; ###########################################################################################################
MUI.CreateGui([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application base="DidL">
<window title=" Program Name Here" id="window" width="800" height="400" notify="closerequest" >
    <vgroup background="pre_ShadowFill">
        <vgroup>
            <listtree id="Files" >
            </listtree>
        </vgroup>
    </vgroup>
</window>
</application>
]])
; ####################################################################################

Function p_ListDrives() ; * Find all devices ********************************************************************************* 
    Execute("info devices sort volume >TEXTCLIP:")
    type, data = GetClipboard()
    h = 0
    o = 0
    u = 0
    r = 0
    devices, noofdevices = SplitStr(data,"\n")
    For Local x = 1 to noofdevices-1
       line = devices[x-1]
       If FindStr(line,"DH",False) = 0
            harddisks[h] = MidStr(line,0, FindStr(line,":"))
            h = h +1
       ElseIf FindStr(line,"CD",False) = 0
            optical[o] = MidStr(line,0, FindStr(line,":"))
            o = o +1
        ElseIf FindStr(Line,"USB",False) = 0
            usb[u] = MidStr(line,0, FindStr(line,":"))
            u = u +1
        ElseIf FindStr(line,"RAM",False) = 0
            ram[r] = MidStr(line,0, FindStr(line,":"))
            r = r +1
        EndIf
    Next
    L=1
    For Local d = 0 to h-1
        Devs[l] = Harddisks[d]
        L = L +1
    Next
; comment out for demo
;    For Local d = 0 to r-1
;        Devs[l] = ram[d]
;        L = L +1
;    Next
;    For Local d = 0 to u-1
;        Devs[l] = Usb[d]
;        L = L +1
;    Next
;    For Local d = 0 to o-1
;        Devs[l] = Optical[d]
;        L = L +1
;    Next
EndFunction

Function p_ListDirectories(SDir$)
    dd = OpenDirectory(NIL,SDir$..":")
    E = NextDirectoryEntry(dd)
    While E <> Nil
        If E.type = #DOSTYPE_FILE
        EndIf
        If E.type = #DOSTYPE_DIRECTORY 
           mui.DoMethod("Files","Insert",E.name,E.name,"Root","Tail","NextNode")
        EndIf
        E = NextDirectoryEntry(dd)
    Wend
    CloseDirectory(dd)    
EndFunction

Function p_MUIEvent(id) ; * Joint event handler for MUI buttons and menus ***********************************
    Switch id
             
        Case "Quit":
            End
    EndSwitch
EndFunction

Function p_EventFunc(msg)
    Switch msg.action
        Case "MUIRoyale":
            Switch msg.attribute
                Case "CloseRequest":
                     End
        
                Case "Pressed":
                    p_MUIEvent(msg.id)
        
            Endswitch

        Case "HideWindow":
            MUI.Set("app", "iconified", True)

        Case "ShowWindow":
            MUI.Set("app", "iconified", False)

    EndSwitch
EndFunction

; listen to these events!
InstallEventHandler({MUIRoyale = p_EventFunc, HideWindow = p_EventFunc, ShowWindow = p_EventFunc})

p_ListDrives()
For  Local d = 1 to L-1
  mui.DoMethod("Files","Insert",Devs[d],Devs[d],"Root","Tail","active")
  mui.set("Files","Active",Devs[d])
  p_ListDirectories(Devs[d])
Next

; main loop!
Repeat
    WaitEvent
Forever 
As you can see, I can put the data in the list but not 'in' the node. I could not find an example anywhere, so I can not figure it out.

Any help would be great.

Cheers
Leo
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How do I adding items to Listtree gadet

Post by airsoftsoftwair »

I'm afraid your example is too long for me to study here. Let's just do a simple example using the Listtree.hws that comes with MUI Royale. Suppose you want to insert a new entry into the node that is named "Machine". To do this, we first have to assign an id to this node so that we can reference it in Listtree.Insert(). Thus, you'd have to modify Listtree.xml as follows:

Code: Select all

<node name="Machine" id="machine">
Now we can refer to the node titled "Machine" by using the id string "machine". Then we can just call:

Code: Select all

mui.DoMethod("listtree", "insert", "Test entry", "myentryid", "machine", "tail", "") 
This will insert an entry named "Test entry" as the last entry into the node defined by the id "machine". If you don't want to insert it as the last entry, you need to pass the identifier of a leaf instead of "tail". Check here for all possible options: Listtree.Insert()

The last parameter of Listtree.Insert() can be used insert nodes instead of leaves. To insert a new node into the "Machine" tree, you'd do the following:

Code: Select all

mui.DoMethod("listtree", "insert", "New node", "myentryid2", "machine", "tail", "list")
And to insert a new leaf into the newly added node, you'd do this:

Code: Select all

mui.DoMethod("listtree", "insert", "Test entry 2", "myentryid3", "myentryid2", "tail", "") 
I hope you get the idea... it's really not that difficult once you get hang of it.
Post Reply