Jump to content

TreeView color file and belonging tree


Recommended Posts

Hello,

i stuck again,

Im using this function to create a treeview from root dir.
 

;https://autoit.de/index.php?thread/86082-treeview-root-verbergen/&postID=691139#post691139
#include <File.au3>
#include <WindowsConstants.au3>

Global $sPath = @ScriptDir
Global $hGui = GUICreate('TreeView-Example', 400, 600)
Global $idTreeView = GUICtrlCreateTreeView(10, 10, 380, 580, Default, $WS_EX_CLIENTEDGE)
GUISetState()
_CreatePath($sPath, $idTreeView)
Do
Until GUIGetMsg() = -3

Func _CreatePath($sPath, $idParent)
    Local $aFolder, $aFiles, $idItem
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS)
    If Not @error Then
        For $i = 1 To $aFolder[0]
            $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent)
            _CreatePath($sPath & $aFolder[$i], $idItem)
        Next
    EndIf
    $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES)
    If @error Then Return
    For $i = 1 To $aFiles[0]
        $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent)
    Next
EndFunc

Folder Structure:

Folder1

Folder2

Folder3

If a file exists in multiple folders, i like to color it red, if not green. 

I know how to do this for files, but nut for the folders.

Because if there is only 1 file in Folder2 that is also in Folder1 that it should only color this single file red, inlcuding its whole tree.

The Folder1 and Folder2 should be red in this case, too. Other files and trees should stay green.

 

Edit:
Basically i like to color a file and its belonging tree red if the file exists more than 1 time.

Edited by xtcislove
Link to post
Share on other sites

The color change for file and folders is the same, just use GUICtrlSetBkColor. Here the script a little enhanced:

;https://autoit.de/index.php?thread/86082-treeview-root-verbergen/&postID=691139#post691139
#include <File.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <ColorConstants.au3>

;Global $sPath = @ScriptDir
Global $sPath = StringRegExpReplace(@AutoItExe, '(.+\\).+', '$1') ; <- als Beispiel das AutoIt-Verzeichnis
Global $hGui = GUICreate('TreeView-Example', 400, 600)
Global $idTreeView = GUICtrlCreateTreeView(10, 10, 380, 580, Default, $WS_EX_CLIENTEDGE)
GUISetState()
ToolTip('Verzeichnis wird eingelesen. Bitte warten!', Default, Default, 'TreeView-Example', $TIP_INFOICON, $TIP_BALLOON)
_GUICtrlTreeView_BeginUpdate($idTreeView)
_CreatePath($sPath, $idTreeView)
_GUICtrlTreeView_EndUpdate($idTreeView)
ToolTip('')
Do
Until GUIGetMsg() = -3

Func _CreatePath($sPath, $idParent)
    Local $aFolder, $aFiles, $idItem
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS)
    If Not @error Then
        For $i = 1 To $aFolder[0]
            $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent)
            If $aFolder[$i] = 'Scite' Then
                GUICtrlSetBkColor(-1, $COLOR_RED)
            Else
                GUICtrlSetBkColor(-1, $COLOR_Yellow)
            EndIf
            _CreatePath($sPath & $aFolder[$i], $idItem)
        Next
    EndIf
    $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES)
    If @error Then Return
    For $i = 1 To $aFiles[0]
        $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent)
        If StringInStr($aFiles[$i], 'Readme') Then
            GUICtrlSetBkColor(-1, $COLOR_RED)
        Else
            GUICtrlSetBkColor(-1, $COLOR_Yellow)
        EndIf
    Next
EndFunc   ;==>_CreatePath

it's only demostration (playing). If you want to know how to build the logic, than i must ask:

What's a duplicate file?

  • Same name
  • Same size
  • Same hash

Files with same name and size can be different, files with same hash most are real duplicates.

So i suggest try following example(s) in help:

  • _GUICtrlListView_SetItemParam
  • _Crypt_HashFile 

these will help to build a stable logic.

Edited by AutoBert
Link to post
Share on other sites

@AutoBert

I like to check only by name. 
The path structures and filenames are unique. 

If a file is in Folder 1 and Folder 2 its in the same sub directorys.

Folder structure: (Edit: Colored for desired result)

Spoiler

;-> This is the folder i build my TreeView from.

Folder\

Folder 1\

Folder 2\

Folder 3\

;-< This is the folder i build my TreeView from.

