-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTreeListView_test.ahk
78 lines (69 loc) · 2.2 KB
/
TreeListView_test.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#Include TreeListView.ahk
TestGui := Gui("-DPIScale")
TestGui.OnEvent("Close", GuiEscape)
TestGui.OnEvent("Escape", GuiEscape)
testobj := {one: [1,2,3], two: {foo: 1, bar: 2, baz: 3}}
tlv := TreeListViewTest(TestGui, TestNode(testobj), "w600 h400", ["One","Two","Three"])
tlv.MinEditColumn := 1
tlv.MaxEditColumn := 3
TestGui.AddButton(, "test button")
TestGui.Show()
; For testing cleanup of nodes (on control destruction
; or when object (value 2) is replaced with string):
; tlv.root.children[3].children.push(RefCountTestNode())
tlv.InsertChild(tlv.root, 3, nz := TestNode([], "z"))
tlv.InsertChild(nz, 1, RefCountTestNode()), nz := ""
class RefCountTestNode {
values := ["One", "Two"]
expandable := false
expanded := false
__delete() {
MsgBox "Delete RefCountTestNode"
}
}
#HotIf WinActive("TreeListView_test.ahk ahk_class AutoHotkeyGUI")
tlv.InsertChild(tlv.root, 2, TestNode("bar", "foo"))
F4::tlv.RemoveChild(tlv.root.children[3], 2)
F5::tlv.Reset()
GuiEscape(*) {
global
TestGui.Destroy()
tlv := ""
ExitApp
}
class TreeListViewTest extends TreeListView {
AfterPopulate() {
this.modifyCol(1, 150)
this.modifyCol(2, "AutoHdr")
this.modifyCol(3, "AutoHdr")
}
CanEdit(r, c:="") {
; This is just to show how tabbing works when some cells are
; not editable.
if (c != "" && InStr(this.getText(r, c), "object"))
return false
return super.CanEdit(r, c)
}
}
; This is used to construct a tree from an object, but since the TLV
; allows a node to have both editable values and children, they aren't
; linked (i.e. replacing the initial "Object" value does not affect the
; child nodes).
TestNode(value, name:="") {
this := {expandable: false, expanded: false}
this.values := [GetValueString(name), GetValueString(value), ""]
if IsObject(value) {
this.expandable := true
this.children := []
for k,v in ObjOwnProps(value)
this.children.Push(TestNode(v, k))
if value.HasMethod('__enum')
for k,v in value
this.children.Push(TestNode(v, k))
}
return this
}
GetValueString(value) {
try return String(value)
return Type(value)
}