-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectionBox.ahk
92 lines (80 loc) · 1.96 KB
/
SelectionBox.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
79
80
81
82
83
84
85
86
87
88
89
90
91
class SelectionBox
{
__New(selections, prompt, title, returnIndex:=false, options:="", eventSink:="")
{
eObj := SelectionBox.Events.New()
this.title := title
this.returnIndex := returnIndex
this.gObj := GuiCreate(options, title, eObj)
selections := JoinStrArray(selections)
if (selections == 0)
return 0
this.gObj.Add("Text", "w300 r1", prompt)
this.gObj.Add("DDL", "w300", selections).Name := "ddlSelections"
this.gObj.Add("Button", "w145 Default", "Submit").Name := "btnSubmit"
this.gObj.Add("Button", "xp+155 w145", "Cancel").Name := "btnCancel"
this.gObj["btnSubmit"].OnEvent("Click", "OnSubmit")
this.gObj["btnCancel"].OnEvent("Click", "OnCancel")
}
Show()
{
this.gObj.Show("AutoSize")
}
GetResult(timeout:="")
{
if (timeout != "")
{
if !WinWaitClose(this.title,, timeout)
{
return 0
}
if this.returnIndex
result := this.gObj["ddlSelections"].Value
else
result := this.gObj["ddlSelections"].Text
this.gObj.Destroy()
return result
}
WinWaitClose this.title
if this.returnIndex
result := this.gObj["ddlSelections"].Value
else
result := this.gObj["ddlSelections"].Text
this.gObj.Destroy()
return result
}
static Call(selections, prompt, title, options:="", eventSink:="")
{
called := SelectionBox.New(selections, prompt, title, options, eventSink)
called.Show()
return called.GetResult()
}
class Events {
OnSubmit(GuiCtrlObj, Info)
{
GuiCtrlObj.Gui.Submit()
}
OnCancel(GuiCtrlObj, Info)
{
GuiCtrlObj.Gui.Hide()
}
}
}
SelectionBox(selections, prompt, title, options:="")
{
return %SelectionBox%(selections, prompt, title, options)
}
JoinStrArray(arr, delim:="|")
{
if (Type(arr) != "Array")
return 0
joined := ""
for key,value in arr
{
if (key == 1)
joined .= value
else
joined .= delim value
}
return joined
}