Improve directory navigation, and rename the command to open-file
This commit is contained in:
@@ -238,9 +238,9 @@ Menu to select an item from playlist.
|
|||||||
|
|
||||||
Menu to seek to start of a specific chapter.
|
Menu to seek to start of a specific chapter.
|
||||||
|
|
||||||
#### `navigate-directory`
|
#### `open-file`
|
||||||
|
|
||||||
Menu to navigate media files in current files' directory with current file preselected.
|
Open file menu. Browsing starts in current file directory, or user directory when file not available.
|
||||||
|
|
||||||
#### `next-file`
|
#### `next-file`
|
||||||
|
|
||||||
@@ -335,19 +335,19 @@ Suggested minimal context menu setup to start with:
|
|||||||
```
|
```
|
||||||
menu script-binding uosc/context-menu
|
menu script-binding uosc/context-menu
|
||||||
mbtn_right script-binding uosc/context-menu
|
mbtn_right script-binding uosc/context-menu
|
||||||
|
o script-binding uosc/open-file #! Open file
|
||||||
alt+s script-binding uosc/load-subtitles #! Load subtitles
|
alt+s script-binding uosc/load-subtitles #! Load subtitles
|
||||||
S script-binding uosc/select-subtitles #! Select subtitles
|
S script-binding uosc/select-subtitles #! Select subtitles
|
||||||
A script-binding uosc/select-audio #! Select audio
|
A script-binding uosc/select-audio #! Select audio
|
||||||
ctrl+s async screenshot #! Utils > Screenshot
|
ctrl+s async screenshot #! Utils > Screenshot
|
||||||
P script-binding uosc/navigate-playlist #! Utils > Navigate playlist
|
P script-binding uosc/navigate-playlist #! Utils > Navigate playlist
|
||||||
C script-binding uosc/navigate-chapters #! Utils > Navigate chapters
|
C script-binding uosc/navigate-chapters #! Utils > Navigate chapters
|
||||||
D script-binding uosc/navigate-directory #! Utils > Navigate directory
|
|
||||||
# script-binding uosc/open-config-directory #! Utils > Open config directory
|
# script-binding uosc/open-config-directory #! Utils > Open config directory
|
||||||
# set video-aspect-override "-1" #! Aspect ratio > Default
|
# set video-aspect-override "-1" #! Aspect ratio > Default
|
||||||
# set video-aspect-override "16:9" #! Aspect ratio > 16:9
|
# set video-aspect-override "16:9" #! Aspect ratio > 16:9
|
||||||
# set video-aspect-override "4:3" #! Aspect ratio > 4:3
|
# set video-aspect-override "4:3" #! Aspect ratio > 4:3
|
||||||
# set video-aspect-override "2.35:1" #! Aspect ratio > 2.35:1
|
# set video-aspect-override "2.35:1" #! Aspect ratio > 2.35:1
|
||||||
o script-binding uosc/show-in-directory #! Show in directory
|
O script-binding uosc/show-in-directory #! Show in directory
|
||||||
esc quit #! Quit
|
esc quit #! Quit
|
||||||
q quit #!
|
q quit #!
|
||||||
```
|
```
|
||||||
|
90
uosc.lua
90
uosc.lua
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
uosc 2.6.0 - 2020-Apr-24 | https://github.com/darsain/uosc
|
uosc 2.6.0 - 2020-Apr-24 | https://github.com/darsain/uosc
|
||||||
|
|
||||||
Minimalistic cursor proximity based UI for MPV player.
|
Minimalist cursor proximity based UI for MPV player.
|
||||||
|
|
||||||
uosc replaces the default osc UI, so that has to be disabled first.
|
uosc replaces the default osc UI, so that has to be disabled first.
|
||||||
Place these options into your `mpv.conf` file:
|
Place these options into your `mpv.conf` file:
|
||||||
@@ -155,7 +155,7 @@ Key script-binding uosc/select-audio
|
|||||||
Key script-binding uosc/select-video
|
Key script-binding uosc/select-video
|
||||||
Key script-binding uosc/navigate-playlist
|
Key script-binding uosc/navigate-playlist
|
||||||
Key script-binding uosc/navigate-chapters
|
Key script-binding uosc/navigate-chapters
|
||||||
Key script-binding uosc/navigate-directory
|
Key script-binding uosc/open-file
|
||||||
Key script-binding uosc/next-file
|
Key script-binding uosc/next-file
|
||||||
Key script-binding uosc/prev-file
|
Key script-binding uosc/prev-file
|
||||||
Key script-binding uosc/first-file
|
Key script-binding uosc/first-file
|
||||||
@@ -507,10 +507,10 @@ end
|
|||||||
|
|
||||||
-- Ensures path is absolute and normalizes slashes to the current platform
|
-- Ensures path is absolute and normalizes slashes to the current platform
|
||||||
function normalize_path(path)
|
function normalize_path(path)
|
||||||
if is_protocol(path) then return path end
|
if not path or is_protocol(path) then return path end
|
||||||
|
|
||||||
-- Ensure path is absolute
|
-- Ensure path is absolute
|
||||||
if not (path:match('^/') or path:match('^%a+:[/\\]') or path:match('^\\\\')) then
|
if not (path:match('^/') or path:match('^%a+:') or path:match('^\\\\')) then
|
||||||
path = utils.join_path(state.cwd, path)
|
path = utils.join_path(state.cwd, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -534,15 +534,17 @@ end
|
|||||||
|
|
||||||
-- Serializes path into its semantic parts
|
-- Serializes path into its semantic parts
|
||||||
function serialize_path(path)
|
function serialize_path(path)
|
||||||
if is_protocol(path) then return end
|
if not path or is_protocol(path) then return end
|
||||||
path = normalize_path(path)
|
path = normalize_path(path)
|
||||||
local parts = split(path, '[\\/]+')
|
local parts = split(path, '[\\/]+')
|
||||||
|
if parts[#parts] == '' then table.remove(parts, #parts) end -- remove trailing separator
|
||||||
local basename = parts and parts[#parts] or path
|
local basename = parts and parts[#parts] or path
|
||||||
local dirname = #parts > 1 and table.concat(itable_slice(parts, 1, #parts - 1), '/') or nil
|
local dirname = #parts > 1 and table.concat(itable_slice(parts, 1, #parts - 1), state.os == 'windows' and '\\' or '/') or nil
|
||||||
local dot_split = split(basename, '%.')
|
local dot_split = split(basename, '%.')
|
||||||
return {
|
return {
|
||||||
path = path:sub(-1) == ':' and state.os == 'windows' and path..'\\' or path,
|
path = path:sub(-1) == ':' and state.os == 'windows' and path..'\\' or path,
|
||||||
dirname = dirname and state.os == 'windows' and dirname:sub(-1) == ':' and dirname..'\\' or dirname,
|
is_root = dirname == nil,
|
||||||
|
dirname = dirname,
|
||||||
basename = basename,
|
basename = basename,
|
||||||
filename = #dot_split > 1 and table.concat(itable_slice(dot_split, 1, #dot_split - 1), '.') or basename,
|
filename = #dot_split > 1 and table.concat(itable_slice(dot_split, 1, #dot_split - 1), '.') or basename,
|
||||||
extension = #dot_split > 1 and dot_split[#dot_split] or nil,
|
extension = #dot_split > 1 and dot_split[#dot_split] or nil,
|
||||||
@@ -1638,11 +1640,11 @@ function render_window_controls(this)
|
|||||||
-- Window title
|
-- Window title
|
||||||
if options.title and state.media_title then
|
if options.title and state.media_title then
|
||||||
local spacing = math.ceil(config.window_controls.height * 0.25)
|
local spacing = math.ceil(config.window_controls.height * 0.25)
|
||||||
local fontsize = math.floor(config.window_controls.height - (spacing * 2))
|
local font_size = math.floor(config.window_controls.height - (spacing * 2))
|
||||||
local clip_coordinates = '0,0,'..(minimize.ax - spacing)..','..config.window_controls.height
|
local clip_coordinates = '0,0,'..(minimize.ax - spacing)..','..config.window_controls.height
|
||||||
|
|
||||||
ass:new_event()
|
ass:new_event()
|
||||||
ass:append('{\\q2\\blur0\\bord0\\shad1\\1c&HFFFFFF\\4c&H000000\\fn'..config.font..'\\fs'..fontsize..'\\clip('..clip_coordinates..')')
|
ass:append('{\\q2\\blur0\\bord0\\shad1\\1c&HFFFFFF\\4c&H000000\\fn'..config.font..'\\fs'..font_size..'\\clip('..clip_coordinates..')')
|
||||||
ass:append(ass_opacity(1, opacity))
|
ass:append(ass_opacity(1, opacity))
|
||||||
ass:pos(0 + spacing, config.window_controls.height / 2)
|
ass:pos(0 + spacing, config.window_controls.height / 2)
|
||||||
ass:an(4)
|
ass:an(4)
|
||||||
@@ -2700,7 +2702,7 @@ function create_navigate_directory(direction)
|
|||||||
return function()
|
return function()
|
||||||
local path = mp.get_property_native("path")
|
local path = mp.get_property_native("path")
|
||||||
|
|
||||||
if is_protocol(path) then return end
|
if not path or is_protocol(path) then return end
|
||||||
|
|
||||||
local next_file = get_adjacent_file(path, direction, options.media_types)
|
local next_file = get_adjacent_file(path, direction, options.media_types)
|
||||||
|
|
||||||
@@ -2714,7 +2716,7 @@ function create_select_adjacent_media_file_index(index)
|
|||||||
return function()
|
return function()
|
||||||
local path = mp.get_property_native("path")
|
local path = mp.get_property_native("path")
|
||||||
|
|
||||||
if is_protocol(path) then return end
|
if not path or is_protocol(path) then return end
|
||||||
|
|
||||||
local dirname = serialize_path(path).dirname
|
local dirname = serialize_path(path).dirname
|
||||||
local files = get_files_in_directory(dirname, options.media_types)
|
local files = get_files_in_directory(dirname, options.media_types)
|
||||||
@@ -2976,7 +2978,7 @@ mp.add_key_binding(nil, 'context-menu', function()
|
|||||||
end)
|
end)
|
||||||
mp.add_key_binding(nil, 'load-subtitles', function()
|
mp.add_key_binding(nil, 'load-subtitles', function()
|
||||||
local path = mp.get_property_native('path')
|
local path = mp.get_property_native('path')
|
||||||
if not is_protocol(path) then
|
if path and not is_protocol(path) then
|
||||||
open_file_navigation_menu(
|
open_file_navigation_menu(
|
||||||
serialize_path(path).dirname,
|
serialize_path(path).dirname,
|
||||||
function(path) mp.commandv('sub-add', path) end,
|
function(path) mp.commandv('sub-add', path) end,
|
||||||
@@ -3058,7 +3060,7 @@ mp.add_key_binding(nil, 'navigate-chapters', function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update selected chapter in chaper navigation menu
|
-- Update selected chapter in chapter navigation menu
|
||||||
function seek_handler()
|
function seek_handler()
|
||||||
if menu:is_open('navigate-chapters') then
|
if menu:is_open('navigate-chapters') then
|
||||||
elements.menu:activate_index(get_selected_chapter_index())
|
elements.menu:activate_index(get_selected_chapter_index())
|
||||||
@@ -3079,7 +3081,7 @@ mp.add_key_binding(nil, 'show-in-directory', function()
|
|||||||
local path = mp.get_property_native('path')
|
local path = mp.get_property_native('path')
|
||||||
|
|
||||||
-- Ignore URLs
|
-- Ignore URLs
|
||||||
if is_protocol(path) then return end
|
if not path or is_protocol(path) then return end
|
||||||
|
|
||||||
path = normalize_path(path)
|
path = normalize_path(path)
|
||||||
|
|
||||||
@@ -3096,31 +3098,41 @@ mp.add_key_binding(nil, 'show-in-directory', function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
mp.add_key_binding(nil, 'navigate-directory', function()
|
mp.add_key_binding(nil, 'open-file', function()
|
||||||
local path = mp.get_property_native('path')
|
local path = mp.get_property_native('path')
|
||||||
if not is_protocol(path) then
|
local directory
|
||||||
-- Update selected file in directory navigation menu
|
local active_file
|
||||||
function handle_file_loaded()
|
|
||||||
if menu:is_open('navigate-directory') then
|
|
||||||
local path = normalize_path(mp.get_property_native('path'))
|
|
||||||
elements.menu:activate_value(path)
|
|
||||||
elements.menu:select_value(path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
path = serialize_path(path)
|
if path == nil or is_protocol(path) then
|
||||||
open_file_navigation_menu(
|
local path = serialize_path(mp.command_native({'expand-path', '~/'}))
|
||||||
path.dirname,
|
directory = path.path
|
||||||
function(path) mp.commandv('loadfile', path) end,
|
active_file = nil
|
||||||
{
|
else
|
||||||
type = 'navigate-directory',
|
local path = serialize_path(path)
|
||||||
allowed_types = options.media_types,
|
directory = path.dirname
|
||||||
active_path = path.path,
|
active_file = path.path
|
||||||
on_open = function() mp.register_event('file-loaded', handle_file_loaded) end,
|
|
||||||
on_close = function() mp.unregister_event(handle_file_loaded) end,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Update selected file in directory navigation menu
|
||||||
|
function handle_file_loaded()
|
||||||
|
if menu:is_open('open-file') then
|
||||||
|
local path = normalize_path(mp.get_property_native('path'))
|
||||||
|
elements.menu:activate_value(path)
|
||||||
|
elements.menu:select_value(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
open_file_navigation_menu(
|
||||||
|
directory,
|
||||||
|
function(path) mp.commandv('loadfile', path) end,
|
||||||
|
{
|
||||||
|
type = 'open-file',
|
||||||
|
allowed_types = options.media_types,
|
||||||
|
active_path = active_file,
|
||||||
|
on_open = function() mp.register_event('file-loaded', handle_file_loaded) end,
|
||||||
|
on_close = function() mp.unregister_event(handle_file_loaded) end,
|
||||||
|
}
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
mp.add_key_binding(nil, 'next-file', create_navigate_directory('forward'))
|
mp.add_key_binding(nil, 'next-file', create_navigate_directory('forward'))
|
||||||
mp.add_key_binding(nil, 'prev-file', create_navigate_directory('backward'))
|
mp.add_key_binding(nil, 'prev-file', create_navigate_directory('backward'))
|
||||||
@@ -3129,7 +3141,7 @@ mp.add_key_binding(nil, 'last-file', create_select_adjacent_media_file_index(-1)
|
|||||||
mp.add_key_binding(nil, 'delete-file-next', function()
|
mp.add_key_binding(nil, 'delete-file-next', function()
|
||||||
local path = mp.get_property_native('path')
|
local path = mp.get_property_native('path')
|
||||||
|
|
||||||
if is_protocol(path) then return end
|
if not path or is_protocol(path) then return end
|
||||||
|
|
||||||
path = normalize_path(path)
|
path = normalize_path(path)
|
||||||
local playlist_count = mp.get_property_native('playlist-count')
|
local playlist_count = mp.get_property_native('playlist-count')
|
||||||
@@ -3139,7 +3151,7 @@ mp.add_key_binding(nil, 'delete-file-next', function()
|
|||||||
else
|
else
|
||||||
local next_file = get_adjacent_file(path, 'forward', options.media_types)
|
local next_file = get_adjacent_file(path, 'forward', options.media_types)
|
||||||
|
|
||||||
if menu:is_open('navigate-directory') then
|
if menu:is_open('open-file') then
|
||||||
elements.menu:delete_value(path)
|
elements.menu:delete_value(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -3154,7 +3166,7 @@ mp.add_key_binding(nil, 'delete-file-next', function()
|
|||||||
end)
|
end)
|
||||||
mp.add_key_binding(nil, 'delete-file-quit', function()
|
mp.add_key_binding(nil, 'delete-file-quit', function()
|
||||||
local path = mp.get_property_native('path')
|
local path = mp.get_property_native('path')
|
||||||
if is_protocol(path) then return end
|
if not path or is_protocol(path) then return end
|
||||||
os.remove(normalize_path(path))
|
os.remove(normalize_path(path))
|
||||||
mp.command('quit')
|
mp.command('quit')
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user