Folder 1\
    characters\models\geralt\head\model\eye__geralt_d01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_d02.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_n01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_n02.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_tattoo_d01.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d01_mark.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d01_mark_tattoo.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d02_mark.xbm
    characters\models\geralt\body\model\body_01_mg__geralt_d01.xbm

Folder 2\
    characters\models\geralt\head\model\eye__geralt_d01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_d02.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_n01.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_n02.xbm
    characters\models\geralt\head\model\h_01_mg__geralt_tattoo_d01.xbm

    characters\models\geralt\head\model\h_01_mg__geralt_tattoo_d02.xbm
    characters\models\geralt\head\model\h_02_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_02_mg__geralt_n01.xbm
    characters\models\geralt\head\model\h_03_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_03_mg__geralt_n01.xbm
    characters\models\geralt\head\model\h_04_mg__geralt_d01.xbm
    characters\models\geralt\head\model\h_04_mg__geralt_n01.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d01_mark.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d01_mark_tattoo.xbm
    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d02_mark.xbm

    characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_d02_mark_tattoo.xbm
    
characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_n01_mark.xbm
  
 characters\models\geralt\head\model\ep1_mark\h_01_mg__geralt_n02_mark.xbm
    characters\models\geralt\body\model\body_01_mg__geralt_d01.xbm
    characters\models\geralt\body\model\s_01_mg__body_hires_d01.xbm
Folder 3\
    dlc\dlc6\data\characters\models\main_npc\triss\model\body_01_wa__triss_dlc_d01.xbm
    dlc\dlc6\data\characters\models\main_npc\triss\model\body_01_wa__triss_dlc_s01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\body_05_wa__yennefer_d01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\body_05_wa__yennefer_d02.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\glove_01_wa__yennefer_d01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\scarf_01_wa__yennefer_d01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\stockings_01_wa__yennefer_d01.xbm
    dlc\dlc4\data\characters\models\main_npc\yennefer\model\yennefer_feathers_d01.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\body_01_wa__ciri_dlc_d01.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\body_01_wa__ciri_dlc_d02.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\body_01_wa__ciri_dlc_d03.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\body_01_wa__ciri_dlc_s01.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\ciri_chainmail_dlc_d01.xbm
    dlc\dlc11\data\characters\models\main_npc\ciri\model\ciri_chainmail_dlc_n01.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_a02.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_d02.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_hooded.w2mesh
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_hooded.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_n01.xbm
    characters\models\main_npc\yennefer\model\body_01_wa__yennefer_n02.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_a02.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_d02.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_n01.xbm
    characters\models\main_npc\yennefer\model\dress_01_wa__yennefer_n02.xbm
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\model\fur_01_wa__yennefer_n01.xbm
    characters\models\main_npc\yennefer\model\fur_02_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\fur_02_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\fur_03_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\fur_03_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\l_01_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\l_01_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer.w2mesh
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer.w2mesh.1.buffer
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\model\l_02_wa__yennefer_n01.xbm
    characters\models\main_npc\yennefer\model\yennefer__body_d_notcensor.xbm
    characters\models\main_npc\yennefer\model\yennefer__body_n_notcensor.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\eye__yennefer_d01.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\h_01_wa__yennefer_a01.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\h_01_wa__yennefer_b01.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\h_01_wa__yennefer_d01.xbm
    characters\models\main_npc\yennefer\h_01_wa__yennefer\h_01_wa__yennefer_n01.xbm
    characters\models\main_npc\triss\model\body_01_wa__triss_d01.xbm
    characters\models\main_npc\triss\model\body_02_wa__triss_d01.xbm
    characters\models\main_npc\triss\model\body_02_wa__triss_s01.xbm
    characters\models\main_npc\triss\model\body_03_wa__triss.w2mesh
    characters\models\main_npc\triss\model\body_03_wa__triss.w2mesh.1.buffer
    characters\models\main_npc\triss\model\body_03_wa__triss_a01.xbm
    characters\models\main_npc\triss\model\body_03_wa__triss_d01.xbm
    characters\models\main_npc\triss\model\body_03_wa__triss_n01.xbm
    characters\models\main_npc\triss\model\body_03_wa__triss_s01.xbm
    characters\models\main_npc\triss\model\i_03_wa__triss_d01.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_b01.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_d01.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_d02.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_d03.xbm
    characters\models\main_npc\triss\h_01_wa__triss\h_01_wa__triss_n01.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_d02.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_d03.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_s01.xbm
    characters\models\main_npc\ciri\model\body_01_wa__ciri_s03.xbm
    characters\models\main_npc\ciri\model\body_03__wa_ciri_a01.xbm
    characters\models\main_npc\ciri\model\body_03__wa_ciri_d01.xbm
    characters\models\main_npc\ciri\model\body_03__wa_ciri_n01.xbm
    characters\models\main_npc\ciri\model\body_05_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\collar_01_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\item_07_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\item_10_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\model\l_01_wa__lingerie_ciri.w2mesh
    characters\models\main_npc\ciri\model\l_01_wa__lingerie_ciri.w2mesh.1.buffer
    characters\models\main_npc\ciri\h_01_wa__ciri\eye__ciri_d01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\eye__ciri_d02.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_a01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_a02.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_a03.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_a04.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_b01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_d01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_d02.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_d03.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_d04.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_n01.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_n02.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_n03.xbm
    characters\models\main_npc\ciri\h_01_wa__ciri\h_01_wa__ciri_n04.xbm


