work on menu and bindings

This commit is contained in:
stax76
2023-11-04 20:24:10 +01:00
parent b41ca3cd89
commit 1d3fe0a924
11 changed files with 195 additions and 82 deletions

View File

@@ -5,17 +5,17 @@ namespace MpvNet;
public class Binding : ObservableObject
{
public string Path { get; set; }
public string Command { get; set; }
public string Comment { get; set; }
public bool IsCustomMenu { get; set; }
public bool IsMenu { get; set; }
string _input = "";
public Binding()
{
Path = Command = Comment = Input = "";
Command = Comment = Input = "";
}
public Binding(string folder = "",
@@ -26,20 +26,19 @@ public class Binding : ObservableObject
{
if (folder != "" && name != "")
{
Path = folder + " > " + name;
Comment = folder + " > " + name;
IsMenu = true;
}
else if (name != "")
{
Path = name;
Comment = name;
IsMenu = true;
}
else
Path = "";
Comment = comment;
Command = command;
Input = input;
Comment = comment == "" ? Path : comment;
}
public string Input
@@ -48,5 +47,5 @@ public class Binding : ObservableObject
set => SetProperty(ref _input, value);
}
public bool IsEmpty() => Path == "" && Command == "" && Comment == "" && Input == "";
public bool IsEmpty() => Command == "" && Comment == "" && Input == "";
}

View File

@@ -1,4 +1,5 @@

using MpvNet.ExtensionMethod;
using MpvNet.Help;
namespace MpvNet;
@@ -20,12 +21,12 @@ public class InputConf
public bool HasMenu => _hasMenu ??= Content.Contains("#menu:");
public List<Binding> GetMenuBindings()
public (List<Binding> menuBindings, List<Binding>? confBindings) GetBindings()
{
var confbindings = InputHelp.Parse(Content);
if (HasMenu)
return confbindings;
return (confbindings, confbindings);
var defaultBindings = InputHelp.GetDefaults();
@@ -42,7 +43,7 @@ public class InputConf
if (defaultBinding.Command == confBinding.Command)
defaultBinding.Input = confBinding.Input;
return defaultBindings;
return (defaultBindings, confbindings);
}
public string GetContent()
@@ -71,4 +72,15 @@ public class InputConf
return InputHelp.ConvertToString(defaults);
}
}
public void CreateBackup()
{
if (!File.Exists(Path))
return;
string targetPath = System.IO.Path.GetTempPath().AddSep() +
"mpv.net input.conf backup " + Guid.NewGuid() + ".conf";
File.Copy(Path, targetPath);
}
}

View File

