Skip to content

Commit bb83e40

Browse files
authored
feat: add more actions to track menu and updated chinese translation (#966)
1 parent 5011139 commit bb83e40

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

src/uosc/intl/zh-hans.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"%s channel": "%s 声道",
44
"%s channels": "%s 声道",
55
"%s to delete": "删除 %s",
6+
"%s to go up in tree.": "使用 %s 返回上一级",
7+
"%s to reorder.": "使用 %s 重新排序",
68
"%s to search": "搜索 %s",
7-
"Activate as secondary": "设置为次字幕",
89
"Add to playlist": "添加到播放列表",
910
"Added to playlist": "已添加到播放列表",
1011
"An error has occurred.": "出现错误",
@@ -31,15 +32,15 @@
3132
"Key bindings": "键位绑定",
3233
"Last": "最后一个",
3334
"Load": "加载",
34-
"Load audio": "加载音频",
35+
"Load audio": "加载音轨",
3536
"Load subtitles": "加载字幕",
36-
"Load video": "加载视频",
37+
"Load video": "加载视频轨",
38+
"Loaded audio": "已加载音轨",
3739
"Loaded subtitles": "已加载字幕",
40+
"Loaded video": "已加载视频轨",
3841
"Loop file": "单个循环",
3942
"Loop playlist": "列表循环",
4043
"Menu": "菜单",
41-
"Move down": "下移",
42-
"Move up": "上移",
4344
"Navigation": "导航",
4445
"Next": "下一个",
4546
"Next page": "下一页",
@@ -57,6 +58,7 @@
5758
"Previous": "上一个",
5859
"Previous page": "上一页",
5960
"Quit": "退出",
61+
"Reload": "重载",
6062
"Remaining downloads today: %s": "今天的剩余下载量: %s",
6163
"Remove": "移除",
6264
"Resets in: %s": "重置: %s",
@@ -72,6 +74,7 @@
7274
"Track %s": "轨道 %s",
7375
"Update uosc": "更新 uosc",
7476
"Updating uosc": "正在更新 uosc",
77+
"Use as secondary": "设置为次字幕",
7578
"Utils": "工具",
7679
"Video": "视频",
7780
"default": "默认",

src/uosc/lib/menus.lua

+55-7
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ function create_self_updating_menu_opener(opts)
130130
end
131131
elseif event.type == 'key' then
132132
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
134136
cleanup_and_close()
135137
elseif event.key == 'del' and item then
136138
if itable_has({nil, 'ctrl'}, event.modifiers) then
137139
remove_or_delete(item.index, item.value, event.menu_id, event.modifiers)
138140
end
139-
elseif opts.on_key then
140-
opts.on_key(event --[[@as MenuEventKey]], cleanup_and_close)
141141
end
142142
elseif event.type == 'paste' and opts.on_paste then
143143
opts.on_paste(event --[[@as MenuEventPaste]])
@@ -186,9 +186,16 @@ function create_select_tracklist_type_menu_opener(opts)
186186
local first_item_index = #items + 1
187187
local active_index = nil
188188
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)'})
192199

193200
for _, track in ipairs(tracklist) do
194201
if track.type == opts.type then
@@ -220,7 +227,7 @@ function create_select_tracklist_type_menu_opener(opts)
220227
active = track_selected or snd_selected,
221228
italic = snd_selected,
222229
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,
224231
}
225232

226233
if track_selected then
@@ -233,6 +240,28 @@ function create_select_tracklist_type_menu_opener(opts)
233240
return items, active_index or first_item_index
234241
end
235242

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+
236265
---@param event MenuEventActivate
237266
local function handle_activate(event)
238267
if event.value == '{load}' then
@@ -244,6 +273,10 @@ function create_select_tracklist_type_menu_opener(opts)
244273
if snd.enable_prop then
245274
mp.commandv('set', snd.enable_prop, 'yes')
246275
end
276+
elseif event.action == 'reload' then
277+
reload(event.value)
278+
elseif event.action == 'remove' then
279+
remove(event.value)
247280
elseif not event.modifiers or event.modifiers == 'alt' then
248281
mp.commandv('set', opts.prop, event.value == get_props() and 'no' or event.value)
249282
if opts.enable_prop then
@@ -253,13 +286,28 @@ function create_select_tracklist_type_menu_opener(opts)
253286
end
254287
end
255288

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+
256303
return create_self_updating_menu_opener({
257304
title = opts.title,
258305
footnote = t('Toggle to disable.') .. ' ' .. t('Paste path or url to add.'),
259306
type = opts.type,
260307
list_prop = 'track-list',
261308
serializer = serialize_tracklist,
262309
on_activate = handle_activate,
310+
on_key = handle_key,
263311
actions_place = 'outside',
264312
on_paste = function(event) load_track(opts.type, event.value) end,
265313
})

0 commit comments

Comments
 (0)