So i am able to check if a file is in more than one folder and color it red instead of green, but i dont know how to paint the sub directorys red, it is in.
 

Edited by xtcislove
Link to post
Share on other sites

My function for finding duplicated files: 

Func _FindDuplicates($sPath)
    Local $aFolder, $aFiles, $aFind, $aRet
    $aFolder = _FileListToArrayRec($sPath, "*", 1, 1, 0, 1)
    $aFiles = _FileListToArrayRec($sPath, "*", 1, 1, 0, 0)
    For $i = 1 To $aFiles[0]
        $aFind = _ArrayFindAll($aFiles, $aFiles[$i])
        If UBound($aFind) <> 1 Then $aRet &= $aFolder[$i] & "|"
    Next
    $aRet = StringSplit(StringTrimRight($aRet, 1), "|")
    Return $aRet
EndFunc

This will return all "trees" that need to be colored red.

 array.PNG.e2d9356767d5bd97ae7f212b388ac6c7.PNG

I could loop trough each line of this array and split each line by "\" but that would also color the characters folder red in Folder_3, too.

I was thinking of using GUICtrlCreateDummy() or to handle each TreeView Item in a array and if the file is a duplicate i could loop trough GUICtrlCreateDummy() or the array, but that wouldnt work either, since the CreatePath function, loops torugh each folder and not the whole tree.

Edited by xtcislove
Link to post
Share on other sites

So i found out how to build an array from every folder/file with its Handle:

But i dont know how to use it and the structure is not quiet right.

array.thumb.PNG.92dbc3e6527bb1450cba3cf3f80f5eb9.PNG

 

Func _CreatePath($sPath, $idParent)
    Local $aFolder, $aFiles, $idItem
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS)
    If Not @error Then
        For $i = 1 To $aFolder[0]

            $aAllItem[0][0] += 1
            ReDim $aAllItem[$aAllItem[0][0]+1][3]
            Local $sItemName = _StripPath($aFolder[$i])

            $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent)
            GUICtrlSetColor(-1, 0x098902)
            GUICtrlSetImage(-1, "shell32.dll", 4)

            $aAllItem[$aAllItem[0][0]][0] = $idItem
            $aAllItem[$aAllItem[0][0]][1] = $sItemName

            _CreatePath($sPath & $aFolder[$i], $idItem)
        Next
    EndIf
    $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES)
    If @error Then Return
    For $i = 1 To $aFiles[0]

        $aAllItem[0][0] += 1
        ReDim $aAllItem[$aAllItem[0][0]+1][3]
        Local $sItemName = _StripPath($aFiles[$i])

        $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent)
        GUICtrlSetImage(-1, @ScriptDir & "\tools\icon.ico")
        GUICtrlSetColor(-1, 0x098902)

        $aAllItem[$aAllItem[0][0]][0] = $idItem
        $aAllItem[$aAllItem[0][0]][1] = $sItemName

    Next
EndFunc

 

Link to post
Share on other sites
On 3.9.2018 at 10:32 PM, LarsJ said:

Have you made it work? It's not impossible.

Yeah i made it, but not a good solution i think...

 

Func _FindDuplicates($sPath)
    Local $aFiles, $aFind, $aRet
    $aFiles = _FileListToArrayRec($sPath, "*", 1, 1, 0, 0)
    For $i = 1 To $aFiles[0]
        $aFind = _ArrayFindAll($aFiles, $aFiles[$i])
        If UBound($aFind) <> 1 Then
            If Not StringInStr($aRet, $aFiles[$i]) Then $aRet &= $aFiles[$i] & "|"
        EndIf
    Next
    $aRet = StringSplit(StringTrimRight($aRet, 1), "|")
    Return $aRet
