Advertisement
EntropicBlackhole

TreeView List Creator

Oct 20th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;TreeView List Creator vAlpha: Added to Reddit
  2. ;Project Halted (Tuesday May 25th 2021)
  3. ;Project continued (Sunday September 19th 2021)
  4. ;just me on the forums has saved my life, I owe it to you: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=94814
  5. ;TreeView List Creator v1.0: Finished, and reposted on Reddit and added to the Forums
  6. ;TreeView List Creator, v1.1: Added Import and Export buttons, also made the second Edit control editable, so you can freely edit lines either way
  7. #SingleInstance, Force
  8. Gui, New, , TreeViewCreator
  9. Gui, Add, Button, w20 h20 gAdd, +
  10. Gui, Add, Button, yp+25 w20 h20 gAddChild, +C
  11. Gui, Add, Button, x+5 ym w50 h20 gDelete, Delete
  12. Gui, Add, Button, yp+25 w50 h20 gModify, Modify
  13. Gui, Add, Button, x+5 ym w50 h20 gImport, Import
  14. Gui, Add, Button, yp+25 w50 h20 gExport, Export
  15. Gui, Add, Button, x+5 ym w50 h20 gCopy, Copy
  16. Gui, Add, Button, yp+25 w50 h20 gScreenShot, Screen
  17. Gui, Add, Button, x+5 ym w50 h20 gReset, Reset
  18. Gui, Add, Button, yp+25 w50 h20 gRedraw, Redraw
  19. Gui, Add, Edit, x+6 ym+2 w115 h42 vName hwndHandle,
  20. Gui, Add, TreeView, xm W185 h250 -ReadOnly AltSubmit vTV
  21. Gui, Add, Edit, x+6 w171 h250 gEdit vEdit
  22. Gui, Show, , TreeView List Creator
  23. Gui, TreeView, TV
  24. Gosub, Redraw
  25. return
  26.  
  27. Add:
  28. Gui, Submit, NoHide
  29. TV_Add(Name, , "Expand")
  30. GuiControl, , Edit1
  31. GoSub, Redraw
  32. return
  33.  
  34. AddChild:
  35. Selected := TV_GetSelection()
  36. Gui, Submit, NoHide
  37. TV_Add(Name, Selected, Options "Expand")
  38. GuiControl, , Edit1
  39. GoSub, Redraw
  40. return
  41.  
  42. Delete:
  43. Selected := TV_GetSelection()
  44. if (Selected = 0)
  45.     MsgBox, 8208, Sorry, Select an item first., 0
  46. else
  47.     TV_Delete(Selected)
  48. GoSub, Redraw
  49. return
  50.  
  51. Modify:
  52. Selected := TV_GetSelection()
  53. if (Selected = 0)
  54.     MsgBox, 8208, Sorry, Select an item first., 0
  55. else
  56. {
  57.     InputBox, Name, New Name, , , 140, 100
  58.     if not ErrorLevel
  59.         TV_Modify(Selected, , Name)
  60. }
  61. GoSub, Redraw
  62. return
  63.  
  64. Reset:
  65. MsgBox, 8500, Warning!, Are you sure? This will erase all items!
  66. ifMsgBox, Yes
  67.     Reload
  68. ifMsgBox, No
  69.     GoSub, Redraw
  70. return
  71.  
  72. Redraw:
  73. GuiControl, Text, Edit2, % TV_GetTree()
  74. GuiControl, -Redraw, TV
  75. GuiControl, +Redraw, TV
  76. GuiControl, Focus, Edit1
  77. SendMessage, 0xB1, -2, -1,, ahk_id %Handle%
  78. SendMessage, 0xB7,,,, ahk_id %Handle%
  79. return
  80.  
  81. Copy:
  82. clipboard := TV_GetTree()
  83. return
  84.  
  85. Edit:
  86. Gui, Submit, NoHide
  87. TV_Delete()
  88. TV_MakeTree(Edit)
  89. return
  90.  
  91. Import:
  92. FileSelectFile, File, 3, %A_ScriptDir%, Import TreeView, (*.txt; *.ahk)
  93. TV_Delete()
  94. FileRead, Tree, %File%
  95. TV_MakeTree(Tree)
  96. GoSub, Redraw
  97. return
  98.  
  99. Export:
  100. FileSelectFile, File, S, %A_ScriptDir%, Export TreeView, (*.txt; *.ahk)
  101. GuiControlGet, NewTV, , Edit2
  102. FileAppend, %NewTV%, %File%
  103. return
  104.  
  105. ScreenShot:
  106. Send, ^!{PrintScreen}
  107. return
  108.  
  109. SubStrInBtw(String, StartingChar, EndingChar, OccurStartChar := 1, OccurEndChar := 1) {
  110.     StartingPos := InStr(String, StartingChar, , , OccurStartChar)+1
  111.     Length := InStr(String, EndingChar, , , OccurEndChar)-InStr(String, StartingChar, , , OccurStartChar)-1
  112.     return SubStr(String, StartingPos, Length)
  113. }
  114. StrAmt(Haystack, Needle, casesense := false) {
  115.     StringCaseSense % casesense
  116.     StrReplace(Haystack, Needle, , Count)
  117.     return Count
  118. }
  119. TV_MakeTree(List, Del := "`n") {
  120.     ID0 := 0
  121.     Loop, Parse, List, %Del%
  122.     {
  123.         if InStr(A_LoopField, "TV_Add")
  124.         {
  125.             StringSplit, TVAdd, A_LoopField, =
  126.             AssignLevel := StrReplace(TVAdd1, " :")
  127.             TV := SubStrInBtw(TVAdd2, "(", ")")
  128.             Loop, Parse, TV, CSV
  129.             {
  130.                 if (A_Index = 1)
  131.                     Name := A_LoopField
  132.                 if (A_Index = 2)
  133.                     Level := StrReplace(A_LoopField, " ")
  134.                 if (A_Index = 3)
  135.                     Options := A_LoopField
  136.             }
  137.             Options .= " Expand"
  138.             %AssignLevel% := TV_Add(Name, %Level%, Options)
  139.         }
  140.     }
  141. }
  142. TV_GetTree(ItemID := 0, Level := 0) { ; uses the default TreeView of the default Gui ;just me THANK YOU SO MUCH *hug*
  143.    Text := ""
  144.    If (ItemID = 0) {
  145.       ItemID := TV_GetNext()
  146.       Text := "ID0 := 0`r`n"
  147.    }
  148.    While (ItemID){
  149.       TV_GetText(ItemText, ItemID)
  150.       Text .= "ID" . (Level + 1) . " := TV_Add(""" . ItemText . """, ID" . Level . ")`r`n"
  151.       If ChildID := TV_GetChild(ItemID)
  152.          Text .= TV_GetTree(ChildID, Level + 1)
  153.       ItemID := TV_GetNext(ItemID)
  154.    }
  155.    Return (Level = 0 ? RTrim(Text, "`r`n") : Text)
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement