Treeview List Creator

Post your working scripts, libraries and tools for AHK v1.1 and older
EntropicBlackhole
Posts: 40
Joined: 12 Jun 2021, 15:28

Treeview List Creator

Post by EntropicBlackhole » 23 Sep 2021, 13:58

The + button is to add a parent
The +C button is to add a child, by first selecting any item
The Delete button is to delete a selected item
The Modify button is to modify a selected item
The Copy button is to copy the created TreeView into a code format
The Reset button is to reload the script, will ask for confirmation
The Redraw button is to redraw the Tree if it has not loaded correctly
The other Buttons are spaces for future buttons I'll add from your suggestions, so just tell me what buttons could be added
Enjoy!

Code: Select all

;TreeView List Creator vAlpha: Added to Reddit
;Project Halted (Tuesday May 25th 2021)
;Project continued (Sunday September 19th 2021)
;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
;TreeView List Creator v1.0: Finished, and reposted on Reddit and added to the Forums
#SingleInstance, Force
Gui, New, , TreeViewCreator
Gui, Add, Button, w20 h20 gAdd, +
Gui, Add, Button, yp+25 w20 h20 gAddChild, +C
Gui, Add, Button, x+5 ym w50 h20 gDelete, Delete
Gui, Add, Button, yp+25 w50 h20 gModify, Modify
Gui, Add, Button, x+5 ym w50 h20 , Button
Gui, Add, Button, yp+25 w50 h20 , Button
Gui, Add, Button, x+5 ym w50 h20 gCopy, Copy
Gui, Add, Button, yp+25 w50 h20 , Button
Gui, Add, Button, x+5 ym w50 h20 gReset, Reset
Gui, Add, Button, yp+25 w50 h20 gRedraw, Redraw
Gui, Add, Button, x+5 ym+1 w50 h20 , Button
Gui, Add, Button, yp+24 w50 h20 , Button
Gui, Add, Edit, x+6 ym+2 w60 h42 vName hwndHandle, 
Gui, Add, TreeView, xm W181 h250 -ReadOnly AltSubmit vTV
Gui, Add, Edit, x+6 w175 h250 ReadOnly
Gui, Show, , TreeView List Creator
Gui, TreeView, TV
return

Add:
Gui, Submit, NoHide
TV_Add(Name, , "Expand")
GuiControl, , Edit1
GoSub, Redraw
return

AddChild:
Selected := TV_GetSelection()
Gui, Submit, NoHide
TV_Add(Name, Selected, Options "Expand")
GuiControl, , Edit1
GoSub, Redraw
return

Delete:
Selected := TV_GetSelection()
if (Selected = 0)
	MsgBox, 8208, Sorry, Select an item first., 0
else
	TV_Delete(Selected)
GoSub, Redraw
return

Modify:
Selected := TV_GetSelection()
if (Selected = 0)
	MsgBox, 8208, Sorry, Select an item first., 0
else
{
	InputBox, Name, New Name, , , 140, 100
	if not ErrorLevel
		TV_Modify(Selected, , Name)
}
GoSub, Redraw
return

Reset:
MsgBox, 8500, Warning!, Are you sure? This will erase all items!
ifMsgBox, Yes
	Reload
ifMsgBox, No
	GoSub, Redraw
return

Redraw:
GuiControl, Text, Edit2, % TV_GetTree()
GuiControl, -Redraw, TV
GuiControl, +Redraw, TV
GuiControl, Focus, Edit1
SendMessage, 0xB1, -2, -1,, ahk_id %Handle%
SendMessage, 0xB7,,,, ahk_id %Handle%
return

Copy:
clipboard := TV_GetTree()
return

TV_GetTree(ItemID := 0, Level := 0) { ; uses the default TreeView of the default Gui ;just me THANK YOU SO MUCH *hug*
   Text := ""
   If (ItemID = 0) {
      ItemID := TV_GetNext()
      Text := "ID0 := 0`r`n"
   }
   While (ItemID){
      TV_GetText(ItemText, ItemID)
      Text .= "ID" . (Level + 1) . " := TV_Add(""" . ItemText . """, ID" . Level . ")`r`n"
      If ChildID := TV_GetChild(ItemID)
         Text .= TV_GetTree(ChildID, Level + 1)
      ItemID := TV_GetNext(ItemID)
   }
   Return (Level = 0 ? RTrim(Text, "`r`n") : Text)
}
;100 lines :D

Return to “Scripts and Functions (v1)”