-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmenu.lua
207 lines (198 loc) · 3.89 KB
/
menu.lua
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
--
-- simplified version of the menu system used in durden:
--
-- table of tables with:
-- handler = function called on menu selection,
-- label = static string or function returning dynamic string
-- name = binding path keybindings
-- hidden = don't show in UI menus
--
local system = {
{
label = "Exit",
name = "exit",
handler = function()
shutdown();
end
},
{
label = "Reset",
name = "reset",
handler = function()
system_collapse();
end
},
{
label = "Screenshot",
name = "screenshot",
eval = function() return false; end,
handler = function()
prioactions.save_screenshot();
end
},
{
label = "Record",
name = "record",
-- eval = function() return false; end,
handler = function()
prioactions.record();
end
}
};
local function gen_show_menu()
local res = {};
for k,v in ipairs(priohidden) do
table.insert(res, {
label = string.format("%d%s", k, (":") ..
(v.ident and v.ident() or "")),
name = "show_" .. tonumber(k),
handler = function()
v:show();
end
});
end
return res;
end
local global = {
{
label = "New",
name = "new",
handler = function()
prio_input = prio_region_input;
end
},
{
label = function()
local cnt = 0;
for k,v in pairs(priowindows) do cnt = cnt + 1; end
return cnt > 0 and "Delete" or nil;
end,
name = "delete",
handler = function()
mouse_switch_cursor("destroy");
priostate = function(wnd)
priostate = nil;
mouse_switch_cursor();
if (wnd and not wnd.delete_protect) then
wnd:destroy();
return true;
end
end
end
},
{
label = function()
local cnt = 0;
for k,v in pairs(priowindows) do cnt = cnt + 1; end
cnt = cnt - #priohidden;
return cnt > 0 and "Hide" or nil;
end,
name = "hide",
handler = function()
mouse_switch_cursor("hide");
priostate = function(wnd)
priostate = nil;
mouse_switch_cursor();
if (wnd and not wnd.delete_protect) then
wnd:hide();
return true;
end
end
end
},
{
label = function()
return #priohidden > 0 and "Show" or nil;
end,
name = "show",
handler = function()
local mx, my = mouse_xy();
prio_menu_spawn(gen_show_menu(), mx, my);
end
},
{
label = "System",
name = "system",
handler = function()
local mx, my = mouse_xy();
prio_menu_spawn(system, mx, my);
end
}
};
local context = {
{
name = "paste",
label = function(ctx) return "Paste(" ..
string.sub(CLIPBOARD_MESSAGE, 1, 10) .. ")"; end,
eval = function(ctx)
return string.len(CLIPBOARD_MESSAGE) > 0;
end,
handler = function(ctx)
ctx[1]:paste(CLIPBOARD_MESSAGE);
end
},
{
label = function(ctx)
local props = image_storage_properties(ctx[2].source);
return (props.width ~= ctx[1].width or props.height ~= ctx[1].height)
and "Set Source Size" or nil;
end,
name = "source_size",
handler = function(ctx)
local props = image_storage_properties(ctx[2].source);
ctx[1]:resize(props.width, props.height);
ctx[1]:synch_tab_sizes();
end
},
{
name = "toggle_force_size",
label = function(ctx)
return ctx[1].force_size and "Dynamic Size" or "Force Size"
end,
handler = function(ctx)
ctx[1].force_size = not ctx[1].force_size;
ctx[1]:resize(ctx[1].width, ctx[1].height);
end
},
{
name = "toggle_mute",
label = function(ctx)
if (ctx[1].aid == nil or ctx[1].aid == BADID) then
return;
end
return (ctx[1].mute and "Unmute" or "Mute");
end,
handler = function(ctx)
end
},
{
name = "close_tab",
label = "Close",
handler = function(ctx)
ctx[1].lost(ctx[1], ctx[2].source);
end
},
{
name = "save_img",
label = "Output Image",
eval = function() return false; end,
handler = function(ctx)
save_screenshot("prio_imgss.png", FORMAT_PNG, ctx[2].source);
end
},
};
function tab_menu(wnd, tab)
local mx, my = mouse_xy();
prio_menu_spawn(context, mx, my, {wnd, tab});
end
function cancel_menu()
if (priomenu) then
priomenu:destroy();
end
mouse_switch_cursor();
end
function prio_menu()
local mx, my = mouse_xy();
mouse_switch_cursor();
prio_menu_spawn(global, mx, my);
end