EndFunc

Func _CreateTreeView($sPath, $idParent, $aDupl)
    Local $aFolder, $aFiles, $idItem, $aPath
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    $aFolder = _FileListToArray($sPath, '*', $FLTA_FOLDERS)
    If Not @error Then
        For $i = 1 To $aFolder[0]
            $idItem = GUICtrlCreateTreeViewItem($aFolder[$i], $idParent)
            GUICtrlSetImage($idItem, "shell32.dll", 4)
            GUICtrlSetColor($idItem, 0x098902)
            $aPath = _FileListToArrayRec($sPath & $aFolder[$i], "*", 1, 1, 0, 0)
            If IsArray($aPath) Then
                For $s = 1 To $aPath[0]
                    _ArraySearch($aDupl, $aPath[$s])
                    If Not @error Then GUICtrlSetColor($idItem, 0xf41e0e)
                Next
            EndIf
            _CreateTreeView($sPath & $aFolder[$i], $idItem, $aDupl)
        Next
    EndIf
    $aFiles = _FileListToArray($sPath, '*', $FLTA_FILES)
    If @error Then Return
    For $i = 1 To $aFiles[0]
        $idItem = GUICtrlCreateTreeViewItem($aFiles[$i], $idParent)
        GUICtrlSetImage($idItem, @ScriptDir & "\tools\icon.ico")
        GUICtrlSetColor($idItem, 0x098902)
        _ArraySearch($aDupl, $aFiles[$i])
        If Not @error Then GUICtrlSetColor($idItem, 0xf41e0e)
    Next
EndFunc

 

Link to post
Share on other sites

This is a way it can be done. The treeview is created with your code from a previous post. A dictionary object is used to find file duplicates. In case of duplicates, ItemParam is set to the value 1 all way up through the treeview. In custom draw code, items with ItemParam = 1 are drawn with red background color. Otherwise green.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

Opt( "MustDeclareVars", 1 )

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

Global $hTreeView, $oDict = ObjCreate( "Scripting.Dictionary" )

Example()

Func Example()
  ; Create GUI
  Local $hGui = GUICreate( "Demo1", 620, 420 )

  ; Create TreeView
  $hTreeView = _GUICtrlTreeView_Create( $hGui, 10, 10, 600, 400, $TVS_HASBUTTONS+$TVS_HASLINES+$TVS_LINESATROOT+$TVS_DISABLEDRAGDROP+$TVS_SHOWSELALWAYS, $WS_EX_CLIENTEDGE )

  ; WM_NOTIFY message handler
  GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )

  ; Show GUI
  GUISetState()

  ; Fill TreeView
  _GUICtrlTreeView_BeginUpdate( $hTreeView )
  ListFiles_ToTreeView( @ScriptDir & "\f", 0 )
  _GUICtrlTreeView_EndUpdate( $hTreeView )

  ; Loop
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd

  ; Cleanup
  GUIDelete()
EndFunc

Func ListFiles_ToTreeView( $sSourceFolder, $hItem )
  ; Force a trailing \
  If StringRight( $sSourceFolder, 1 ) <> "\" Then $sSourceFolder &= "\"

  ; Start the search
  Local $hSearch = FileFindFirstFile( $sSourceFolder & "*.*" )
  ; If no files found then return
  If $hSearch = -1 Then Return ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<

  ; Now run through the contents of the folder
  Local $sFile, $hFile
  While 1
    ; Get next match
    $sFile = FileFindNextFile( $hSearch )
    ; If no more files then close search handle and return
    If @error Then ExitLoop ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<<

    ; Check if a folder
    If @extended Then
      ; If so then call the function recursively
      ListFiles_ToTreeView( $sSourceFolder & $sFile, _GUICtrlTreeView_AddChild( $hTreeView, $hItem, $sFile ) )
    Else
      ; If a file than write path and name
      $hFile = _GUICtrlTreeView_AddChild( $hTreeView, $hItem, $sFile )
      If $oDict.Exists( $sFile ) Then
        ; File exists in another folder
        ; Set second, third, ... files red
        While $hFile
          _GUICtrlTreeView_SetItemParam( $hTreeView, $hFile, 1 ) ; Red
          $hFile = _GUICtrlTreeView_GetParentHandle( $hTreeView, $hFile )
        WEnd
        If $oDict( $sFile ) Then
          ; Set first file red
          $hFile = $oDict( $sFile )
          While $hFile
            _GUICtrlTreeView_SetItemParam( $hTreeView, $hFile, 1 ) ; Red
            $hFile = _GUICtrlTreeView_GetParentHandle( $hTreeView, $hFile )
          WEnd
          $oDict( $sFile ) = 0 ; Set first file red only once
        EndIf
      Else
        $oDict( $sFile ) = $hFile ; To be able to set first file red
      EndIf
    EndIf
  WEnd

  ; Close search handle
  FileClose( $hSearch )