@@ -126,6 +126,7 @@ public static class InputHelp
new (_("View > Advanced"), _("Show Commands"), "script-message-to mpvnet show-commands", "C"),
new (_("View > Advanced"), _("Show Demuxers"), "script-message-to mpvnet show-demuxers"),
new (_("View > Advanced"), _("Show Decoders"), "script-message-to mpvnet show-decoders"),
new (_("View > Advanced"), _("Show Bindings"), "script-message-to mpvnet show-bindings"),
new ("", _("Profile")),
new (_("Settings"), _("Show Config Editor"), "script-message-to mpvnet show-conf-editor", "Ctrl+,"),
new (_("Settings"), _("Show Input Editor"), "script-message-to mpvnet show-input-editor", "Ctrl+i"),
@@ -141,6 +142,7 @@ public static class InputHelp
new (_("Tools"), _("Exit"), "quit", "Esc"),
new (_("Tools"), _("Exit Watch Later"), "quit-watch-later", "Q"),
new (_("Tools"), _("Show current file in File Explorer"), @"run powershell -command ""explorer.exe '/select,' ( \""${path}\"" -replace '/', '\\' )""", "e"),
new ("", _("Custom")),
new (_("Help"), _("Website mpv"), "script-message-to mpvnet shell-execute https://mpv.io"),
new (_("Help"), _("Website mpv.net"), "script-message-to mpvnet shell-execute https://github.com/mpvnet-player/mpv.net"),
new (_("Help"), "-"),
@@ -204,7 +206,7 @@ public static class InputHelp
if (binding.Comment != "" &&
binding.Command == "" &&
binding.Input == "" &&
binding.Path == "")
!binding.IsMenu)
{
sb.AppendLine("#" + binding.Comment.Trim());
continue;
@@ -212,13 +214,28 @@ public static class InputHelp
string command = binding.Command.Trim();
string input = binding.Input.Trim();
string comment = binding.IsMenu ? "menu: " + binding.Path : binding.Path.Trim();
input = input == "" ? "_" : input;
string line = input.PadRight(10) + " ";
line += command == "" ? "ignore" : command;
string comment;
if (binding.IsMenu)
comment = "menu: " + binding.Comment.Trim();
else if (binding.IsCustomMenu)
comment = "custom-menu: " + binding.Comment.Trim();
else
comment = binding.Comment.Trim();
if (comment != "")
line = line.PadRight(40) + " #" + comment;
{
if (comment.StartsWith("menu: ") || comment.StartsWith("custom-menu: "))
comment = " #" + comment;
else
comment = " # " + comment;
line = line.PadRight(40) + comment;
}
sb.AppendLine(line);
}
@@ -276,17 +293,25 @@ public static class InputHelp
if (line.Contains("#menu:"))
{
binding.Path = line[(line.IndexOf("#menu:") + 6)..].Trim();
binding.Comment = binding.Path;
binding.Comment = line[(line.IndexOf("#menu:") + 6)..].Trim();
binding.IsMenu = true;
line = line[..line.IndexOf("#menu:")];
if (binding.Path.Contains(';'))
binding.Path = binding.Path[(binding.Path.IndexOf(";") + 1)..].Trim();
}
//else if (line.Contains("#!"))
//{
// binding.Comment = line[(line.IndexOf("#!") + 2)..].Trim();
// binding.IsMenu = true;
// line = line[..line.IndexOf("#!")];
//}
else if (line.Contains("#custom-menu:"))
{
binding.Comment = line[(line.IndexOf("#custom-menu:") + 13)..].Trim();
binding.IsCustomMenu = true;
line = line[..line.IndexOf("#custom-menu:")];
}
else if (line.Contains('#'))
{
binding.Path = line[(line.IndexOf("#") + 1)..].Trim();
binding.Comment = line[(line.IndexOf("#") + 1)..].Trim();
line = line[..line.IndexOf("#")];
}
@@ -378,11 +403,11 @@ public static class InputHelp
if (value.Contains("#menu:"))
{
binding.Path = value[(value.IndexOf("#menu:") + 6)..].Trim();
binding.Comment = value[(value.IndexOf("#menu:") + 6)..].Trim();
value = value[..value.IndexOf("#menu:")];
if (binding.Path.Contains(';'))
binding.Path = binding.Path[(binding.Path.IndexOf(";") + 1)..].Trim();
if (binding.Comment.Contains(';'))
binding.Comment = binding.Comment[(binding.Comment.IndexOf(";") + 1)..].Trim();
}
binding.Command = value.Trim();

View File

@@ -1,7 +1,6 @@

using System.Drawing;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
@@ -23,6 +22,7 @@ public class MainPlayer : MpvClient
public string GPUAPI { get; set; } = "auto";
public string Path { get; set; } = "";
public string VO { get; set; } = "gpu";
public string UsedInputConfContent { get; set; } = "";
public string VID { get; set; } = "";
public string AID { get; set; } = "";
@@ -101,8 +101,8 @@ public class MainPlayer : MpvClient
SetPropertyString("osc", "yes");
SetPropertyString("force-window", "yes");
SetPropertyString("config-dir", ConfigFolder);
SetPropertyString("config", "yes");
SetPropertyString("input-conf", @"memory://" + App.InputConf.GetContent());
SetPropertyString("config", "yes");
SetPropertyString("input-conf", @"memory://" + (UsedInputConfContent = App.InputConf.GetContent()));
ProcessCommandLine(true);