Treeview List Creator v1.1 (Completed)

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 v1.1 (Completed)

Post by EntropicBlackhole » 29 Sep 2021, 13:34

TreeView's too tough? Got the tool for you!
TreeView's too time-consuming? Make one in minutes!
TreeView's too complicated? I have you covered!

I present to you:
TreeView List Creator v1.1
So you don't have to worry about taking hours and hours creating TreeViews and checking if you have the correct variables in place
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
;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
;Finished, 155 lines
#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 gImport, Import
Gui, Add, Button, yp+25 w50 h20 gExport, Export
Gui, Add, Button, x+5 ym w50 h20 gCopy, Copy
Gui, Add, Button, yp+25 w50 h20 gScreenShot, Screen
Gui, Add, Button, x+5 ym w50 h20 gReset, Reset
Gui, Add, Button, yp+25 w50 h20 gRedraw, Redraw
Gui, Add, Edit, x+6 ym+2 w115 h42 vName hwndHandle, 
Gui, Add, TreeView, xm W185 h250 -ReadOnly AltSubmit vTV
Gui, Add, Edit, x+6 w171 h250 gEdit vEdit
Gui, Show, , TreeView List Creator
Gui, TreeView, TV
Gosub, Redraw
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

Edit:
Gui, Submit, NoHide
TV_Delete()
TV_MakeTree(Edit)
return

Import:
FileSelectFile, File, 3, %A_ScriptDir%, Import TreeView, (*.txt; *.ahk)
TV_Delete()
FileRead, Tree, %File%
TV_MakeTree(Tree)
GoSub, Redraw
return

Export:
FileSelectFile, File, S, %A_ScriptDir%, Export TreeView, (*.txt; *.ahk)
GuiControlGet, NewTV, , Edit2
FileAppend, %NewTV%, %File%
return

ScreenShot:
Send, ^!{PrintScreen}
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)
}
SubStrInBtw(String, StartingChar, EndingChar, OccurStartChar := 1, OccurEndChar := 1) {
	StartingPos := InStr(String, StartingChar, , , OccurStartChar)+1
	Length := InStr(String, EndingChar, , , OccurEndChar)-InStr(String, StartingChar, , , OccurStartChar)-1
	return SubStr(String, StartingPos, Length)
}
StrAmt(Haystack, Needle, casesense := false) {
	StringCaseSense % casesense
	StrReplace(Haystack, Needle, , Count)
	return Count
}
TV_MakeTree(List, Del := "`n") {
	ID0 := 0
	Loop, Parse, List, %Del%
	{
		if InStr(A_LoopField, "TV_Add")
		{
			StringSplit, TVAdd, A_LoopField, =
			AssignLevel := StrReplace(TVAdd1, " :")
			TV := SubStrInBtw(TVAdd2, "(", ")")
			Loop, Parse, TV, CSV
			{
				if (A_Index = 1)
					Name := A_LoopField
				if (A_Index = 2)
					Level := StrReplace(A_LoopField, " ")
				if (A_Index = 3)
					Options := A_LoopField
			}
			Options .= " Expand"
			%AssignLevel% := TV_Add(Name, %Level%, Options)
		}
	}
}

Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Treeview List Creator v1.1 (Completed)

Post by Johnny R » 30 Sep 2021, 00:53

How to use the GUI? Give an example, please.

EntropicBlackhole
Posts: 40
Joined: 12 Jun 2021, 15:28

Re: Treeview List Creator v1.1 (Completed)

Post by EntropicBlackhole » 30 Sep 2021, 12:30

Johnny R wrote:
30 Sep 2021, 00:53
How to use the GUI? Give an example, please.
Type something in the top edit control, then use the + button to add a branch, if you want to create a child branch, select the item you want to be the parent, and type something in the eidt control and click on the +C, its like this since you can't really deselect an item in a treeview for some reason, the other buttons just do what they say

carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Re: Treeview List Creator v1.1 (Completed)

Post by carno » 21 Nov 2021, 18:05

Tested and works in Win 7.

Post Reply

Return to “Scripts and Functions (v1)”