Skip to content
New issue

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

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

Already on GitHub? # to your account

add dialog interface #38

Merged
merged 1 commit into from
Jan 20, 2024
Merged

add dialog interface #38

merged 1 commit into from
Jan 20, 2024

Conversation

tsl0922
Copy link
Owner

@tsl0922 tsl0922 commented Jan 19, 2024

Messages

  • clipboard/get <src>: get clipboard text
  • clipboard/set <text>: set clipboard text
  • dialog/open <src>: single file open dialog
  • dialog/open-multi <src>: multiple file open dialog
  • dialog/open-folder <src>: folder choosing dialog
  • dialog/save <src>: file save dialog

properties can be set to custom dialog behaviour:

  • user-data/menu/dialog/filters: custom file type filters, the first one will be default selected
  • user-data/menu/dialog/default-path: default path for open/save dialog
  • user-data/menu/dialog/default-name: default file name for save dialog

Example

dialog.lua

local file_types_prop = 'user-data/menu/dialog/filters'
local file_types = {
    { name = 'All Files (*.*)', spec = '*.*' },
    { name = 'Video Files',     spec = '*.mpeg4;*.m4v;*.mp4;*.mp4v;*.mpg4;*.h264;*.avc;*.x264;*.264;*.hevc;*.h265;*.x265;*.265;*.m2ts;*.m2t;*.mts;*.mtv;*.ts;*.tsv;*.tsa;*.tts;*.mpeg;*.mpg;*.mpe;*.mpeg2;*.m1v;*.m2v;*.mp2v;*.mkv;*.mk3d;*.wm;*.wmv;*.asf;*.vob;*.vro;*.evob;*.evo;*.ogv;*.ogm;*.ogx;*.webm;*.avi;*.vfw;*.divx;*.3iv;*.xvid;*.nut;*.flic;*.fli;*.flc;*.nsv;*.gxf;*.mxf;*.dvr-ms;*.dvr;*.wtv;*.dv;*.hdv;*.flv;*.f4v;*.qt;*.mov;*.hdmov;*.rm;*.rmvb;*.3gpp;*.3gp;*.3gp2;*.3g2;*.yuv;*.y4m' },
    { name = 'Audio Files',     spec = '*.mp3;*.m4a;*.aac;*.flac;*.ac3;*.a52;*.eac3;*.mpa;*.m1a;*.m2a;*.mp1;*.mp2;*.oga;*.ogg;*.wav;*.mlp;*.dts;*.dts-hd;*.dtshd;*.true-hd;*.thd;*.truehd;*.thd+ac3;*.tta;*.pcm;*.aiff;*.aif;*.aifc;*.amr;*.awb;*.au;*.snd;*.lpcm;*.ape;*.wv;*.shn;*.adts;*.adt;*.opus;*.spx;*.mka;*.weba;*.wma;*.f4a;*.ra;*.ram;*.3ga;*.3ga2;*.ay;*.gbs;*.gym;*.hes;*.kss;*.nsf;*.nsfe;*.sap;*.spc;*.vgm;*.vgz;*.m3u;*.m3u8;*.pls;*.cue' },
    { name = 'Image Files',     spec = '*.jpg;*.bmp;*.png;*.gif;*.webp' },
    { name = 'Subtitle Files',  spec = '*.srt;*.ass;*.idx;*.sub;*.sup;*.ttxt;*.txt;*.ssa;*.smi;*.mks' },
    { name = 'Playlist Files',  spec = '*.m3u;*.m3u8;*.pls;*.cue' },
}
mp.set_property_native(file_types_prop, file_types)

local function dialog_open_cb(...)
    for i, v in ipairs({ ... }) do
        local path = tostring(v)
        local option = i > 1 and 'append' or 'replace'
        mp.commandv('loadfile', path, option)
    end
end

mp.register_script_message('dialog-open-reply', dialog_open_cb)
mp.register_script_message('dialog-open-multi-reply', dialog_open_cb)
mp.register_script_message('dialog-open-folder-reply', dialog_open_cb)

mp.register_script_message('open', function()
    mp.commandv('script-message-to', 'menu', 'dialog/open-multi', mp.get_script_name())
end)

mp.register_script_message('open-folder', function()
    mp.commandv('script-message-to', 'menu', 'dialog/open-folder', mp.get_script_name())
end)

mp.register_script_message('clipboard-get-reply', function(clipboard)
    mp.commandv('loadfile', clipboard, 'append-play')
    mp.osd_message('clipboard: ' .. clipboard)
end)

mp.register_script_message('open-clipboard', function()
    mp.commandv('script-message-to', 'menu', 'clipboard/get', mp.get_script_name())
end)

input.conf

Ctrl+o      script-message-to dialog open            #menu: Open > Files...
Ctrl+O      script-message-to dialog open-folder     #menu: Open > Folder...
Ctrl+v      script-message-to dialog open-clipboard  #menu: Open > Clipboard

@tsl0922 tsl0922 force-pushed the dialog branch 3 times, most recently from 0dc13f7 to 9d19958 Compare January 20, 2024 07:05
@tsl0922 tsl0922 marked this pull request as ready for review January 20, 2024 07:36
@tsl0922 tsl0922 merged commit b394bec into main Jan 20, 2024
2 checks passed
@tsl0922 tsl0922 deleted the dialog branch January 20, 2024 08:05
@candrapersada
Copy link

candrapersada commented Jan 20, 2024

is there an option to use Add files/URLs to playlist from clipboard?

Open file dialog starts in current file directory, or user directory when file/folder not available.

@tsl0922
Copy link
Owner Author

tsl0922 commented Jan 21, 2024

is there an option to use Add files/URLs to playlist from clipboard?

You may add it yourself, it's pretty easy to implement it in lua.

Open file dialog starts in current file directory, or user directory when file/folder not available.

Well, Windows will remember the last dir you opened, I don't think it is necessary here.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants