From 8c02bb59ee6a15f1cc2f887ea5552a9010decbb0 Mon Sep 17 00:00:00 2001 From: stax76 Date: Sat, 12 Mar 2022 21:27:07 +0100 Subject: [PATCH] Media Info is shown using command palette --- docs/Changelog.md | 3 ++ src/Misc/Commands.cs | 47 ++++++++++++++++++++------- src/Misc/Misc.cs | 8 +++++ src/WPF/CommandPaletteControl.xaml.cs | 17 +++++++--- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 849bcb8..2e970cf 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -4,6 +4,9 @@ - Fix opening zip files. - The list of available input commands is like before shown by the text editor, so it's like everything else searchable. +- Media Info isn't shown directly, instead the command palette + shows several choices. The command palette can be bypassed + using the arguments: textbox, editor, full, raw 5.7.0.0 Stable (2022-03-09) diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index 69cab37..b5687ac 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -344,16 +344,16 @@ namespace mpvnet public static void ShowCommands() { - string json = Core.GetPropertyString("command-list"); - var o = json.FromJson>>().OrderBy(i => i["name"]); + string jsonString = Core.GetPropertyString("command-list"); + var jsonObject = jsonString.FromJson>>().OrderBy(i => i["name"]); StringBuilder sb = new StringBuilder(); - foreach (Dictionary i in o) + foreach (Dictionary dic in jsonObject) { sb.AppendLine(); - sb.AppendLine(i["name"].ToString()); + sb.AppendLine(dic["name"].ToString()); - foreach (Dictionary i2 in i["args"] as List) + foreach (Dictionary i2 in dic["args"] as List) { string value = i2["name"].ToString() + " <" + i2["type"].ToString().ToLower() + ">"; @@ -386,8 +386,23 @@ namespace mpvnet "}${osd-ass-cc/1}" + text + "\" " + duration); } - public static void ShowMediaInfo(string[] args) + public static void ShowMediaInfo(string[] args) => App.InvokeOnMainThread(() => { + if (args == null || args.Length == 0) + { + (string Name, string Value)[] pairs = { + ("Show text box", "script-message mpv.net show-media-info default"), + ("Show text editor", "script-message mpv.net show-media-info editor"), + ("Show full", "script-message mpv.net show-media-info editor full"), + ("Show raw", "script-message mpv.net show-media-info editor full raw") }; + + var list = pairs.Select(i => new CommandPaletteItem(i.Name, () => Core.Command(i.Value))); + CommandPalette.Instance.SetItems(list); + MainForm.Instance.ShowCommandPalette(); + CommandPalette.Instance.SelectFirst(); + return; + } + string path = Core.GetPropertyString("path"); if (File.Exists(path) && !path.Contains(@"\\.\pipe\")) @@ -396,14 +411,22 @@ namespace mpvnet { bool full = args.Contains("full"); bool raw = args.Contains("raw"); + bool editor = args.Contains("editor"); + string text = mediaInfo.GetSummary(full, raw); text = Regex.Replace(text, "Unique ID.+", ""); - MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Consolas"); - Msg.ShowInfo(text); - MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Segoe UI"); + + if (editor) + ShowTextWithEditor("media-info", text); + else + { + MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Consolas"); + Msg.ShowInfo(text); + MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Segoe UI"); + } } } - } + }); public static void ShowCommandPalette() => App.InvokeOnMainThread(() => { @@ -636,13 +659,13 @@ namespace mpvnet public static void ShowSetupDialog() => App.InvokeOnMainThread(() => { - (string, string)[] pairs = { + (string Name, string Value)[] pairs = { ("Register video file associations", "script-message mpv.net reg-file-assoc video"), ("Register audio file associations", "script-message mpv.net reg-file-assoc audio"), ("Register image file associations", "script-message mpv.net reg-file-assoc image"), ("Unregister file associations", "script-message mpv.net reg-file-assoc unreg") }; - var list = pairs.Select(i => new CommandPaletteItem(i.Item1, () => Core.Command(i.Item2))); + var list = pairs.Select(i => new CommandPaletteItem(i.Name, () => Core.Command(i.Value))); CommandPalette.Instance.SetItems(list); MainForm.Instance.ShowCommandPalette(); CommandPalette.Instance.SelectFirst(); diff --git a/src/Misc/Misc.cs b/src/Misc/Misc.cs index 759a839..6349b8c 100644 --- a/src/Misc/Misc.cs +++ b/src/Misc/Misc.cs @@ -166,6 +166,14 @@ namespace mpvnet } } + public string Alias { + get { + if (Input.Contains("SHARP") || Input.Contains("sharp") || Input.Contains("Sharp")) + return "#"; + return null; + } + } + public static ObservableCollection GetItems(string content) { var items = new ObservableCollection(); diff --git a/src/WPF/CommandPaletteControl.xaml.cs b/src/WPF/CommandPaletteControl.xaml.cs index a253bab..ce4dc61 100644 --- a/src/WPF/CommandPaletteControl.xaml.cs +++ b/src/WPF/CommandPaletteControl.xaml.cs @@ -90,10 +90,19 @@ namespace mpvnet { string filter = SearchControl.SearchTextBox.Text.ToLower(); - if (filter.Length == 1 && item.CommandItem != null) - return item.CommandItem.Input.ToLower().Replace("ctrl+", "") - .Replace("shift+", "") - .Replace("alt+", "") == filter.ToLower(); + if (item.CommandItem != null) + { + if (item.CommandItem.Alias.ContainsEx(filter)) + return true; + + if (filter.Length == 1) + return item.CommandItem.Input.ToLower().Replace("ctrl+", "") + .Replace("shift+", "") + .Replace("alt+", "") == filter.ToLower(); + + if (item.CommandItem.Command.ToLower().Contains(filter)) + return true; + } if (filter == "" || item.Text.ToLower().Contains(filter) || item.SecondaryText.ToLower().Contains(filter))