Created
October 4, 2013 12:12
-
-
Save Pulover/6824965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;======================================================================== | |
; | |
; TreeView Browser | |
; | |
; Author: Pulover [Rodolfo U. Batista] | |
; [email protected] | |
; | |
; Requires CreateTreeView.ahk (Thanks Learning one for this function) | |
; http://www.autohotkey.com/board/topic/92863-function-createtreeview/ | |
; | |
;======================================================================== | |
#NoEnv | |
SetWorkingDir %A_ScriptDir% | |
SetBatchLines, -1 | |
; Customize File Extension (optional) | |
CustomExt = tvb | |
ImageListID := IL_Create(10) | |
Gui, +Resize +MinSize260x60 | |
Gui, Add, Button, Default w70 gLoadFolder, Load Folder | |
Gui, Add, Button, w70 yp xp+85 gLoadFile, Load File | |
Gui, Add, Button, w70 yp xp+85 gSaveFile, Save File | |
Gui, Add, Checkbox, Checked yp+5 xp+85 vLoadIcons gLoadIcons, Load Icons | |
Gui, Add, TreeView, xm h400 w300 ImageList%ImageListID% vTreeView | |
Gui, Show,, TreeView Browser | |
return | |
LoadFolder: | |
Gui, Submit, NoHide | |
Gui, +OwnDialogs | |
FileSelectFolder, TreeRoot, *%A_MyDocuments% | |
if !TreeRoot | |
return | |
TV_Delete() | |
Progress, M H80 W600 FS10,, Loading folders & files..., TreeView Browser | |
TVString := CreateString(TreeRoot) | |
Progress, Off | |
CreateTreeView(TVString) | |
return | |
LoadFile: | |
Gui, Submit, NoHide | |
Gui, +OwnDialogs | |
FileSelectFile, StrFile,,, Load File, TreeView (*.%CustomExt%) | |
if !StrFile | |
return | |
TV_Delete() | |
TVString := "" | |
Progress, M H80 W600 FS10,, % "Loading tree" (LoadIcons ? " & icons" : "") "...", TreeView Browser | |
Loop, Read, %StrFile% | |
{ | |
RegExMatch(A_LoopReadLine, "\t+([^\t]+)", Line) | |
TVString .= RegExReplace(A_LoopReadLine, "\tIcon\d+") | |
. (LoadIcons ? "`tIcon" GetIcon(Line1) : "") "`n" | |
Progress, %A_Index%, %Line1% | |
} | |
Progress, Off | |
CreateTreeView(TVString) | |
return | |
SaveFile: | |
Gui, +OwnDialogs | |
FormatTime, Today,, yyyy-MM-dd | |
FileSelectFile, SaveFile, S16, %Today%.%CustomExt%, Save File, TreeView (*.%CustomExt%) | |
If !SaveFile | |
return | |
SplitPath, SaveFile,,, ext | |
If (ext <> CustomExt) | |
SaveFile .= "." CustomExt | |
IfExist %SaveFile% | |
FileDelete %SaveFile% | |
FileAppend, %TVString%, %SaveFile%, UTF-8 | |
return | |
LoadIcons: | |
Gui, Submit, NoHide | |
If LoadIcons | |
TV_SetImageList(ImageListID) | |
Else | |
TV_SetImageList(0) | |
return | |
GuiSize: | |
if A_EventInfo = 1 | |
return | |
GuiControl, Move, TreeView, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40) | |
return | |
GuiClose: | |
ExitApp | |
CreateString(Folder, Call=0) | |
{ | |
global LoadIcons | |
Call++ | |
Loop, %Folder%\*.*, 1 | |
{ | |
Progress, %A_Index%, %A_LoopFileDir% | |
If LoadIcons | |
Icon := "`tIcon" GetIcon(A_LoopFileFullPath) | |
If InStr(FileExist(A_LoopFileFullPath), "D") | |
{ | |
Loop, %Call% | |
String .= "`t" | |
String .= A_LoopFileName . Icon "`n" | |
String .= CreateString(A_LoopFileFullPath, Call) | |
} | |
Else | |
{ | |
Loop, %Call% | |
Files .= "`t" | |
Files .= A_LoopFileName . Icon "`n" | |
} | |
} | |
String .= Files | |
Call-- | |
return String | |
} | |
GetIcon(FileName) | |
{ | |
global ImageListID | |
sfi_size := A_PtrSize + 8 + (A_IsUnicode ? 680 : 340) | |
VarSetCapacity(sfi, sfi_size) | |
SplitPath, FileName,,, FileExt | |
if FileExt in EXE,ICO,ANI,CUR | |
{ | |
ExtID := FileExt | |
IconNumber = 0 | |
} | |
else | |
{ | |
ExtID = 0 | |
Loop 7 | |
{ | |
StringMid, ExtChar, FileExt, A_Index, 1 | |
If not ExtChar | |
break | |
ExtID := ExtID | (Asc(ExtChar) << (8 * (A_Index - 1))) | |
} | |
IconNumber := IconArray%ExtID% | |
} | |
If not IconNumber | |
{ | |
if not DllCall("Shell32\SHGetFileInfo" . (A_IsUnicode ? "W":"A"), "str", "." FileExt | |
, "uint", (FileExt ? 0x80 : 0), "ptr", &sfi, "uint", sfi_size, "uint", (FileExt ? 0x111 : 0x101)) | |
IconNumber = 9999999 | |
else | |
{ | |
hIcon := NumGet(sfi, 0) | |
IconNumber := DllCall("ImageList_ReplaceIcon", "ptr", ImageListID, "int", -1, "ptr", hIcon) + 1 | |
DllCall("DestroyIcon", "ptr", hIcon) | |
IconArray%ExtID% := IconNumber | |
} | |
} | |
return IconNumber | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment