-
Notifications
You must be signed in to change notification settings - Fork 72
/
CMenuBar.ahk
185 lines (168 loc) · 9.71 KB
/
CMenuBar.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#Include <CMenuItem>
class CMenuBar
{
; Instance properties
; Menu name
name := ""
; text for dropdown menus
text := ""
; Menu items
items := []
itemsByNames := {}
; submenus
; submenus := []
; A parent item object for a submenu
parent := ""
; A flag that is used to insert or remove all standard (non-custom) menu items from the tray menu (if they are present).
standard := false
; A variable that is used to set the Tray menu's default item or to change the menu back to having its standard default menu item, which is OPEN for non-compiled scripts and none for compiled scripts (except when the MainWindow option is in effect). If the OPEN menu item does not exist due to a previous use of the NoStandard command below, there will be no default and thus double-clicking the tray icon will have no effect. For menus other than TRAY: Any existing default item is returned to a non-bold font.
default := ""
; A gui
gui := {}
;
; Function: __New
; Description:
; Creates an instance of MenuBase (not the menu itself).
; Syntax: __New(gui [, name, parent, standard, default])
; Parameters:
; gui - Gui this menu belongs to.
; name - Menu name (as used in Menu, [b]name[/b], add, ...)
; parent - (Optional) (CMenuItem) A menu item containing this menu. Tray menu will always have parent = "" even if set.
; standard - (Optional) Inserts (if true) or removes (if false) standard menu items into this menu.
; default - (Optional) (MenuItemBase) Changes the menu's default item to be the specified item.
; Return Value:
; Returns an instance of MenuBase.
; Remarks:
; Use without parameters to create an empty tray menu with no default items.
; Example:
; mTray := new MenuBase()
; mi := new MenuItemBase("MyMenuItem1", mTray)
;
__New(name = "tray", parent = "", gui="", standard = false, default = "")
{
this.name := name
if(this.name = "tray" or this.name = "Tray")
{
this.name := "tray"
this.parent := ""
this.gui := ""
this.default := default
}
else
{
this.parent := parent
this.default := ""
this.gui := gui
this.parent.AddLastSubmenu(this)
}
this.standard := standard
; OutputDebug % "MenuBar.__New result : name = " this.name
}
;
; Function: Create
; Description:
; Creates the menu and all its items (if any).
; Syntax: Object.Create()
; Remarks:
; The menu is not created if it nas ho items.
;
Create()
{
; OutputDebug % "In MenuBar.Create(" this.name ")"
if(IsEmpty(this.items) && IsEmpty(this.submenus))
return
if(this.name = "tray")
{
if(!this.standard)
{
menu, tray, NoStandard
}
if(this.default = "")
{
menu, tray, NoDefault
}
}
for i, item in this.items
{
; We do not check here if an item is created because this check is performed in item.Create()
item.Create()
}
; for i, item in this.submenus
; {
; ; We do not check here if an item is created because this check is performed in item.Create()
; item.Create()
; }
if(this.parent)
{
; OutputDebug % "Adding to the parent: Menu, " this.parent.name ", add, :" _t(this.name)
Menu, % this.parent.name, add, % _t(this.name), % ":" this.name
this.text := _t(this.name)
}
; Set the flag
this.created := true
; OutputDebug % "Leaving MenuBar.Create(" this.name ")"
}
AddLastItem(name = "", label = "")
{
; OutputDebug, Adding menu item %name% > %label%
mi := new CMenuItem(this, name, label)
this.items.insert(mi)
if(name)
{
this.itemsByNames[name] := mi
}
; mi.position := this.items.maxindex()
return mi
}
AddLastSubmenu(submenu)
{
; OutputDebug, % "Adding submenu " submenu.name
this.items.insert(submenu)
if(submenu.name)
{
this.itemsByNames[submenu.name] := submenu
}
}
AddFirstItem(name = "", label = "")
{
; OutputDebug, Adding menu item %name% > %label%
mi := new CMenuItem(this, name, label)
this.items.insert(1, mi)
if(name)
{
this.itemsByNames[name] := mi
}
return mi
}
RemoveLastItem()
{
if(this.items)
{
if(this.created)
Menu, % this.name, delete, % this.items[Count(this.items)].name
this.items.Remove()
}
}
RemoveItems()
{
if(this.created)
{
Menu, % this.name, deleteAll
}
this.items := []
this.itemsByNames := {}
}
Localize()
{
for i, item in this.items
{
item.Localize()
}
if(this.parent)
{
; OutputDebug % "Adding to the parent: Menu, " this.parent.name ", add, :" _t(this.name)
Menu, % this.parent.name, Rename, % this.text, % _t(this.name)
this.text := _t(this.name)
}
}
}