Skip to content

Commit

Permalink
command palette support
Browse files Browse the repository at this point in the history
  • Loading branch information
stax76 committed Oct 13, 2024
1 parent 59a5567 commit a0d2fb6
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 224 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

- Support for autocreate-playlist, video-exts, audio-exts, image-exts.
Windows 7 support should still work, but needs auto-load-folder to be enabled.
- The command palette user script is installable from the context menu under
`Settings > Setup > Install Command Palette`. The command palette features
are shown in the menu under 'View > Command Palette'.


# v7.1.1.2 Beta (2024-10-10)

Expand Down
53 changes: 53 additions & 0 deletions src/MpvNet.Windows/GuiCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using MpvNet.Windows.WPF.MsgBox;
using MpvNet.Windows.Help;
using MpvNet.Help;
using System.Windows.Documents;

namespace MpvNet;

Expand Down Expand Up @@ -56,6 +57,8 @@ public class GuiCommand
["show-properties"] = args => Player.Command("script-binding select/show-properties"),
["show-protocols"] = args => ShowProtocols(),
["window-scale"] = args => WindowScaleNet?.Invoke(float.Parse(args[0], CultureInfo.InvariantCulture)),
["install-command-palette"] = args => InstallCommandPalette(),
["show-recent-in-command-palette"] = args => ShowRecentFilesInCommandPalette(),


// deprecated
Expand Down Expand Up @@ -267,6 +270,56 @@ void RegisterFileAssociations(IList<string> args)
catch { }
}

void InstallCommandPalette()
{
if (Msg.ShowQuestion("Install command palette?") != MessageBoxResult.OK)
return;

try
{
Environment.SetEnvironmentVariable("MPVNET_HOME", Player.ConfigFolder);
using Process proc = new Process();
proc.StartInfo.FileName = "powershell";
proc.StartInfo.Arguments = "-executionpolicy bypass -nologo -noexit -noprofile -command \"irm https://raw.githubusercontent.com/stax76/mpv-scripts/refs/heads/main/powershell/command_palette_installer.ps1 | iex\"";
proc.Start();
}
catch
{
}
}

void ShowRecentFilesInCommandPalette()
{
Obj o = new();
o.title = "Recent Files";
o.selected_index = 0;

var items = new List<Item>();

foreach (string file in App.Settings.RecentFiles)
items.Add(new Item() { title = Path.GetFileName(file),
value = new string []{ "loadfile", file },
hint = file});

o.items = items.ToArray();
string json = JsonSerializer.Serialize(o);
Player.CommandV("script-message", "show-command-palette-json", json);
}

public class Obj
{
public string title { get; set; } = "";
public int selected_index { get; set; } = 0;
public Item[] items { get; set; } = Array.Empty<Item>();
}

public class Item
{
public string[] value { get; set; } = Array.Empty<string>();
public string title { get; set; } = "";
public string hint { get; set; } = "";
}

void ShowMediaInfo(IList<string> args)
{
if (Player.PlaylistPos == -1)
Expand Down
6 changes: 3 additions & 3 deletions src/MpvNet.Windows/Resources/editor_conf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ name = image-exts
file = mpv
directory = General
width = 500
help = Image file extentions to try to match when using --cover-art-auto, --autocreate-playlist or --directory-filter-types. By mpv.net used to create file associations and used by the auto-load-folder feature.
help = Image file extentions to try to match when using --cover-art-auto, --autocreate-playlist or --directory-filter-types. By mpv.net used to create file associations and used by the auto-load-folder feature. Default: avif,bmp,gif,j2k,jp2,jpeg,jpg,jxl,png,svg,tga,tif,tiff,webp

name = menu-syntax
file = mpvnet
Expand Down Expand Up @@ -782,7 +782,7 @@ name = video-exts
file = mpv
directory = Video
width = 500
help = Video file extentions to try to match when using --autocreate-playlist or --directory-filter-types. By mpv.net used to create file associations and used by the auto-load-folder feature.
help = Video file extentions to try to match when using --autocreate-playlist or --directory-filter-types. By mpv.net used to create file associations and used by the auto-load-folder feature. Default: 3g2,3gp,avi,flv,m2ts,m4v,mj2,mkv,mov,mp4,mpeg,mpg,ogv,rmvb,ts,webm,wmv,y4m

name = volume
file = mpv
Expand Down Expand Up @@ -831,7 +831,7 @@ name = audio-exts
file = mpv
directory = Audio
width = 500
help = Audio file extentions to try to match when using --audio-file-auto, --autocreate-playlist or --directory-filter-types. By mpv.net used to create file associations and used by the auto-load-folder feature.
help = Audio file extentions to try to match when using --audio-file-auto, --autocreate-playlist or --directory-filter-types. By mpv.net used to create file associations and used by the auto-load-folder feature. Default: aac,ac3,aiff,ape,au,dts,eac3,flac,m4a,mka,mp3,oga,ogg,ogm,opus,thd,wav,wav,wma,wv

name = slang
file = mpv
Expand Down
Loading

0 comments on commit a0d2fb6

Please sign in to comment.