-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathclass_Menu.ahk
154 lines (128 loc) · 3.9 KB
/
class_Menu.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Library: menu
Author: neovis
Link: https://github.com/neovis22/menu
*/
menu(menuItems, callback="") {
return new __Menu__(menuItems, callback)
}
class __Menu__ {
static _selectedItem
_groups := []
__new(menuItems, callback="") {
static id := 0
this.name := "menu_" ++ id
this.callback := callback
for i, item in menuItems {
if (item.menu) {
submenu := menu(item.menu, callback)
sub := ":" submenu.name
this[a_index] := submenu ; 레퍼런스 카운트 유지 (서브메뉴의 소멸방지)
} else {
sub := Func("_menuEventHandler").bind(&this, item)
}
if (item.hasKey("group")) {
this._groups[item.group, a_index] := item
opts := " Radio"
} else {
opts := ""
}
Menu % this.name, Add, -, % sub, % item.options opts
if (item.checked)
this.check(a_index "&")
if (item.disabled)
this.disable(a_index "&")
if (item.color != "")
this.setColor(a_index "&", item.color)
if (item.icon.file)
this.setIcon(a_index "&", item.icon.file, item.icon.number, item.icon.width)
if (item.default)
this.default := a_index "&"
this.rename(a_index "&", item.name)
}
}
__delete() {
Menu % this.name, DeleteAll
}
delete(itemName) {
Menu % this.name, Delete, % itemName
}
rename(itemName, newName="") {
Menu % this.name, Rename, % itemName, % newName
}
check(itemName) {
Menu % this.name, Check, % itemName
}
uncheck(itemName) {
Menu % this.name, Uncheck, % itemName
}
toggleCheck(itemName) {
Menu % this.name, ToggleCheck, % itemName
}
enable(itemName) {
Menu % this.name, Enable, % itemName
}
disable(itemName) {
Menu % this.name, Disable, % itemName
}
toggleEnable(itemName) {
Menu % this.name, ToggleEnable, % itemName
}
setColor(itemName, color="", applyToSubmenus="") {
Menu % this.name, Color, % itemName, % color, % applyToSubmenus ? "" : "Single"
}
setIcon(itemName, fileName, iconNumber="", iconWidth="") {
Menu % this.name, Icon, % itemName, % fileName, % iconNumber, % iconWidth
}
noIcon(itemName) {
Menu % this.name, NoIcon, % itemName
}
show(x="", y="") {
__Menu__._selectedItem := ""
Menu % this.name, Show, % x, % y
return __Menu__._selectedItem
}
default[] {
get {
return this._default
}
set {
Menu % this.name, Default, % value
return this._default := value
}
}
handle[] {
get {
return MenuGetHandle(this.name)
}
set {
return value
}
}
}
_menuEventHandler(menu, item, name, index, menuName) {
__Menu__._selectedItem := item
menu := Object(menu)
if (item.hasKey("group")) {
for i, v in menu._groups[item.group] {
if (i == index) {
v.checked := true
menu.check(i "&")
} else {
v.checked := false
menu.uncheck(i "&")
}
}
} else if (item.hasKey("checked")) {
item.checked := !item.checked
menu.toggleCheck(index "&")
}
if (menu.callback) {
func := IsObject(menu.callback) ? menu.callback : Func(menu.callback)
func.call(item, index, menu)
}
if (item.callback) {
func := IsObject(item.callback) ? item.callback : Func(item.callback)
func.call(item, index, menu)
}
}