This commit is contained in:
Frank Skare
2021-06-22 19:10:27 +02:00
parent 6634ef094c
commit bac8b2b96c
15 changed files with 363 additions and 271 deletions

View File

@@ -9,6 +9,7 @@ using System.Windows.Interop;
using System.Windows;
using static mpvnet.Global;
using System.Collections.Generic;
namespace mpvnet
{
@@ -44,7 +45,7 @@ namespace mpvnet
case "show-keys": ShowTextWithEditor("input-key-list", Core.get_property_string("input-key-list").Replace(",", BR)); break;
case "show-media-info": ShowMediaInfo(args); break;
case "show-media-search": ShowDialog(typeof(EverythingWindow)); break;
case "show-playlist": ShowPlaylist(args); break;
case "show-playlist": ShowPlaylist(); break;
case "show-profiles": ShowTextWithEditor("profile-list", mpvHelp.GetProfiles()); break;
case "show-properties": ShowProperties(); break;
case "show-protocols": ShowTextWithEditor("protocol-list", mpvHelp.GetProtocols()); break;
@@ -360,23 +361,6 @@ namespace mpvnet
"}${osd-ass-cc/1}" + text + "\" " + duration);
}
public static void ShowPlaylist(string[] args)
{
int duration = 5000;
if (args.Length == 1 && int.TryParse(args[0], out int result))
duration = result;
var size = Core.get_property_number("osd-font-size");
Core.set_property_number("osd-font-size", 40);
Core.command("show-text ${playlist} " + duration);
App.RunTask(() => {
Thread.Sleep(6000);
Core.set_property_number("osd-font-size", size);
});
}
public static void ShowMediaInfo(string[] args)
{
string path = Core.GetPropertyString("path");
@@ -393,9 +377,38 @@ namespace mpvnet
}
}
public static void ShowCommandPalette()
{
public static void ShowCommandPalette() => App.InvokeOnMainThread(ShowCommandPaletteInternal);
static void ShowCommandPaletteInternal()
{
CommandPalette.Instance.SetItems(CommandPalette.GetItems());
MainForm.Instance.ShowCommandPalette();
}
public static void ShowPlaylist() => App.InvokeOnMainThread(ShowPlaylistInternal);
static void ShowPlaylistInternal()
{
int count = Core.get_property_int("playlist-count");
if (count <= 0)
return;
List<CommandPaletteItem> items = new List<CommandPaletteItem>();
for (int i = 0; i < count; i++)
{
int index = i;
string file = Core.get_property_string($"playlist/{i}/filename");
CommandPaletteItem item = new CommandPaletteItem() {
Text = PathHelp.GetFileName(file),
Action = () => Core.set_property_int("playlist-pos", index)
};
items.Add(item);
}
CommandPalette.Instance.SetItems(items);
MainForm.Instance.ShowCommandPalette();
}
}
}

View File

@@ -14,6 +14,20 @@ 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)

View File

@@ -228,4 +228,21 @@ namespace mpvnet
}
}
}
public class CommandPaletteItem
{
public string Text { get; set; } = "";
public string SecondaryText { get; set; } = "";
public Action Action { get; set; }
}
public class CommandPalette
{
public static CommandPaletteControl Instance { get; } = new CommandPaletteControl();
public static IEnumerable<CommandPaletteItem> GetItems()
{
return CommandItem.Items.Select(i => new CommandPaletteItem() { Text = i.Display, SecondaryText = i.Input });
}
}
}