Directory list and treeview

BlitzMax Forums/MaxGUI Module/Directory list and treeview

Filax(Posted 2007) [#1]
Hi :)

I'm trying to do an explorer like treeview but i get
problem with recursivity :( Anybody can help me ?




Filax(Posted 2007) [#2]
I found this way :
http://www.2dgamecreators.com/maxgui/T18%20-%20TreeView.html


Scaremonger(Posted 2007) [#3]
Try this:
Strict 

Global window:TGadget=CreateWindow("My Window",50,50,240,240)
Global treeview:TGadget=CreateTreeView(0,0,200,200,window)
SetGadgetLayout treeview,2,2,2,2

Global root:TGadget=TreeViewRoot(treeview)

Global Drive:String="C:\"
Global Direc:String="library"

Global directory:TGadget
directory=AddTreeViewNode(Drive,root)
directory=AddTreeViewNode(Direc,directory)

Global Previous:TGadget

ListFiles(directory, Drive+Direc)

While WaitEvent()
	Print CurrentEvent.ToString()
	Select EventID()
	Case EVENT_WINDOWCLOSE
		End
	End Select
Wend

Function ListFiles( folder:TGadget, rootdir:String)
	Local dir:Int = ReadDir( rootdir)
	Local subfolder:TGadget
	If Not dir Then Return
	
	'If Not rootdir.EndsWith("/") Then rootdir:+ "/"
	Repeat
		Local fn:String = NextFile(dir)
		If Not fn Then Exit ' <-- this is important, we dont want an endless loop
		
		If FileType( rootdir+"/"+fn) = 2 And fn<>"." And fn<>".." Then
			subFolder = AddTreeViewNode( fn, folder )			
			ListFiles( subFolder, rootdir+"/"+fn) ' <-- recurse over this folder
		EndIf
	Forever
	CloseDir dir
EndFunction



Filax(Posted 2007) [#4]
Many thanks :)


Lane(Posted 2009) [#5]
I know I'm new to blitzMax but...
Scaremongers code doesn't seem to do anything.


Firstly I had to add
Import MaxGui.Drivers

the end result is only a tree with

c:\
|--Library


Lane(Posted 2009) [#6]
I neglected to mention I'm testing with the demo version 1.3.


SebHoll(Posted 2009) [#7]
Scaremonger's example isn't really a fully featured explorer treeview. I've hacked at it a bit to make it slightly more flexible, but we could still probably do with, perhaps, a TProxyGadget implementation.




Lane(Posted 2009) [#8]
Thank you SebHoll for the very nice example code