Skip to content

Commit fb6bc2b

Browse files
committed
uosc: Add items to playlist from files menu when holding Ctrl
tomasklaen/uosc@0f970b5
1 parent c9a8d68 commit fb6bc2b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

scripts/uosc/elements/Menu.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ function Menu:enable_key_bindings()
10261026
self:create_key_action('open_selected_item_soft', {shift = true}))
10271027
self:add_key_binding('shift+mbtn_left', 'menu-select3', self:create_modified_mbtn_left_handler({shift = true}))
10281028
self:add_key_binding('ctrl+mbtn_left', 'menu-select4', self:create_modified_mbtn_left_handler({ctrl = true}))
1029-
self:add_key_binding('alt+mbtn_left', 'menu-select4', self:create_modified_mbtn_left_handler({alt = true}))
1029+
self:add_key_binding('alt+mbtn_left', 'menu-select5', self:create_modified_mbtn_left_handler({alt = true}))
10301030
self:add_key_binding('mbtn_back', 'menu-back-alt3', self:create_key_action('back'))
10311031
self:add_key_binding('bs', 'menu-back-alt4', self:create_key_action('key_bs'), {repeatable = true, complex = true})
10321032
self:add_key_binding('shift+bs', 'menu-clear-query', self:create_key_action('key_bs', {shift = true}),

scripts/uosc/lib/menus.lua

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ function create_select_tracklist_type_menu_opener(menu_title, track_type, track_
186186
})
187187
end
188188

189-
---@alias NavigationMenuOptions {type: string, title?: string, allowed_types?: string[], active_path?: string, selected_path?: string; on_open?: fun(); on_close?: fun()}
189+
---@alias NavigationMenuOptions {type: string, title?: string, allowed_types?: string[], keep_open?: boolean, active_path?: string, selected_path?: string; on_open?: fun(); on_close?: fun()}
190190

191191
-- Opens a file navigation menu with items inside `directory_path`.
192192
---@param directory_path string
193-
---@param handle_select fun(path: string): nil
193+
---@param handle_select fun(path: string, mods: Modifiers): nil
194194
---@param opts NavigationMenuOptions
195195
function open_file_navigation_menu(directory_path, handle_select, opts)
196196
directory = serialize_path(normalize_path(directory_path))
@@ -251,6 +251,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
251251
local is_to_parent = is_drives or #path < #directory_path
252252
local inheritable_options = {
253253
type = opts.type, title = opts.title, allowed_types = opts.allowed_types, active_path = opts.active_path,
254+
keep_open = opts.keep_open,
254255
}
255256

256257
if is_drives then
@@ -273,15 +274,15 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
273274
return
274275
end
275276

276-
if info.is_dir and not meta.modifiers.alt then
277+
if info.is_dir and not meta.modifiers.alt and not meta.modifiers.ctrl then
277278
-- Preselect directory we are coming from
278279
if is_to_parent then
279280
inheritable_options.selected_path = directory.path
280281
end
281282

282283
open_file_navigation_menu(path, handle_select, inheritable_options)
283284
else
284-
handle_select(path)
285+
handle_select(path, meta.modifiers)
285286
end
286287
end
287288

@@ -293,6 +294,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
293294
type = opts.type,
294295
title = opts.title or directory.basename .. path_separator,
295296
items = items,
297+
keep_open = opts.keep_open,
296298
selected_index = selected_index,
297299
}
298300
local menu_options = {on_open = opts.on_open, on_close = opts.on_close, on_back = handle_back}
@@ -535,11 +537,19 @@ function open_open_file_menu()
535537

536538
menu = open_file_navigation_menu(
537539
directory,
538-
function(path) mp.commandv('loadfile', path) end,
540+
function(path, mods)
541+
if mods.ctrl then
542+
mp.commandv('loadfile', path, 'append')
543+
else
544+
mp.commandv('loadfile', path)
545+
Menu:close()
546+
end
547+
end,
539548
{
540549
type = 'open-file',
541550
allowed_types = config.types.media,
542551
active_path = active_file,
552+
keep_open = true,
543553
on_open = function() mp.register_event('file-loaded', handle_file_loaded) end,
544554
on_close = function() mp.unregister_event(handle_file_loaded) end,
545555
}

0 commit comments

Comments
 (0)