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_FreeIconCache
; __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:
; #AutoIt3Wrapper_UseX64=Y
#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 $idInputPathRight = GUICtrlCreateInput("", $iLeft, $iTop-$iSpace-20, $iCtrlWidth, 20)
; _GUICtrlEdit_SetReadOnly($idInputPathRight, True) ; If the Input should be readonly
Local $idTreeViewLeft = GUICtrlCreateTreeView($iLeft, $iTop, $iCtrlWidth, $iCtrlHeight)
$iTop+=$iCtrlHeight+$iSpace
Local $idListViewLeft = GUICtrlCreateListView("", $iLeft, $iTop, $iCtrlWidth, $iCtrlHeight)
; create right gui
Local $iLeft = $iSpace*2 + $iCtrlWidth
Local $iTop = $iSpace
GUICtrlCreateLabel("Current Folder:", $iLeft, $iTop, 75, 20)
Local $idLabelCurrentFolderRight = GUICtrlCreateLabel("", $iLeft+75, $iTop, $iCtrlWidth-75, 20)
GUICtrlCreateLabel("Selected Folder:", $iLeft, $iTop+20+$iSpace, 80, 20)
Local $idLabelSelectRight = GUICtrlCreateLabel("", $iLeft+80, $iTop+20+$iSpace, $iCtrlWidth-80, 20)
Local $idProgressRight = GUICtrlCreateProgress($iLeft, $iTop+40+$iSpace*2, $iCtrlWidth, 20)
Local $iTop = $iSpace*2+$iTopLine
Local $idTreeViewRight = GUICtrlCreateTreeView($iLeft, $iTop, $iCtrlWidth, $iCtrlHeight)
$iTop+=$iCtrlHeight+$iSpace
Global $idListViewRight = GUICtrlCreateListView("", $iLeft, $iTop, $iCtrlWidth, $iCtrlHeight, $LVS_SHOWSELALWAYS)
; Create TLE system for the left side
Local $hTLESystemLeft = __TreeListExplorer_CreateSystem($hGui);, "", Default, Default, 0)
If @error Then ConsoleWrite("__TreeListExplorer_CreateSystem left failed: "&@error&":"&@extended&@crlf)
; Add Views to TLE system
__TreeListExplorer_AddView($hTLESystemLeft, $idInputPathRight)
If @error Then ConsoleWrite("__TreeListExplorer_AddView $idInputPathRight failed: "&@error&":"&@extended&@crlf)
__TreeListExplorer_AddView($hTLESystemLeft, $idTreeViewLeft)
If @error Then ConsoleWrite("__TreeListExplorer_AddView $idTreeViewLeft failed: "&@error&":"&@extended&@crlf)
__TreeListExplorer_AddView($hTLESystemLeft, $idListViewLeft)
If @error Then ConsoleWrite("__TreeListExplorer_AddView $idListViewLeft failed: "&@error&":"&@extended&@crlf)
; Create TLE system for the right side
Local $hTLESystemRight = __TreeListExplorer_CreateSystem($hGui, "", "_currentFolderRight", "_selectCallback")
If @error Then ConsoleWrite("__TreeListExplorer_CreateSystem right failed: "&@error&":"&@extended&@crlf)
; Add Views to TLE system: ShowFolders=True, ShowFiles=True
__TreeListExplorer_AddView($hTLESystemRight, $idTreeViewRight, True, True, "_clickCallback", "_doubleClickCallback", "_loadingCallback")
If @error Then ConsoleWrite("__TreeListExplorer_AddView $idTreeViewRight failed 2: "&@error&":"&@extended&@crlf)
__TreeListExplorer_AddView($hTLESystemRight, $idListViewRight, True, True, "_clickCallback", "_doubleClickCallback", "_loadingCallback", "_filterCallback", False)
If @error Then ConsoleWrite("__TreeListExplorer_AddView $idListViewRight 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, @DesktopDir)
;__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($idTreeViewRight)
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_Reload($hTLESystemLeft, True) ; reload folder in the right system
EndIf
WEnd
Func _currentFolderRight($hSystem, $sRoot, $sFolder, $sSelected)
GUICtrlSetData($idLabelCurrentFolderRight, $sRoot&$sFolder&"["&$sSelected&"]")
; ConsoleWrite("Folder "&$hSystem&": "&$sRoot&$sFolder&"["&$sSelected&"]"&@CRLF)
EndFunc
Func _selectCallback($hSystem, $sRoot, $sFolder, $sSelected)
GUICtrlSetData($idLabelSelectRight, $sRoot&$sFolder&"["&$sSelected&"]")
__TreeListExplorer__FileGetIconIndex($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)
If $hView=GUICtrlGetHandle($idListViewRight) Then
Local $sSel = _GUICtrlListView_GetSelectedIndices($hView)
If StringInStr($sSel, "|") Then ConsoleWrite("Multiple selected items: "&$sSel&@CRLF)
EndIf
EndFunc
Func _doubleClickCallback($hSystem, $hView, $sRoot, $sFolder, $sSelected, $item)
ConsoleWrite("Double click at "&$hView&": "&$sRoot&$sFolder&"["&$sSelected&"] :"&$item&@CRLF)
EndFunc
Func _filterCallback($hSystem, $hView, $bIsFolder, $sPath, $sName, $sExt)
; ConsoleWrite("Filter: "&$hSystem&" > "&$hView&" -- Folder: "&$bIsFolder&" Path: "&$sPath&" Filename: "&$sName&" Ext: "&$sExt&@crlf)
Return $bIsFolder Or $sExt=".au3"
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($idTreeViewLeft)
ToolTip("Load TreeView: "&$sPath)
;ConsoleWrite("Load: "&$hView&" >> "&$sPath&@crlf)
Case GUICtrlGetHandle($idListViewLeft)
ToolTip("Load ListView: "&$sPath)
;ConsoleWrite("Load: "&$hView&" >> "&$sPath&@crlf)
Case GUICtrlGetHandle($idListViewRight), GUICtrlGetHandle($idTreeViewRight)
GUICtrlSetData($idProgressRight, 50)
EndSwitch
Else
Switch $hView
Case GUICtrlGetHandle($idListViewRight), GUICtrlGetHandle($idTreeViewRight)
GUICtrlSetData($idProgressRight, 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
Version 2.5.1
- Fixed: selection not working for drives
Version 2.6.0
- Added support for icons of all file extensions for TreeViews and ListViews.
Version 2.7.0
- Input controls are now possible as a view. They show the current folder and when pressing {ENTER} inside, the system tries to open the path show in the input.
- Changed the behavior of the treeview when clicking items. They now change the current folder, but are not expanded. This changes the folder in the ListView, when clicking a folder in the TreeView.
Version 2.7.1
- Clicking on the Bitmap of a TreeView item is now registered as a click (not just the text like before)
- Fixed a missing selection update when clicking on a TreeView item
Version 2.8.0
- TreeView selection is now triggering the select event and the $sSelect corresponds to the selected folder/file. NOTE: __TreeViewExplorer_GetSelected will be empty, if the selection is a folder in a treeview
- Selection handling was improved, especially the synchronization between TreeView and ListView
- Add keyboard navigation to the listview
- Fixed a bug, where the icon index was sent as event (GuIGetMsg), when an item was clicked (happens without the udf message handling, so it needed a workaround: suppress the default autoit handler for mouseclicks)
Version 2.9.0
- Fixed bug for TreeViews, where folders were shown as expandable, when having only files but no folders, even if showing files was turned of
- rework how treeviews are filled/updated/expanded (folders that are expanded will stay expanded on reload)
- add the possibility to set a depth limit for the treeview (Example: Drive selection with $sRoot="" and $iMaxDepth=0)
- Fixed bug for Arrow selection in the ListView to not trigger a click event anymore
- When the open folder or the selection changed, the TreeView checks, if it still exists (=> treeview updates, if a folder was deleted)
Version 2.9.1
- Workaround for a Bug in the GuiTreeView UDF (until it is fixed), causing random control deletions instead of TreeView item deletions
Version 2.9.2
- Improved fileicon support. Should support pretty much any file.
Version 2.9.3
- Fixed custom icon size when extracting icons
Version 2.9.4
- Improved display quality for some icons (Thanks WildByDesign for the work on that)
- Fixed an issue, where cached file icons for individual files were shown as a folder
Version 2.9.5
- Improved display quality for some icons (When resource files are defined in the registry, the one with the size greater or equal to the required icon size will be choosen)
Version 2.10.0
- Added the possibility to filter ListViews/TreeViews with a callback function. This callbackfunction is called for every file/folder and only if it returns True, will they be added to the view.
- Added the possibility to set $bNavigate for ListViews when adding them. This enables or disables the possibility to navigate through folders with doubleclicks in a ListView (and add/removes the ".." folder at the top, which enables the user to navigate to the parent folder)
Alles anzeigen
Ich hoffe euch gefällt die UDF und meldet euch gerne bei Verbesserungsvorschlägen/Bugs.
Ihr könnt die TreeListExplorer UDF auch auf Github finden.
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