1
Developer's Corner / Re: Could someone please help me with treeview in this ahk script?
« on: December 31, 2011, 04:17 PM »I simplified a few things where you were duplicating a lot of code when using the whole alphabet. You'll see what I mean. Also, I tried to clean up and indent your code a bit. I'm not a fan of including labels/functions within other labels/functions so, if you would like, I can clean it up much further than this. Here you go:Code: Autohotkey [Select]
Letter=%Letter%\ TreeViewWidth := 385 ; Create an ImageList and put some standard system icons into it: Width=413 tBarHeight=20.5 Title=Selecione el Folder : ;---------------------------------------------------------- Title Bar & Caption Text ;----------------------------------------------------------- Minimize / Close Icons Cl_IconPos:=395 { } ; Create a TreeView and a ListView side-by-side to behave like Windows Explorer: GuiNum=2 { IfWinActive, Seleccione el Folder : { } Return Fill: { } { } { If ErrorLevel { } If FirstLetterOrNumber=%FilterLetterOrNumber% { ( %Letter%%TempFlderName%`n ),%A_Temp%\PathList.txt,UTF-8 } } { } Else { Goto, Guishow } { { If ErrorLevel { } AddSubFoldersToTree(TreeRoot) AddSubFoldersToTree(Folder, ParentItemID = 0) { ; This function adds to the TreeView all subfolders in the specified folder. ; It also calls itself recursively to gather nested folders to any depth. { { } } If ParentItemID!=0 } } } { } Else Guishow: { } Return MyTreeLabel: ; This subroutine handles user actions (such as clicking). Return lns=0 Sng:= ItemText=%SelectedItemText% ParentID := A_EventInfo Loop ; Build the full path to the selected folder. { If MainGuiLeft=0 If not ParentID ; No more ancestors. SelectedItemText = %ParentText%\%SelectedItemText% } Return 2ButtonA: 2ButtonB: 2ButtonC: 2ButtonD: 2ButtonE: 2ButtonF: 2ButtonG: 2ButtonH: 2ButtonI: 2ButtonJ: 2ButtonK: 2ButtonL: 2ButtonM: 2ButtonN: 2ButtonO: 2ButtonP: 2ButtonQ: 2ButtonR: 2ButtonS: 2ButtonT: 2ButtonU: 2ButtonV: 2ButtonW: 2ButtonX: 2ButtonY: 2ButtonZ: Goto, Fill Return Return } Return Close: IfWinNotExist, Cargando { If GuiNum=2 { 2GuiClose: If Looping= { } } } Return-skwire (December 31, 2011, 08:21 AM)
skwire that makes nearly what i need, but stills having problem, I added a "#" button too, but it should show all full path in the treeview and sometimes only appear the first folder but not all the subfolders
Also I added the folders structure and the Z: virtual drive to test it.
Check it
This is the new code:
Code: Autohotkey [Select]
- /*
- FileSelectFolder, Letter,::{20d04fe0-3aea-1069-a2d8-08002b30309d}, 0,Just Select Your Drive
- SplitPath,Letter,,,,,Letter ;If user select a full path instead of a Drive
- Letter=%Letter%\
- */
- ;Creating virtual drive
- {
- VLetter=Z
- }
- Letter=Z:\
- TreeViewWidth := 385
- ; Create an ImageList and put some standard system icons into it:
- Width=413
- tBarHeight=20.5
- Title=Selecione el Folder :
- ;---------------------------------------------------------- Title Bar & Caption Text
- ;----------------------------------------------------------- Minimize / Close Icons
- Cl_IconPos:=395
- {
- }
- ; Create a TreeView and a ListView side-by-side to behave like Windows Explorer:
- GuiNum=2
- {
- IfWinActive, Seleccione el Folder :
- {
- }
- Return
- Fill:
- {
- }
- {
- }
- {
- If ErrorLevel
- {
- }
- If FilterLetterOrNumber=#
- {
- If FirstLetterOrNumber is digit ;Si la variable esta ocupada de caracteres numericos
- {
- (
- %Letter%%TempFlderName%`n
- ),%A_Temp%\PathList.txt,UTF-8
- }
- }
- else
- {
- If FirstLetterOrNumber=%FilterLetterOrNumber%
- {
- (
- %Letter%%TempFlderName%`n
- ),%A_Temp%\PathList.txt,UTF-8
- }
- }
- }
- {
- }
- Else
- {
- Goto, Guishow
- }
- {
- {
- If ErrorLevel
- {
- }
- AddSubFoldersToTree(TreeRoot)
- AddSubFoldersToTree(Folder, ParentItemID = 0)
- {
- ; This function adds to the TreeView all subfolders in the specified folder.
- ; It also calls itself recursively to gather nested folders to any depth.
- {
- {
- }
- }
- If ParentItemID!=0
- }
- }
- }
- {
- }
- Else
- Guishow:
- {
- }
- Return
- MyTreeLabel: ; This subroutine handles user actions (such as clicking).
- Return
- lns=0
- Sng:=
- ItemText=%SelectedItemText%
- ParentID := A_EventInfo
- Loop ; Build the full path to the selected folder.
- {
- If MainGuiLeft=0
- If not ParentID ; No more ancestors.
- SelectedItemText = %ParentText%\%SelectedItemText%
- }
- Return
- 2Button#:
- 2ButtonA:
- 2ButtonB:
- 2ButtonC:
- 2ButtonD:
- 2ButtonE:
- 2ButtonF:
- 2ButtonG:
- 2ButtonH:
- 2ButtonI:
- 2ButtonJ:
- 2ButtonK:
- 2ButtonL:
- 2ButtonM:
- 2ButtonN:
- 2ButtonO:
- 2ButtonP:
- 2ButtonQ:
- 2ButtonR:
- 2ButtonS:
- 2ButtonT:
- 2ButtonU:
- 2ButtonV:
- 2ButtonW:
- 2ButtonX:
- 2ButtonY:
- 2ButtonZ:
- Goto, Fill
- Return
- Return
- }
- Return
- Close:
- IfWinNotExist, Cargando
- {
- If GuiNum=2
- {
- 2GuiClose:
- If Looping=
- {
- ;Erasing virual drive
- {
- }
- }
- }
- }
- Return