EndFunc

Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )
  Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
  Local $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
  Local $iCode = DllStructGetData( $tNMHDR, "Code" )

  Switch $hWndFrom
    Case $hTreeView
      Switch $iCode
        Case $NM_CUSTOMDRAW
          Local $tNMTVCUSTOMDRAW = DllStructCreate( $tagNMTVCUSTOMDRAW, $lParam )
          Local $dwDrawStage = DllStructGetData( $tNMTVCUSTOMDRAW, "DrawStage" )
          Switch $dwDrawStage              ; Specifies the drawing stage
            Case $CDDS_PREPAINT           ; Before the paint cycle begins
              Return $CDRF_NOTIFYITEMDRAW ; Item-related drawing operations
            Case $CDDS_ITEMPREPAINT        ; Before painting an item
              Local $iItemParam = DllStructGetData( $tNMTVCUSTOMDRAW, "ItemParam" )
              If $iItemParam Then
                DllStructSetData( $tNMTVCUSTOMDRAW, "ClrTextBk", 0xCCCCFF )  ; Red, BGR
              Else
                DllStructSetData( $tNMTVCUSTOMDRAW, "ClrTextBk", 0xCCFFCC )  ; Green
              EndIf
              Return $CDRF_NEWFONT        ; Return $CDRF_NEWFONT after changing colors
          EndSwitch
      EndSwitch
  EndSwitch

  Return $GUI_RUNDEFMSG
  #forceref $hWnd, $iMsg, $wParam
EndFunc

The zip-file contains the code and a simpel file/folder structure to test it.

tv.7z

