Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect linux and run yad #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion open-file-dialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@

utils = require 'mp.utils'

function open_file_dialog()
function is_windows()
local windir = os.getenv("windir")
if windir~=nil then
return true
else
return false
end
end

function open_file_dialog_windows()
local was_ontop = mp.get_property_native("ontop")
if was_ontop then mp.set_property_native("ontop", false) end
local res = utils.subprocess({
Expand Down Expand Up @@ -42,4 +51,26 @@ function open_file_dialog()
end
end

function open_file_dialog_linux()
local was_ontop = mp.get_property_native("ontop")
if was_ontop then mp.set_property_native("ontop", false) end
local res = utils.subprocess({ args = {"yad", "--file"}, capture_stdout='yes', capture_stderr='yes', cancellable = false, })
if was_ontop then mp.set_property_native("ontop", true) end
if (res.status ~= 0) then print("bad return code") return end

local first_file = true
for filename in string.gmatch(res.stdout, '[^\n]+') do
mp.commandv('loadfile', filename, first_file and 'replace' or 'append')
first_file = false
end
end

function open_file_dialog()
if is_windows() then
open_file_dialog_windows()
else
open_file_dialog_linux()
end
end

mp.add_key_binding('ctrl+o', 'open-file-dialog', open_file_dialog)