Skip to content

Commit

Permalink
feat: ctrl+c to copy a path of selected item in playlist or `open…
Browse files Browse the repository at this point in the history
…-file` menus
  • Loading branch information
tomasklaen committed Sep 4, 2024
1 parent 66cf568 commit ca3263f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ Note: there are alternative ways to open stuff from clipboard without the need t
Copy currently open path or URL to clipboard.
Additionally, you can also press `ctrl+c` to copy path of a selected item in `playlist` or all directory listing menus.
#### `open-config-directory`
Open directory with `mpv.conf` in file explorer.
Expand Down
7 changes: 5 additions & 2 deletions src/uosc/elements/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ function Menu:update_dimensions()
-- and dumb titles with no search inputs. It could use a refactor.
local margin = round(self.item_height / 2)
local external_buttons_reserve = display.width / self.item_height > 14 and self.scroll_step * 6 - margin * 2 or 0
local width_available, height_available = display.width - margin * 2 - external_buttons_reserve, display.height - margin * 2
local width_available = display.width - margin * 2 - external_buttons_reserve
local height_available = display.height - margin * 2
local min_width = math.min(self.min_width, width_available)

for _, menu in ipairs(self.all) do
Expand Down Expand Up @@ -1031,7 +1032,9 @@ end

function Menu:enable_key_bindings()
-- `+` at the end enables `repeatable` flag
local standalone_keys = {'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', {'v', 'ctrl'}}
local standalone_keys = {
'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', {'v', 'ctrl'}, {'c', 'ctrl'},
}
local modifiable_keys = {'up+', 'down+', 'left', 'right', 'enter', 'kp_enter', 'bs', 'tab', 'esc', 'pgup+',
'pgdwn+', 'home', 'end', 'del'}
local modifiers = {nil, 'alt', 'alt+ctrl', 'alt+shift', 'alt+ctrl+shift', 'ctrl', 'ctrl+shift', 'shift'}
Expand Down
5 changes: 5 additions & 0 deletions src/uosc/lib/menus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ function open_file_navigation_menu(directory_path, handle_activate, opts)
if back_path then open_directory(back_path) end
elseif event.type == 'paste' then
handle_activate({type = 'activate', value = event.value})
elseif event.type == 'key' then
if event.id == 'ctrl+c' and event.selected_item then
set_clipboard(event.selected_item.value)
mp.commandv('show-text', t('Copied to clipboard') .. ': ' .. event.selected_item.value, 3000)
end
elseif event.type == 'close' then
close()
end
Expand Down
7 changes: 7 additions & 0 deletions src/uosc/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,13 @@ bind_command('playlist', create_self_updating_menu_opener({
end,
on_activate = function(event) mp.commandv('set', 'playlist-pos-1', tostring(event.value)) end,
on_paste = function(event) mp.commandv('loadfile', tostring(event.value), 'append') end,
on_key = function(event)
if event.id == 'ctrl+c' and event.selected_item then
local payload = mp.get_property_native('playlist/' .. (event.selected_item.value - 1) .. '/filename')
set_clipboard(payload)
mp.commandv('show-text', t('Copied to clipboard') .. ': ' .. payload, 3000)
end
end,
on_move = function(event)
local from, to = event.from_index, event.to_index
mp.commandv('playlist-move', tostring(from - 1), tostring(to - (to > from and 0 or 1)))
Expand Down

0 comments on commit ca3263f

Please sign in to comment.