Skip to content

Commit

Permalink
feat: add more actions to track menu and updated chinese translation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dyphire authored Sep 2, 2024
1 parent 5011139 commit bb83e40
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 deletions.
13 changes: 8 additions & 5 deletions src/uosc/intl/zh-hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"%s channel": "%s 声道",
"%s channels": "%s 声道",
"%s to delete": "删除 %s",
"%s to go up in tree.": "使用 %s 返回上一级",
"%s to reorder.": "使用 %s 重新排序",
"%s to search": "搜索 %s",
"Activate as secondary": "设置为次字幕",
"Add to playlist": "添加到播放列表",
"Added to playlist": "已添加到播放列表",
"An error has occurred.": "出现错误",
Expand All @@ -31,15 +32,15 @@
"Key bindings": "键位绑定",
"Last": "最后一个",
"Load": "加载",
"Load audio": "加载音频",
"Load audio": "加载音轨",
"Load subtitles": "加载字幕",
"Load video": "加载视频",
"Load video": "加载视频轨",
"Loaded audio": "已加载音轨",
"Loaded subtitles": "已加载字幕",
"Loaded video": "已加载视频轨",
"Loop file": "单个循环",
"Loop playlist": "列表循环",
"Menu": "菜单",
"Move down": "下移",
"Move up": "上移",
"Navigation": "导航",
"Next": "下一个",
"Next page": "下一页",
Expand All @@ -57,6 +58,7 @@
"Previous": "上一个",
"Previous page": "上一页",
"Quit": "退出",
"Reload": "重载",
"Remaining downloads today: %s": "今天的剩余下载量: %s",
"Remove": "移除",
"Resets in: %s": "重置: %s",
Expand All @@ -72,6 +74,7 @@
"Track %s": "轨道 %s",
"Update uosc": "更新 uosc",
"Updating uosc": "正在更新 uosc",
"Use as secondary": "设置为次字幕",
"Utils": "工具",
"Video": "视频",
"default": "默认",
Expand Down
62 changes: 55 additions & 7 deletions src/uosc/lib/menus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ function create_self_updating_menu_opener(opts)
end
elseif event.type == 'key' then
local item = event.selected_item
if event.id == 'enter' then
if opts.on_key then
opts.on_key(event --[[@as MenuEventKey]], cleanup_and_close)
elseif event.id == 'enter' then
cleanup_and_close()
elseif event.key == 'del' and item then
if itable_has({nil, 'ctrl'}, event.modifiers) then
remove_or_delete(item.index, item.value, event.menu_id, event.modifiers)
end
elseif opts.on_key then
opts.on_key(event --[[@as MenuEventKey]], cleanup_and_close)
end
elseif event.type == 'paste' and opts.on_paste then
opts.on_paste(event --[[@as MenuEventPaste]])
Expand Down Expand Up @@ -186,9 +186,16 @@ function create_select_tracklist_type_menu_opener(opts)
local first_item_index = #items + 1
local active_index = nil
local disabled_item = nil
local track_actions = snd and {
{name = 'as_secondary', icon = snd.icon, label = t('Use as secondary') .. ' (shift+enter/click)'},
} or nil
local track_actions = nil
local track_external_actions = {}

if snd then
local action = {name = 'as_secondary', icon = snd.icon, label = t('Use as secondary') .. ' (shift+enter/click)'}
track_actions = {action}
table.insert(track_external_actions, action)
end
table.insert(track_external_actions, {name = 'reload', icon = 'refresh', label = t('Reload') .. ' (f5)'})
table.insert(track_external_actions, {name = 'remove', icon = 'delete', label = t('Remove') .. ' (del)'})

for _, track in ipairs(tracklist) do
if track.type == opts.type then
Expand Down Expand Up @@ -220,7 +227,7 @@ function create_select_tracklist_type_menu_opener(opts)
active = track_selected or snd_selected,
italic = snd_selected,
icon = snd and snd_selected and snd.icon or nil,
actions = track_actions,
actions = track.external and track_external_actions or track_actions,
}

if track_selected then
Expand All @@ -233,6 +240,28 @@ function create_select_tracklist_type_menu_opener(opts)
return items, active_index or first_item_index
end

local function reload(id)
if not id then return end
if opts.type == "video" then
mp.commandv("video-reload", id)
elseif opts.type == "audio" then
mp.commandv("audio-reload", id)
elseif opts.type == "sub" then
mp.commandv("sub-reload", id)
end
end

local function remove(id)
if not id then return end
if opts.type == "video" then
mp.commandv("video-remove", id)
elseif opts.type == "audio" then
mp.commandv("audio-remove", id)
elseif opts.type == "sub" then
mp.commandv("sub-remove", id)
end
end

---@param event MenuEventActivate
local function handle_activate(event)
if event.value == '{load}' then
Expand All @@ -244,6 +273,10 @@ function create_select_tracklist_type_menu_opener(opts)
if snd.enable_prop then
mp.commandv('set', snd.enable_prop, 'yes')
end
elseif event.action == 'reload' then
reload(event.value)
elseif event.action == 'remove' then
remove(event.value)
elseif not event.modifiers or event.modifiers == 'alt' then
mp.commandv('set', opts.prop, event.value == get_props() and 'no' or event.value)
if opts.enable_prop then
Expand All @@ -253,13 +286,28 @@ function create_select_tracklist_type_menu_opener(opts)
end
end

---@param event MenuEventKey
local function handle_key(event)
local item = event.selected_item
if event.id == 'f5' then
if item then
reload(item.value)
end
elseif event.id == 'del' then
if item then
remove(item.value)
end
end
end

return create_self_updating_menu_opener({
title = opts.title,
footnote = t('Toggle to disable.') .. ' ' .. t('Paste path or url to add.'),
type = opts.type,
list_prop = 'track-list',
serializer = serialize_tracklist,
on_activate = handle_activate,
on_key = handle_key,
actions_place = 'outside',
on_paste = function(event) load_track(opts.type, event.value) end,
})
Expand Down

0 comments on commit bb83e40

Please sign in to comment.