feat: add items to playlist from files menu when holding ctrl (#822)

Closes #821
This commit is contained in:
christoph-heinrich
2024-01-08 19:18:43 +01:00
committed by GitHub
parent efd6a55b20
commit 0f970b5d8e
3 changed files with 18 additions and 7 deletions

View File

@@ -257,7 +257,8 @@ Displays a command palette menu with all key bindings defined in your `input.con
Open file menu. Browsing starts in current file directory, or user directory when file not available. The explorer only displays file types defined in the `video_types`, `audio_types`, and `image_types` options. Open file menu. Browsing starts in current file directory, or user directory when file not available. The explorer only displays file types defined in the `video_types`, `audio_types`, and `image_types` options.
You can use `ctrl+enter` or `ctrl+click` to load the whole directory in mpv instead of navigating its contents. You can use `alt+enter` or `alt+click` to load the whole directory in mpv instead of navigating its contents.
You can also use `ctrl+enter` or `ctrl+click` to append a file or directory to the playlist.
#### `items` #### `items`

View File

@@ -1026,7 +1026,7 @@ function Menu:enable_key_bindings()
self:create_key_action('open_selected_item_soft', {shift = true})) self:create_key_action('open_selected_item_soft', {shift = true}))
self:add_key_binding('shift+mbtn_left', 'menu-select3', self:create_modified_mbtn_left_handler({shift = true})) self:add_key_binding('shift+mbtn_left', 'menu-select3', self:create_modified_mbtn_left_handler({shift = true}))
self:add_key_binding('ctrl+mbtn_left', 'menu-select4', self:create_modified_mbtn_left_handler({ctrl = true})) self:add_key_binding('ctrl+mbtn_left', 'menu-select4', self:create_modified_mbtn_left_handler({ctrl = true}))
self:add_key_binding('alt+mbtn_left', 'menu-select4', self:create_modified_mbtn_left_handler({alt = true})) self:add_key_binding('alt+mbtn_left', 'menu-select5', self:create_modified_mbtn_left_handler({alt = true}))
self:add_key_binding('mbtn_back', 'menu-back-alt3', self:create_key_action('back')) self:add_key_binding('mbtn_back', 'menu-back-alt3', self:create_key_action('back'))
self:add_key_binding('bs', 'menu-back-alt4', self:create_key_action('key_bs'), {repeatable = true, complex = true}) self:add_key_binding('bs', 'menu-back-alt4', self:create_key_action('key_bs'), {repeatable = true, complex = true})
self:add_key_binding('shift+bs', 'menu-clear-query', self:create_key_action('key_bs', {shift = true}), self:add_key_binding('shift+bs', 'menu-clear-query', self:create_key_action('key_bs', {shift = true}),

View File

@@ -186,11 +186,11 @@ function create_select_tracklist_type_menu_opener(menu_title, track_type, track_
}) })
end end
---@alias NavigationMenuOptions {type: string, title?: string, allowed_types?: string[], active_path?: string, selected_path?: string; on_open?: fun(); on_close?: fun()} ---@alias NavigationMenuOptions {type: string, title?: string, allowed_types?: string[], keep_open?: boolean, active_path?: string, selected_path?: string; on_open?: fun(); on_close?: fun()}
-- Opens a file navigation menu with items inside `directory_path`. -- Opens a file navigation menu with items inside `directory_path`.
---@param directory_path string ---@param directory_path string
---@param handle_select fun(path: string): nil ---@param handle_select fun(path: string, mods: Modifiers): nil
---@param opts NavigationMenuOptions ---@param opts NavigationMenuOptions
function open_file_navigation_menu(directory_path, handle_select, opts) function open_file_navigation_menu(directory_path, handle_select, opts)
directory = serialize_path(normalize_path(directory_path)) directory = serialize_path(normalize_path(directory_path))
@@ -251,6 +251,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
local is_to_parent = is_drives or #path < #directory_path local is_to_parent = is_drives or #path < #directory_path
local inheritable_options = { local inheritable_options = {
type = opts.type, title = opts.title, allowed_types = opts.allowed_types, active_path = opts.active_path, type = opts.type, title = opts.title, allowed_types = opts.allowed_types, active_path = opts.active_path,
keep_open = opts.keep_open,
} }
if is_drives then if is_drives then
@@ -273,7 +274,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
return return
end end
if info.is_dir and not meta.modifiers.alt then if info.is_dir and not meta.modifiers.alt and not meta.modifiers.ctrl then
-- Preselect directory we are coming from -- Preselect directory we are coming from
if is_to_parent then if is_to_parent then
inheritable_options.selected_path = directory.path inheritable_options.selected_path = directory.path
@@ -281,7 +282,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
open_file_navigation_menu(path, handle_select, inheritable_options) open_file_navigation_menu(path, handle_select, inheritable_options)
else else
handle_select(path) handle_select(path, meta.modifiers)
end end
end end
@@ -293,6 +294,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
type = opts.type, type = opts.type,
title = opts.title or directory.basename .. path_separator, title = opts.title or directory.basename .. path_separator,
items = items, items = items,
keep_open = opts.keep_open,
selected_index = selected_index, selected_index = selected_index,
} }
local menu_options = {on_open = opts.on_open, on_close = opts.on_close, on_back = handle_back} 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()
menu = open_file_navigation_menu( menu = open_file_navigation_menu(
directory, directory,
function(path) mp.commandv('loadfile', path) end, function(path, mods)
if mods.ctrl then
mp.commandv('loadfile', path, 'append')
else
mp.commandv('loadfile', path)
Menu:close()
end
end,
{ {
type = 'open-file', type = 'open-file',
allowed_types = config.types.media, allowed_types = config.types.media,
active_path = active_file, active_path = active_file,
keep_open = true,
on_open = function() mp.register_event('file-loaded', handle_file_loaded) end, on_open = function() mp.register_event('file-loaded', handle_file_loaded) end,
on_close = function() mp.unregister_event(handle_file_loaded) end, on_close = function() mp.unregister_event(handle_file_loaded) end,
} }