Get a TreeViewNode text?

BlitzMax Forums/MaxGUI Module/Get a TreeViewNode text?

Grisu(Posted 2011) [#1]
Hello!

Is there a way to get the text of a selected item inside a treeviewnode? (cross platform)

I'd like to get the filename from this tree for example

Import MaxGui.Drivers

Strict 

Local window:TGadget=CreateWindow("My Window",50,50,240,240,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
Local treeview:TGadget=CreateTreeView(5,5,ClientWidth(window)-10,ClientHeight(window)-10,window)

SetGadgetLayout treeview, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED

Local root:TGadget=TreeViewRoot(treeview)


Local projects:TGadget=AddTreeViewNode("My Files -> Select a ZIP",root)
AddTreeViewNode("file1.zip",projects)
AddTreeViewNode("file3.zip",projects)

While WaitEvent()
	Print CurrentEvent.ToString()
	Select EventID()
	      Case EVENT_GADGETACTION 
              Print "What was the filename again?" 	
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend


Thanks!
Grisu


jsp(Posted 2011) [#2]
Just GadgetText() should do the trick

Case EVENT_GADGETACTION
Print "What was the filename again?"
If EventSource()=treeview Then
Print "->"+GadgetText(TGadget(SelectedTreeViewNode(treeview)))
End If


Grisu(Posted 2011) [#3]
Perfect! - Thought it was more complicated than this... ;)

Danke!

Last edited 2011


ima747(Posted 2011) [#4]
You can also store the filename in the gadgetextra field and then have the gadget text available for cleaner display (like stripping off the file extension, or the gadget extra could include the full path, etc.)


Grisu(Posted 2011) [#5]
Thanks for the informations.

I'm using this in my automatic file updater, so leaving the file extension intact is ok. As the user should be able to track the changes that were made.



What I really would like to have is a tooltip that stores the filesize though.


jsp(Posted 2011) [#6]
What I really would like to have is a tooltip that stores the filesize though.

You could update a label showing the filesize of the selected treeview node upon GADGETSELECT event. The filesize could be read than as requested, or stored upfront in the gadgetextra field as ima suggested for the filepath and retrieved from there without an extra disk access.


ima747(Posted 2011) [#7]
you could also use node selection event to trigger the gadget tooltip for the treeview to be set to the gadgetextra, etc... I forget how tooltips work on treeviews, but there may be some cross platform issues with changing it like that, if I recall correctly I used something like that one and it was fine on mac but a little sketchy on windows...


jsp(Posted 2011) [#8]
AFAIK no crossplatform tooltips for treeviews.


Grisu(Posted 2011) [#9]
Not sure if showing the fliesize on selection is a good thing?
I want to keep the update process as quick as possible.
It already takes a while if you need to download all station files.

Uploaded the latest internal build here to illustrate what I mean:
http://188.165.211.46/~knot/prp/prp_slim.zip (650 KB)

[Click "About" -> "Check Updates")

I really appreciate comments as I want to keep the app user friendly, slick and pretty... :)

Last edited 2011