Skip to content

Commit

Permalink
feat: various menu actions adjustments
Browse files Browse the repository at this point in the history
We now only display actions outside the menu when hint or icon have a high informational value and shouldn't be covered by buttons (like track menus).

Up/down reordering buttons in playlist menu have been removed. A bit too much clutter, and reordering by clicking these was not a good UX anyway. The info about what shortcuts can be used to reorder items is now available in menu footer.

Clarified shortcut alternatives to various menu actions in their labels.

And some action icon changes.

ref #965
  • Loading branch information
tomasklaen committed Sep 1, 2024
1 parent a77e11f commit 3215c13
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
34 changes: 8 additions & 26 deletions src/uosc/lib/menus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function toggle_menu_with_items(opts)
end

---@alias EventRemove {type: 'remove' | 'delete', index: number; value: any; menu_id: string;}
---@param opts {type: string; title: string; list_prop: string; active_prop?: string; footnote?: string; serializer: fun(list: any, active: any): MenuDataItem[]; actions?: MenuAction[]; on_paste: fun(event: MenuEventPaste); on_move?: fun(event: MenuEventMove); on_activate?: fun(event: MenuEventActivate); on_remove?: fun(event: EventRemove); on_delete?: fun(event: EventRemove);}
---@param opts {type: string; title: string; list_prop: string; active_prop?: string; footnote?: string; serializer: fun(list: any, active: any): MenuDataItem[]; actions?: MenuAction[]; actions_place?: 'inside'|'outside'; on_paste: fun(event: MenuEventPaste); on_move?: fun(event: MenuEventMove); on_activate?: fun(event: MenuEventActivate); on_remove?: fun(event: EventRemove); on_delete?: fun(event: EventRemove);}
function create_self_updating_menu_opener(opts)
return function()
if Menu:is_open(opts.type) then
Expand Down Expand Up @@ -77,14 +77,6 @@ function create_self_updating_menu_opener(opts)

---@type MenuAction[]
local actions = opts.actions or {}
if opts.on_move then
actions[#actions + 1] = {
name = 'move_up', icon = 'arrow_upward', label = t('Move up') .. ' (ctrl+up/pgup/home)'
}
actions[#actions + 1] = {
name = 'move_down', icon = 'arrow_downward', label = t('Move down') .. ' (ctrl+down/pgdwn/end)'
}
end
if opts.on_remove or opts.on_delete then
local label = (opts.on_remove and t('Remove') or t('Delete')) .. ' (del)'
if opts.on_remove and opts.on_delete then
Expand Down Expand Up @@ -117,25 +109,14 @@ function create_self_updating_menu_opener(opts)
footnote = opts.footnote,
items = initial_items,
item_actions = actions,
item_actions_place = opts.actions_place,
selected_index = selected_index,
on_move = opts.on_move and 'callback' or nil,
on_paste = opts.on_paste and 'callback' or nil,
on_close = 'callback',
}, function(event)
if event.type == 'activate' then
if (event.action == 'move_up' or event.action == 'move_down') and opts.on_move then
local to_index = event.index + (event.action == 'move_up' and -1 or 1)
if to_index >= 1 and to_index <= #menu.current.items then
opts.on_move({
type = 'move',
from_index = event.index,
to_index = to_index,
menu_id = menu.current.id,
})
menu:select_index(to_index)
menu:scroll_to_index(to_index, nil, true)
end
elseif event.action == 'remove' and (opts.on_remove or opts.on_delete) then
if event.action == 'remove' and (opts.on_remove or opts.on_delete) then
remove_or_delete(event.index, event.value, event.menu_id, event.modifiers)
else
opts.on_activate(event --[[@as MenuEventActivate]])
Expand Down Expand Up @@ -200,7 +181,7 @@ function create_select_tracklist_type_menu_opener(opts)
local active_index = nil
local disabled_item = nil
local track_actions = snd and {
{name = 'as_secondary', icon = snd.icon, label = t('Activate as secondary') .. ' (shift)'},
{name = 'as_secondary', icon = snd.icon, label = t('Use as secondary') .. ' (shift+enter/click)'},
} or nil

for _, track in ipairs(tracklist) do
Expand Down Expand Up @@ -273,6 +254,7 @@ function create_select_tracklist_type_menu_opener(opts)
list_prop = 'track-list',
serializer = serialize_tracklist,
on_activate = handle_activate,
actions_place = 'outside',
on_paste = function(event) load_track(opts.type, event.value) end,
})
end
Expand Down Expand Up @@ -744,11 +726,11 @@ function open_open_file_menu()
allowed_types = config.types.media,
active_path = active_file,
directory_actions = {
{name = 'add_to_playlist', icon = 'playlist_add', label = t('Add to playlist') .. ' (shift)'},
{name = 'force_open', icon = 'folder_open', label = t('Open in mpv') .. ' (ctrl)'},
{name = 'add_to_playlist', icon = 'playlist_add', label = t('Add to playlist') .. ' (shift+enter/click)'},
{name = 'force_open', icon = 'play_circle_outline', label = t('Open in mpv') .. ' (ctrl+enter/click)'},
},
file_actions = {
{name = 'add_to_playlist', icon = 'playlist_add', label = t('Add to playlist') .. ' (shift)'},
{name = 'add_to_playlist', icon = 'playlist_add', label = t('Add to playlist') .. ' (shift+enter/click)'},
},
keep_open = true,
on_close = function() mp.unregister_event(handle_file_loaded) end,
Expand Down
2 changes: 1 addition & 1 deletion src/uosc/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ bind_command('playlist', create_self_updating_menu_opener({
title = t('Playlist'),
type = 'playlist',
list_prop = 'playlist',
footnote = t('Paste path or url to add.'),
footnote = t('Paste path or url to add.') .. ' ' .. t('%s to reorder.', 'ctrl+up/down/pgup/pgdn/home/end'),
serializer = function(playlist)
local items = {}
for index, item in ipairs(playlist) do
Expand Down

0 comments on commit 3215c13

Please sign in to comment.