From 95a3403898644f5db0bb3c832b8fc3df3fe37e27 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sun, 8 Aug 2021 14:31:43 +0200 Subject: [PATCH] 5.4.9.2 Beta --- docs/Changelog.md | 5 ++++- src/Misc/Commands.cs | 43 ++++++++++++++++++++++-------------- src/Misc/CorePlayer.cs | 17 ++++++++++++++ src/Misc/ExtensionMethods.cs | 12 ++++++++++ src/Misc/Help.cs | 14 ------------ src/Resources/input.conf.txt | 1 + src/WinForms/MainForm.cs | 2 +- 7 files changed, 61 insertions(+), 33 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 5759155..4d6de2f 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,5 +1,5 @@ -5.4.9.2 Beta (2021-??-??) +5.4.9.2 Beta (2021-08-08) - Manual translated to simplified Chinese. (hooke007) - watch-later-options support added to conf editor. (hooke007) @@ -15,6 +15,9 @@ - Some scroll bars where replaced with Windows 10 styled scroll bars, complex code used from HandyControl project. - Some UI elements use rounded corners. +- The recent list can also be shown in the command palette: + Alt+r script-message mpv.net show-recent #menu: View > Show Recent +- The recent context menu removes the folder info in case of very long paths. - libmpv shinchiro 2021-08-01 diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index 50ded39..8420a79 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -3,7 +3,6 @@ using System; using System.Globalization; using System.IO; using System.Linq; -using System.Threading; using System.Windows.Forms; using System.Windows.Interop; using System.Windows; @@ -48,6 +47,7 @@ namespace mpvnet case "show-profiles": ShowTextWithEditor("profile-list", mpvHelp.GetProfiles()); break; case "show-properties": ShowProperties(); break; case "show-protocols": ShowTextWithEditor("protocol-list", mpvHelp.GetProtocols()); break; + case "show-recent": ShowRecent(); break; case "show-setup-dialog": ShowDialog(typeof(SetupWindow)); break; case "show-text": ShowText(args[0], Convert.ToInt32(args[1]), Convert.ToInt32(args[2])); break; case "update-check": UpdateCheck.CheckOnline(true); break; @@ -93,21 +93,7 @@ namespace mpvnet dialog.ShowNewFolderButton = false; if (dialog.ShowDialog() == DialogResult.OK) - { - Core.Command("stop"); - Thread.Sleep(500); - - if (Directory.Exists(dialog.SelectedPath + "\\BDMV")) - { - Core.SetPropertyString("bluray-device", dialog.SelectedPath); - Core.LoadFiles(new[] { @"bd://" }, false, false); - } - else - { - Core.SetPropertyString("dvd-device", dialog.SelectedPath); - Core.LoadFiles(new[] { @"dvd://" }, false, false); - } - } + Core.LoadDiskFolder(dialog.SelectedPath); } })); } @@ -398,7 +384,7 @@ namespace mpvnet string file = Core.GetPropertyString($"playlist/{i}/filename"); CommandPaletteItem item = new CommandPaletteItem() { - Text = PathHelp.GetFileName(file), + Text = file.FileName(), Action = () => Core.SetPropertyInt("playlist-pos", index) }; @@ -451,5 +437,28 @@ namespace mpvnet CommandPalette.Instance.SetItems(items); MainForm.Instance.ShowCommandPalette(); } + + public static void ShowRecent() => App.InvokeOnMainThread(ShowRecentInternal); + + public static void ShowRecentInternal() + { + List items = new List(); + + foreach (string i in App.Settings.RecentFiles) + { + string file = i; + + CommandPaletteItem item = new CommandPaletteItem() + { + Text = file.ShortPath(60), + Action = () => Core.LoadFiles(new[] { file }, true, Control.ModifierKeys.HasFlag(Keys.Control)) + }; + + items.Add(item); + } + + CommandPalette.Instance.SetItems(items); + MainForm.Instance.ShowCommandPalette(); + } } } diff --git a/src/Misc/CorePlayer.cs b/src/Misc/CorePlayer.cs index f12b7ec..8c36d11 100644 --- a/src/Misc/CorePlayer.cs +++ b/src/Misc/CorePlayer.cs @@ -1189,6 +1189,23 @@ namespace mpvnet } } + public void LoadDiskFolder(string path) + { + Core.Command("stop"); + Thread.Sleep(500); + + if (Directory.Exists(path + "\\BDMV")) + { + Core.SetPropertyString("bluray-device", path); + Core.LoadFiles(new[] { @"bd://" }, false, false); + } + else + { + Core.SetPropertyString("dvd-device", path); + Core.LoadFiles(new[] { @"dvd://" }, false, false); + } + } + public void LoadFolder() { if (!App.AutoLoadFolder || Control.ModifierKeys.HasFlag(Keys.Shift)) diff --git a/src/Misc/ExtensionMethods.cs b/src/Misc/ExtensionMethods.cs index 2b0468a..6c43cc6 100644 --- a/src/Misc/ExtensionMethods.cs +++ b/src/Misc/ExtensionMethods.cs @@ -1,6 +1,7 @@  using System.Globalization; using System.IO; +using System.Text.RegularExpressions; public static class TestStringExtension { @@ -94,6 +95,17 @@ public static class PathStringExtension return instance; } + public static string ShortPath(this string instance, int maxLength) + { + if (string.IsNullOrEmpty(instance)) + return ""; + + if (instance.Length > maxLength && instance.Substring(1, 2) == ":\\") + instance = instance.Substring(0, 3) + "...\\" + instance.FileName(); + + return instance; + } + // Ensure trailing directory separator char public static string AddSep(this string instance) { diff --git a/src/Misc/Help.cs b/src/Misc/Help.cs index 2b66c64..2053c96 100644 --- a/src/Misc/Help.cs +++ b/src/Misc/Help.cs @@ -14,20 +14,6 @@ using static mpvnet.Global; namespace mpvnet { - public static class PathHelp - { - public static string GetFileName(string path) - { - if (string.IsNullOrEmpty(path)) - return ""; - - if (path.Contains(Path.DirectorySeparatorChar)) - return path.Substring(path.LastIndexOf(Path.DirectorySeparatorChar) + 1); - - return path; - } - } - public static class StringHelp { public static string GetMD5Hash(string txt) diff --git a/src/Resources/input.conf.txt b/src/Resources/input.conf.txt index e5f4f0d..c055f41 100644 --- a/src/Resources/input.conf.txt +++ b/src/Resources/input.conf.txt @@ -157,6 +157,7 @@ P script-message mpv.net show-properties #menu: View > Show Propertie _ script-message mpv.net show-protocols #menu: View > Show Protocols F9 show-text ${track-list} 5000 #menu: View > Show Tracks Ctrl+m script-message mpv.net show-media-info #menu: View > Show Media Info +Alt+r script-message mpv.net show-recent #menu: View > Show Recent _ ignore #menu: Profile diff --git a/src/WinForms/MainForm.cs b/src/WinForms/MainForm.cs index 48fb5b5..e522dab 100644 --- a/src/WinForms/MainForm.cs +++ b/src/WinForms/MainForm.cs @@ -270,7 +270,7 @@ namespace mpvnet recent.DropDownItems.Clear(); foreach (string path in App.Settings.RecentFiles) - MenuItem.Add(recent.DropDownItems, path, () => Core.LoadFiles(new[] { path }, true, Control.ModifierKeys.HasFlag(Keys.Control))); + MenuItem.Add(recent.DropDownItems, path.ShortPath(100), () => Core.LoadFiles(new[] { path }, true, ModifierKeys.HasFlag(Keys.Control))); recent.DropDownItems.Add(new ToolStripSeparator()); MenuItem mi = new MenuItem("Clear List");