Edited by LarsJ
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jcpetu
      Hi people, I'm trying to dynamically populate a TreeView based on a script from Water that I modified for my needs. but I can't figured it out how to make it work.
      Here what I have in case anyone can help me, thanks in advance:
      #include <array.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> Local $aTV1[14][3] = [ _ ['1', 'Text 1', -1], _ ;-1 idicates it's an index item ['2', 'Text 2',-1], _ ['3', 'Text 3',-1], _ ['1-1', 'Text 1-1',0], _ ['1-2', 'Text 1-2',0], _ ['2-1', 'Text 2-1',0], _ ['2-2', 'Text 2-2',0], _ ['2-1-1', 'Text 2-1-1',0], _ ['2-1-2', 'Text 2-1-2',0], _ ['2-1-2-1', 'Text 2-1-2-1',0], _ ['2-1-2-1-1', 'Text 2-1-2-1-1',0], _ ['3-1', 'Text 3-1',0], _ ['3-1-1', 'Text 3-1-1',0], _ ['3-1-1-1', 'Text 3-1-1-1',0]] ;_ArrayDisplay($aTV1) Local $Gui = GUICreate('TreeView Example', 500, 600) Local $tv = GUICtrlCreateTreeView(10, 30, 450, 550) GUISetState() _pop_treeview($tv, $aTV1) While 1 Switch GUIGetMsg() Case $gui_event_close Exit EndSwitch WEnd Func _pop_treeview($hTV, $array) Local $TimeInitial = TimerInit(), $Hours, $Mins, $Secs, $item _ArraySort($array, 0, 0, 0, 0) ;------------------------- sort Ascending on column 0 ;_ArrayDisplay($array) $idxroot = _GUICtrlTreeView_Add($hTV, 0, "index") For $i = 0 To UBound($array) - 1 ConsoleWrite("$array[" & $i & "][" & 0 & "] = " & $array[$i][0] & @CRLF) If $array[$i][0] = '' Then ExitLoop ;--------------- Exit at first empty element $item = '' If $array[$i][2] = -1 Then ;------------------------ Add root element _GUICtrlTreeView_AddChild($hTV, $idxroot, $array[$i][1]) Else $item = StringLeft($array[$i][0], StringInStr($array[$i][0], "-", 1, -1) - 1) ConsoleWrite("$item = " & $item & @CRLF) $Found = _ArrayBinarySearch($array, $item, 0, 0, 0) ;search on column 0 Switch $Found Case 0 ;----------------------------------- Value wasn't found in array ConsoleWrite("Item NOT found @error= " & @error & @CRLF) Case Else ConsoleWrite("Item found " & @CRLF) _GUICtrlTreeView_AddChild($hTV, $Found, $array[$i][1]) EndSwitch EndIf Next _GUICtrlTreeView_Expand($hTV) EndFunc ;==>_pop_treeview  
    • By MesterPerfect
      good morning
      this is the first post here in the autoit forums
      i hope that you can help me in my problem
      i have a JSON encoded
      it a map of my forums
      where i want to make a treeview that have the same type of map
      e.g
      a system (as category)
      windows (as sub category)
      software (as an child item in the windows category)
      .....
      i don't know how to do that
      so, i know that i can do that using the json functions
      but i need your help about how we can do it as the type that i told you
      by the way i need to put the sub info for each item in an array that give me the ability to manage my items
      e.g
      can post thread
      can reply
      message cound ...
      you just give me a small example and i can continue.
      am sorry if this against the rules of the forum.
      but i realy searched a lot but i couldn't
      i hope some one give me the way.
      thank you very much in advance
       
      here is the link of json forum
      https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/
      and here is my encoded json file
       
      { "tree_map": { "0": [ 1, 5, 6, 7 ], "1": [ 2 ], "2": [ 4 ], "5": [ 3 ], "6": [ 8 ], "8": [ 9, 10 ] }, "nodes": [ { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 1, "node_id": 1, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Main category", "type_data": {} }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 2, "node_name": null, "node_type_id": "Forum", "parent_node_id": 1, "title": "Main forum", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" }, { "node_id": 2, "title": "Main forum", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 4, "node_name": null, "node_type_id": "Forum", "parent_node_id": 2, "title": "my forums1", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 2, "node_id": 5, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Perfect", "type_data": {} }, { "breadcrumbs": [ { "node_id": 5, "title": "Perfect", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 2, "node_id": 3, "node_name": null, "node_type_id": "Forum", "parent_node_id": 5, "title": "ahmed", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 3, "node_id": 6, "node_name": null, "node_type_id": "Forum", "parent_node_id": 0, "title": "autoit", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 8, "node_name": null, "node_type_id": "Forum", "parent_node_id": 6, "title": "examples", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 9, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "GUI", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 31, "node_id": 10, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "windowEX", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 4, "node_id": 7, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "vbs", "type_data": {} } ] }  
    • By argumentum
      ..I'm coding the High Contrast theme editor and using the _ChooseColor() I wandered why it does not keep the the custom colors I've added.
      Found that adding a static declaration would do it. But why stop there. Why not keep going, So I put this together that is non code braking ( backwards compatible ), to replace the one in <Misc.au3>
       
      Hopefully will replace the default one in the next release 
      Better use the new code down this post.
    • By DannyJ
      Hello Forum, 
      I have one special Combo-box [with BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE) ] and if I press one button I want to change the Combo-box's background color, and after I press Button B I want to change it to the basic settings and it not works.
      I wanna do this with one combo-box.
      I have already tried several methods and I tried  GUICtrlComboSetColors that I have found on this forum.
      (But this methods works perfectly with Cobo boxes that don't have BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE). 
      Here is the example code
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= ;$CBS_DROPDOWNLIST ;$GUI_SS_DEFAULT_COMBO $Form1 = GUICreate("Form1", 504, 249, 252, 227) $Combo1 = GUICtrlCreateCombo("", 136, 24, 193, 25,BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; I want to change this special combo's background color if I press button 1 $Button1 = GUICtrlCreateButton("Button1", 112, 96, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 264, 96, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1," " & "|" & "apple" & "|" & "banana" & "|" & "cherry" ," ") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetBkColor($Combo1,0x0078D7) Case $Button2 ;Makes the original bc color GUICtrlSetBkColor($Combo1,0xFFFFFF) EndSwitch WEnd  
      Thanks you in advance your help
    • By user4157124
      ConsoleWrite('>Message here.' & @CRLF) outputs colored text (per + > - ! characters).
      ConsoleWrite('warning' & @TAB & '38' & @TAB & 'more text ...' & @CRLF) enables jump to line 38 on doubleclick.

      Using "jump to line" format, only red and pink text coloring seems possible (simply prefixing color directives to output-text disables jump to line functionality). Is it possible to combine the two (define custom color while keeping "jump to line" functionality)?
×
×
  • Create New...