Die TreeListExplorer UDF kann genutzt werden um eine TreeView/ListView zum navigieren von Ordnern/Dateien zu nutzen.
Sie erlaubt es, ein TLE System zu erstellen, welches beliebig viele TreeViews und ListViews synchronisiert. Bei dem System kann auch ein Root Ordner gesetzt werden. Jede View kann dabei Ordner und/oder Dateien anzeigen.
Die folgenen Funktionen sind verfügbar:
; #CURRENT# =====================================================================================================================
; __TreeListExplorer_StartUp
; __TreeListExplorer_Shutdown
; __TreeListExplorer_CreateSystem
; __TreeListExplorer_DeleteSystem
; __TreeListExplorer_AddView
; __TreeListExplorer_RemoveView
; __TreeListExplorer_OpenPath
; __TreeListExplorer_Reload
; __TreeListExplorer_GetPath
; __TreeListExplorer_GetRoot
; __TreeListExplorer_GetSelected
; __TreeListExplorer_SetRoot
; ===============================================================================================================================
Alles anzeigen
Wenn ein System erstellt wird, kann eine callback Funktion übergeben werden, die aufgerufen wird, wenn der Root Ordner oder der aktuelle Ordner sich wechselt.
Wenn eine View zu einem System hinzugefügt wird, können Callbacks für den Klick/Doppelklick auf ein Item hinzugefügt werden. Es gibt auch einen Callback zum behandeln des Anfangs/Ende eines Ladevorgangs (Befüllen einer Tree-/ListView).
Beispiel Oberfläche:
Der Code für das Beispiel:
#include "TreeListExplorer.au3"
#include <GuiTreeView.au3>
Global $iWidth = 1600, $iHeight = 1000, $iSpace = 5
; StartUp of the TreeListExplorer UDF (required)
__TreeListExplorer_StartUp()
If @error Then ConsoleWrite("__TreeListExplorer_StartUp failed: "&@error&":"&@extended&@crlf)
; create gui
Local $hGui = GUICreate("TreeListExplorer Example", $iWidth, $iHeight)
Local $iTopLine = 100
Local $iCtrlHeight = ($iHeight - $iTopLine)/2 - $iSpace*3, $iCtrlWidth = $iWidth/2 - $iSpace*3
; create left gui
Local $iTop = $iSpace*2+$iTopLine, $iLeft = $iSpace
Local $hTreeViewLeft = GUICtrlCreateTreeView($iLeft, $iTop, $iCtrlWidth, $iCtrlHeight)
$iTop+=$iCtrlHeight+$iSpace
Local $hListViewLeft = GUICtrlCreateListView("", $iLeft, $iTop, $iCtrlWidth, $iCtrlHeight)
; create right gui
Local $iLeft = $iSpace*2 + $iCtrlWidth
Local $iTop = $iSpace
GUICtrlCreateLabel("Current Folder:", $iLeft, $iTop, 75, 20)
Local $hLabelCurrentFolderRight = GUICtrlCreateLabel("", $iLeft+75, $iTop, $iCtrlWidth-75, 20)
GUICtrlCreateLabel("Selected Folder:", $iLeft, $iTop+20+$iSpace, 80, 20)
Local $hLabelSelectRight = GUICtrlCreateLabel("", $iLeft+80, $iTop+20+$iSpace, $iCtrlWidth-80, 20)
Local $hProgressRight = GUICtrlCreateProgress($iLeft, $iTop+40+$iSpace*2, $iCtrlWidth, 20)
Local $iTop = $iSpace*2+$iTopLine
Local $hTreeViewRight = GUICtrlCreateTreeView($iLeft, $iTop, $iCtrlWidth, $iCtrlHeight)
$iTop+=$iCtrlHeight+$iSpace
Local $hListViewRight = GUICtrlCreateListView("", $iLeft, $iTop, $iCtrlWidth, $iCtrlHeight)
; Create TLE system for the left side
Local $hTLESystemLeft = __TreeListExplorer_CreateSystem($hGui)
If @error Then ConsoleWrite("__TreeListExplorer_CreateSystem failed: "&@error&":"&@extended&@crlf)
; Add Views to TLE system
__TreeListExplorer_AddView($hTLESystemLeft, $hTreeViewLeft)
If @error Then ConsoleWrite("__TreeListExplorer_AddView $hTreeView failed: "&@error&":"&@extended&@crlf)
__TreeListExplorer_AddView($hTLESystemLeft, $hListViewLeft)
If @error Then ConsoleWrite("__TreeListExplorer_AddView $hListView failed: "&@error&":"&@extended&@crlf)
; Create TLE system for the right side
Local $hTLESystemRight = __TreeListExplorer_CreateSystem($hGui, "", "_currentFolder", "_selectCallback")
If @error Then ConsoleWrite("__TreeListExplorer_CreateSystem failed: "&@error&":"&@extended&@crlf)
; Add Views to TLE system: ShowFolders=True, ShowFiles=True
__TreeListExplorer_AddView($hTLESystemRight, $hTreeViewRight, True, True, "_clickCallback", "_doubleClickCallback", "_loadingCallback")
If @error Then ConsoleWrite("__TreeListExplorer_AddView $hTreeView failed: "&@error&":"&@extended&@crlf)
__TreeListExplorer_AddView($hTLESystemRight, $hListViewRight, True, True, "_clickCallback", "_doubleClickCallback", "_loadingCallback")
If @error Then ConsoleWrite("__TreeListExplorer_AddView $hListView failed: "&@error&":"&@extended&@crlf)
; Set the root directory for the right side to the users directory
__TreeListExplorer_SetRoot($hTLESystemRight, "C:\Users")
If @error Then ConsoleWrite("__TreeListExplorer_SetRoot failed: "&@error&":"&@extended&@crlf)
; Open the User profile on the right side
__TreeListExplorer_OpenPath($hTLESystemRight, @UserProfileDir)
If @error Then ConsoleWrite("__TreeListExplorer_OpenPath failed: "&@error&":"&@extended&@crlf)
Local $idButtonTest = GUICtrlCreateButton("Test", $iSpace, $iSpace)
GUISetState(@SW_SHOW)
ConsoleWrite("Left root: "&__TreeListExplorer_GetRoot($hTLESystemLeft)&" Left folder: "&__TreeListExplorer_GetPath($hTLESystemLeft)&@crlf)
ConsoleWrite("Right root: "&__TreeListExplorer_GetRoot($hTLESystemRight)&" Right folder: "&__TreeListExplorer_GetPath($hTLESystemRight)&@crlf)
; Removes the TLE system and clears the Tree/Listview
; __TreeListExplorer_DeleteSystem($hTLESystemLeft)
; __TreeListExplorer_RemoveView($hTreeViewRight)
while True
Local $iMsg = GUIGetMsg()
If $iMsg=-3 Then
__TreeListExplorer_Shutdown()
Exit
EndIf
If $iMsg=$idButtonTest Then
__TreeListExplorer_Reload($hTLESystemRight, True) ; reload all folders in the right system
__TreeListExplorer_OpenPath($hTLESystemRight, @UserProfileDir, "Desktop")
EndIf
WEnd
Func _currentFolder($hSystem, $sRoot, $sFolder, $sSelected)
GUICtrlSetData($hLabelCurrentFolderRight, $sRoot&$sFolder&"["&$sSelected&"]")
; ConsoleWrite("Folder "&$hSystem&": "&$sRoot&$sFolder&"["&$sSelected&"]"&@CRLF)
EndFunc
Func _selectCallback($hSystem, $sRoot, $sFolder, $sSelected)
GUICtrlSetData($hLabelSelectRight, $sRoot&$sFolder&"["&$sSelected&"]")
; ConsoleWrite("Select "&$hSystem&": "&$sRoot&$sFolder&"["&$sSelected&"]"&@CRLF)
EndFunc
Func _clickCallback($hSystem, $hView, $sRoot, $sFolder, $sSelected, $item)
ConsoleWrite("Click at "&$hView&": "&$sRoot&$sFolder&"["&$sSelected&"] :"&$item&@CRLF)
EndFunc
Func _doubleClickCallback($hSystem, $hView, $sRoot, $sFolder, $sSelected, $item)
ConsoleWrite("Double click at "&$hView&": "&$sRoot&$sFolder&"["&$sSelected&"] :"&$item&@CRLF)
EndFunc
Func _loadingCallback($hSystem, $hView, $sRoot, $sFolder, $sSelected, $sPath, $bLoading)
; ConsoleWrite("Loading "&$hSystem&": Status: "&$bLoading&" View: "&$hView&" >> "&$sRoot&$sFolder&"["&$sSelected&"] >> "&$sPath&@CRLF)
If $bLoading Then
Switch $hView
Case GUICtrlGetHandle($hTreeViewLeft)
ToolTip("Load TreeView: "&$sPath)
;ConsoleWrite("Load: "&$hView&" >> "&$sPath&@crlf)
Case GUICtrlGetHandle($hListViewLeft)
ToolTip("Load ListView: "&$sPath)
;ConsoleWrite("Load: "&$hView&" >> "&$sPath&@crlf)
Case GUICtrlGetHandle($hListViewRight), GUICtrlGetHandle($hTreeViewRight)
GUICtrlSetData($hProgressRight, 50)
EndSwitch
Else
Switch $hView
Case GUICtrlGetHandle($hListViewRight), GUICtrlGetHandle($hTreeViewRight)
GUICtrlSetData($hProgressRight, 0)
EndSwitch
ToolTip("")
;ConsoleWrite("Done: "&$hView&" >> "&$sPath&@crlf)
EndIf
EndFunc
Alles anzeigen
Changelog:
Version 2.0.0 (New Version after rework)
Version 2.1.0
- Rename $sCallbackOnSelect to $sCallbackOnClick
- Add an additional callback $sCallbackOnSelectionChange, that is called whenever the Tree-/ListView item selection changes
Version 2.2.0
- Improve loading speed for TreeView folders when expanding
Version 2.3.0
- Fix some bugs where folders did not correctly expand/collapse when clicking them (when the root folder is not "" => shows all drives)
- Fix some documentation
- Add a method for reloading (__TreeListExplorer_Reload) the current folder (ListView/TreeView) or all folders (TreeView)
- Remove the reload parameter from the __TreeListExplorer_OpenPath method (Replaced with __TreeListExplorer_Reload).
- Other small internal changes
Version 2.4.0
- Add the possibility to handle file/folder selections better
- Files/Folders keep selected when reloading
- The currently selected File/Folder can be checked with __TreeListExplorer_GetSelected
- File selection is synchronized between all Tree-/Listviews, Folder selection only between ListViews (TreeView folder selection changes the current folder and expands it)
- fixed minor issues
Version 2.5.0
- Disabled TreeList expand with a single click and changed it to a double click
- Selection is now synchronized for all files/folders between all views (Tree-/ListView)
- The Selection callback is now moved from __TreeListExplorer_AddView to __TreeListExplorer_CreateSystem and only fires ones per change for the system and not for every view (as it was before)
- All callbacks were changed to pass the selected folder and some additional information is now provided (clicked index/item, the loading path,...)
- Small performance improvements
- Some internal restructuring
Alles anzeigen
Ich hoffe euch gefällt die UDF und meldet euch gerne bei Verbesserungsvorschlägen/Bugs.
PS:
Diese UDF ist ein rework (bzw. komplettes neuschreiben) einer alten UDF von mir (FileExplorere List and TiewView), ich kann den Post aber nicht mehr bearbeiten, ist vmtl. zu alt