@@ -130,14 +130,14 @@ function create_self_updating_menu_opener(opts)
130
130
end
131
131
elseif event .type == ' key' then
132
132
local item = event .selected_item
133
- if event .id == ' enter' then
133
+ if opts .on_key then
134
+ opts .on_key (event --[[ @as MenuEventKey]] , cleanup_and_close )
135
+ elseif event .id == ' enter' then
134
136
cleanup_and_close ()
135
137
elseif event .key == ' del' and item then
136
138
if itable_has ({nil , ' ctrl' }, event .modifiers ) then
137
139
remove_or_delete (item .index , item .value , event .menu_id , event .modifiers )
138
140
end
139
- elseif opts .on_key then
140
- opts .on_key (event --[[ @as MenuEventKey]] , cleanup_and_close )
141
141
end
142
142
elseif event .type == ' paste' and opts .on_paste then
143
143
opts .on_paste (event --[[ @as MenuEventPaste]] )
@@ -186,9 +186,16 @@ function create_select_tracklist_type_menu_opener(opts)
186
186
local first_item_index = # items + 1
187
187
local active_index = nil
188
188
local disabled_item = nil
189
- local track_actions = snd and {
190
- {name = ' as_secondary' , icon = snd .icon , label = t (' Use as secondary' ) .. ' (shift+enter/click)' },
191
- } or nil
189
+ local track_actions = nil
190
+ local track_external_actions = {}
191
+
192
+ if snd then
193
+ local action = {name = ' as_secondary' , icon = snd .icon , label = t (' Use as secondary' ) .. ' (shift+enter/click)' }
194
+ track_actions = {action }
195
+ table.insert (track_external_actions , action )
196
+ end
197
+ table.insert (track_external_actions , {name = ' reload' , icon = ' refresh' , label = t (' Reload' ) .. ' (f5)' })
198
+ table.insert (track_external_actions , {name = ' remove' , icon = ' delete' , label = t (' Remove' ) .. ' (del)' })
192
199
193
200
for _ , track in ipairs (tracklist ) do
194
201
if track .type == opts .type then
@@ -220,7 +227,7 @@ function create_select_tracklist_type_menu_opener(opts)
220
227
active = track_selected or snd_selected ,
221
228
italic = snd_selected ,
222
229
icon = snd and snd_selected and snd .icon or nil ,
223
- actions = track_actions ,
230
+ actions = track . external and track_external_actions or track_actions ,
224
231
}
225
232
226
233
if track_selected then
@@ -233,6 +240,28 @@ function create_select_tracklist_type_menu_opener(opts)
233
240
return items , active_index or first_item_index
234
241
end
235
242
243
+ local function reload (id )
244
+ if not id then return end
245
+ if opts .type == " video" then
246
+ mp .commandv (" video-reload" , id )
247
+ elseif opts .type == " audio" then
248
+ mp .commandv (" audio-reload" , id )
249
+ elseif opts .type == " sub" then
250
+ mp .commandv (" sub-reload" , id )
251
+ end
252
+ end
253
+
254
+ local function remove (id )
255
+ if not id then return end
256
+ if opts .type == " video" then
257
+ mp .commandv (" video-remove" , id )
258
+ elseif opts .type == " audio" then
259
+ mp .commandv (" audio-remove" , id )
260
+ elseif opts .type == " sub" then
261
+ mp .commandv (" sub-remove" , id )
262
+ end
263
+ end
264
+
236
265
--- @param event MenuEventActivate
237
266
local function handle_activate (event )
238
267
if event .value == ' {load}' then
@@ -244,6 +273,10 @@ function create_select_tracklist_type_menu_opener(opts)
244
273
if snd .enable_prop then
245
274
mp .commandv (' set' , snd .enable_prop , ' yes' )
246
275
end
276
+ elseif event .action == ' reload' then
277
+ reload (event .value )
278
+ elseif event .action == ' remove' then
279
+ remove (event .value )
247
280
elseif not event .modifiers or event .modifiers == ' alt' then
248
281
mp .commandv (' set' , opts .prop , event .value == get_props () and ' no' or event .value )
249
282
if opts .enable_prop then
@@ -253,13 +286,28 @@ function create_select_tracklist_type_menu_opener(opts)
253
286
end
254
287
end
255
288
289
+ --- @param event MenuEventKey
290
+ local function handle_key (event )
291
+ local item = event .selected_item
292
+ if event .id == ' f5' then
293
+ if item then
294
+ reload (item .value )
295
+ end
296
+ elseif event .id == ' del' then
297
+ if item then
298
+ remove (item .value )
299
+ end
300
+ end
301
+ end
302
+
256
303
return create_self_updating_menu_opener ({
257
304
title = opts .title ,
258
305
footnote = t (' Toggle to disable.' ) .. ' ' .. t (' Paste path or url to add.' ),
259
306
type = opts .type ,
260
307
list_prop = ' track-list' ,
261
308
serializer = serialize_tracklist ,
262
309
on_activate = handle_activate ,
310
+ on_key = handle_key ,
263
311
actions_place = ' outside' ,
264
312
on_paste = function (event ) load_track (opts .type , event .value ) end ,
265
313
})
0 commit comments