Skip to content

Commit

Permalink
feat: add items to playlist from files menu when holding ctrl (#822)
Browse files Browse the repository at this point in the history
Closes #821
  • Loading branch information
christoph-heinrich authored Jan 8, 2024
1 parent efd6a55 commit 0f970b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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`
Expand Down
2 changes: 1 addition & 1 deletion src/uosc/elements/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ function Menu:enable_key_bindings()
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('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('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}),
Expand Down
20 changes: 15 additions & 5 deletions src/uosc/lib/menus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ function create_select_tracklist_type_menu_opener(menu_title, track_type, track_
})
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`.
---@param directory_path string
---@param handle_select fun(path: string): nil
---@param handle_select fun(path: string, mods: Modifiers): nil
---@param opts NavigationMenuOptions
function open_file_navigation_menu(directory_path, handle_select, opts)
directory = serialize_path(normalize_path(directory_path))
Expand Down Expand Up @@ -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 inheritable_options = {
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
Expand All @@ -273,15 +274,15 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
return
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
if is_to_parent then
inheritable_options.selected_path = directory.path
end

open_file_navigation_menu(path, handle_select, inheritable_options)
else
handle_select(path)
handle_select(path, meta.modifiers)
end
end

Expand All @@ -293,6 +294,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
type = opts.type,
title = opts.title or directory.basename .. path_separator,
items = items,
keep_open = opts.keep_open,
selected_index = selected_index,
}
local menu_options = {on_open = opts.on_open, on_close = opts.on_close, on_back = handle_back}
Expand Down Expand Up @@ -535,11 +537,19 @@ function open_open_file_menu()

menu = open_file_navigation_menu(
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',
allowed_types = config.types.media,
active_path = active_file,
keep_open = true,
on_open = function() mp.register_event('file-loaded', handle_file_loaded) end,
on_close = function() mp.unregister_event(handle_file_loaded) end,
}
Expand Down

0 comments on commit 0f970b5

Please sign in to comment.