Skip to content

Commit a0d2fb6

Browse files
committed
command palette support
1 parent 59a5567 commit a0d2fb6

File tree

4 files changed

+307
-224
lines changed

4 files changed

+307
-224
lines changed

docs/changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

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

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

src/MpvNet.Windows/GuiCommand.cs

+53
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using MpvNet.Windows.WPF.MsgBox;
1515
using MpvNet.Windows.Help;
1616
using MpvNet.Help;
17+
using System.Windows.Documents;
1718

1819
namespace MpvNet;
1920

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

6063

6164
// deprecated
@@ -267,6 +270,56 @@ void RegisterFileAssociations(IList<string> args)
267270
catch { }
268271
}
269272

273+
void InstallCommandPalette()
274+
{
275+
if (Msg.ShowQuestion("Install command palette?") != MessageBoxResult.OK)
276+
return;
277+
278+
try
279+
{
280+
Environment.SetEnvironmentVariable("MPVNET_HOME", Player.ConfigFolder);
281+
using Process proc = new Process();
282+
proc.StartInfo.FileName = "powershell";
283+
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\"";
284+
proc.Start();
285+
}
286+
catch
287+
{
288+
}
289+
}
290+
291+
void ShowRecentFilesInCommandPalette()
292+
{
293+
Obj o = new();
294+
o.title = "Recent Files";
295+
o.selected_index = 0;
296+
297+
var items = new List<Item>();
298+
299+
foreach (string file in App.Settings.RecentFiles)
300+
items.Add(new Item() { title = Path.GetFileName(file),
301+
value = new string []{ "loadfile", file },
302+
hint = file});
303+
304+
o.items = items.ToArray();
305+
string json = JsonSerializer.Serialize(o);
306+
Player.CommandV("script-message", "show-command-palette-json", json);
307+
}
308+
309+
public class Obj
310+
{
311+
public string title { get; set; } = "";
312+
public int selected_index { get; set; } = 0;
313+
public Item[] items { get; set; } = Array.Empty<Item>();
314+
}
315+
316+
public class Item
317+
{
318+
public string[] value { get; set; } = Array.Empty<string>();
319+
public string title { get; set; } = "";
320+
public string hint { get; set; } = "";
321+
}
322+
270323
void ShowMediaInfo(IList<string> args)
271324
{
272325
if (Player.PlaylistPos == -1)

src/MpvNet.Windows/Resources/editor_conf.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ name = image-exts
2525
file = mpv
2626
directory = General
2727
width = 500
28-
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.
28+
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
2929

3030
name = menu-syntax
3131
file = mpvnet
@@ -782,7 +782,7 @@ name = video-exts
782782
file = mpv
783783
directory = Video
784784
width = 500
785-
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.
785+
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
786786

787787
name = volume
788788
file = mpv
@@ -831,7 +831,7 @@ name = audio-exts
831831
file = mpv
832832
directory = Audio
833833
width = 500
834-
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.
834+
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
835835

836836
name = slang
837837
file = mpv

0 commit comments

Comments
 (0)