From 765854cd10afa657e5ce81c3f42794eff3b3e6dd Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Fri, 28 May 2021 11:38:36 +0200 Subject: [PATCH] After using the config editor it's no longer necessary to restart mpv.net. --- docs/Changelog.md | 4 +- src/DynamicGUI/DynamicGUI.cs | 30 +++--- src/DynamicGUI/OptionSettingControl.xaml | 95 ++++++++++-------- src/DynamicGUI/OptionSettingControl.xaml.cs | 7 ++ src/DynamicGUI/StringSettingControl.xaml | 87 ++++++++-------- src/DynamicGUI/StringSettingControl.xaml.cs | 7 ++ .../RatingExtension/RatingExtension.cs | 4 +- src/Misc/App.cs | 20 +++- src/Misc/CSharpScriptHost.cs | 4 +- src/Misc/CorePlayer.cs | 6 +- src/Misc/Extension.cs | 8 +- src/Misc/Msg.cs | 4 +- src/Misc/Theme.cs | 18 ++-- src/Resources/input.conf.txt | 4 +- src/Scripts/C-Sharp/rate-file.cs | 12 +-- src/WPF/AboutWindow.xaml | 33 ++++--- src/WPF/AboutWindow.xaml.cs | 5 + src/WPF/CommandPaletteWindow.xaml | 66 +++++++------ src/WPF/CommandPaletteWindow.xaml.cs | 5 + src/WPF/ConfWindow.xaml | 70 +++++++------ src/WPF/ConfWindow.xaml.cs | 40 +++++++- src/WPF/EverythingWindow.xaml | 57 ++++++----- src/WPF/EverythingWindow.xaml.cs | 5 + src/WPF/InputWindow.xaml | 50 +++++----- src/WPF/InputWindow.xaml.cs | 12 ++- src/WPF/LearnWindow.xaml | 68 +++++++------ src/WPF/LearnWindow.xaml.cs | 10 +- src/WPF/Resources.xaml | 54 +++++----- src/WPF/SearchTextBoxUserControl.xaml | 99 +++++++++++-------- src/WPF/SearchTextBoxUserControl.xaml.cs | 12 ++- src/WPF/SetupWindow.xaml | 42 ++++---- src/WPF/SetupWindow.xaml.cs | 10 +- src/WPF/WPF.cs | 2 - src/WinForms/MainForm.cs | 10 -- src/WinForms/Menu.cs | 4 +- src/mpv.net.csproj | 1 + 36 files changed, 570 insertions(+), 395 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 7d3f2f9..bab8764 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -19,9 +19,9 @@ open source code however. Example scripts and extensions were updated. - Fix console not working due to incorrect mpv.conf value generated (script-opts=console-scale=0). -- Registry usage is not portable and also not popular, so settings - are stored in the file settings.xml now instead of the Registry. +- Settings are stored in the file settings.xml now instead of the Registry. - Video rotation support added. +- After using the config editor it's no longer necessary to restart mpv.net. 5.4.8.8 Beta (2021-05-09) diff --git a/src/DynamicGUI/DynamicGUI.cs b/src/DynamicGUI/DynamicGUI.cs index 55b57d9..5994094 100644 --- a/src/DynamicGUI/DynamicGUI.cs +++ b/src/DynamicGUI/DynamicGUI.cs @@ -1,14 +1,13 @@  -using mpvnet; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Windows; using System.Windows.Documents; using System.Windows.Navigation; using Tommy; +using mpvnet; namespace DynamicGUI { @@ -62,10 +61,10 @@ namespace DynamicGUI baseSetting.File = setting["file"]; baseSetting.Filter = setting["filter"]; - if (setting.HasKey("help")) baseSetting.Help = setting["help"]; - if (setting.HasKey("url")) baseSetting.URL = setting["url"]; + if (setting.HasKey("help")) baseSetting.Help = setting["help"]; + if (setting.HasKey("url")) baseSetting.URL = setting["url"]; if (setting.HasKey("width")) baseSetting.Width = setting["width"]; - if (setting.HasKey("type")) baseSetting.Type = setting["type"]; + if (setting.HasKey("type")) baseSetting.Type = setting["type"]; settingsList.Add(baseSetting); } @@ -75,26 +74,29 @@ namespace DynamicGUI public class ConfItem { - public string Name { get; set; } = ""; - public string Value { get; set; } = ""; public string Comment { get; set; } = ""; - public string LineComment { get; set; } = ""; - public string Section { get; set; } = ""; public string File { get; set; } = ""; + public string LineComment { get; set; } = ""; + public string Name { get; set; } = ""; + public string Section { get; set; } = ""; + public string Value { get; set; } = ""; + public bool IsSectionItem { get; set; } public SettingBase SettingBase { get; set; } } public abstract class SettingBase { - public string Name { get; set; } - public string File { get; set; } - public string Value { get; set; } - public string Help { get; set; } public string Default { get; set; } - public string URL { get; set; } + public string File { get; set; } public string Filter { get; set; } + public string Help { get; set; } + public string Name { get; set; } + public string StartValue { get; set; } public string Type { get; set; } + public string URL { get; set; } + public string Value { get; set; } + public int Width { get; set; } public ConfItem ConfItem { get; set; } } diff --git a/src/DynamicGUI/OptionSettingControl.xaml b/src/DynamicGUI/OptionSettingControl.xaml index 533e8a1..2a9a74f 100644 --- a/src/DynamicGUI/OptionSettingControl.xaml +++ b/src/DynamicGUI/OptionSettingControl.xaml @@ -1,61 +1,70 @@ - + - + - + - + - + + diff --git a/src/DynamicGUI/OptionSettingControl.xaml.cs b/src/DynamicGUI/OptionSettingControl.xaml.cs index 8ab2f1c..b5a408c 100644 --- a/src/DynamicGUI/OptionSettingControl.xaml.cs +++ b/src/DynamicGUI/OptionSettingControl.xaml.cs @@ -2,6 +2,8 @@ using System.Windows; using System.Windows.Controls; +using mpvnet; + namespace DynamicGUI { public partial class OptionSettingControl : UserControl, ISettingControl @@ -12,6 +14,7 @@ namespace DynamicGUI { OptionSetting = optionSetting; InitializeComponent(); + DataContext = this; TitleTextBox.Text = optionSetting.Name; if (string.IsNullOrEmpty(optionSetting.Help)) @@ -26,6 +29,10 @@ namespace DynamicGUI Link.SetURL(optionSetting.URL); } + public Theme Theme { + get => Theme.Current; + } + string _SearchableText; public string SearchableText { diff --git a/src/DynamicGUI/StringSettingControl.xaml b/src/DynamicGUI/StringSettingControl.xaml index 025786f..41718bf 100644 --- a/src/DynamicGUI/StringSettingControl.xaml +++ b/src/DynamicGUI/StringSettingControl.xaml @@ -1,54 +1,61 @@ - + - + - - - + + + - + diff --git a/src/DynamicGUI/StringSettingControl.xaml.cs b/src/DynamicGUI/StringSettingControl.xaml.cs index 2b12c51..b933e8b 100644 --- a/src/DynamicGUI/StringSettingControl.xaml.cs +++ b/src/DynamicGUI/StringSettingControl.xaml.cs @@ -1,9 +1,11 @@  +using mpvnet; using System; using System.Globalization; using System.Windows; using System.Windows.Controls; using System.Windows.Media; + using WinForms = System.Windows.Forms; namespace DynamicGUI @@ -16,6 +18,7 @@ namespace DynamicGUI { StringSetting = stringSetting; InitializeComponent(); + DataContext = this; TitleTextBox.Text = stringSetting.Name; HelpTextBox.Text = stringSetting.Help; ValueTextBox.Text = StringSetting.Value; @@ -32,6 +35,10 @@ namespace DynamicGUI LinkTextBlock.Visibility = Visibility.Collapsed; } + public Theme Theme { + get => Theme.Current; + } + string _SearchableText; public string SearchableText { diff --git a/src/Extensions/RatingExtension/RatingExtension.cs b/src/Extensions/RatingExtension/RatingExtension.cs index 806121f..00062f6 100644 --- a/src/Extensions/RatingExtension/RatingExtension.cs +++ b/src/Extensions/RatingExtension/RatingExtension.cs @@ -94,7 +94,9 @@ namespace RatingExtension // the assembly name must end with 'Extension'! } } else if (args[1] == "about") - MessageBox.Show("This extension writes a rating to the filename of rated videos when mpv.net shuts down.\n\nThe input.conf defaults contain key bindings for this extension to set ratings.", + MessageBox.Show($"This extension writes a rating to the filename of rated videos " + + "when mpv.net shuts down." + BR2 + + "The input.conf defaults contain key bindings for this extension to set ratings.", "Rating Extension"); } diff --git a/src/Misc/App.cs b/src/Misc/App.cs index f011fc9..220da57 100644 --- a/src/Misc/App.cs +++ b/src/Misc/App.cs @@ -26,7 +26,6 @@ namespace mpvnet public static bool AutoLoadFolder { get; set; } = true; public static bool Queue { get; set; } public static bool UpdateCheck { get; set; } - public static bool GlobalMediaKeys { get; set; } public static int StartThreshold { get; set; } = 1500; public static int RecentCount { get; set; } = 15; @@ -52,8 +51,8 @@ namespace mpvnet public static void Init() { - string dummy = Core.ConfigFolder; - var dummy2 = Core.Conf; + var useless1 = Core.ConfigFolder; + var useless2 = Core.Conf; foreach (var i in Conf) ProcessProperty(i.Key, i.Value, true); @@ -79,6 +78,14 @@ namespace mpvnet } } + InitTheme(); + + Core.Shutdown += Shutdown; + Core.Initialized += Initialized; + } + + public static void InitTheme() + { string themeContent = null; if (File.Exists(Core.ConfigFolder + "theme.conf")) @@ -89,8 +96,11 @@ namespace mpvnet Properties.Resources.theme, IsDarkMode ? DarkTheme : LightTheme); - Core.Shutdown += Shutdown; - Core.Initialized += Initialized; + ToolStripRendererEx.ForegroundColor = Theme.Current.GetWinFormsColor("menu-foreground"); + ToolStripRendererEx.BackgroundColor = Theme.Current.GetWinFormsColor("menu-background"); + ToolStripRendererEx.SelectionColor = Theme.Current.GetWinFormsColor("menu-highlight"); + ToolStripRendererEx.BorderColor = Theme.Current.GetWinFormsColor("menu-border"); + ToolStripRendererEx.CheckedColor = Theme.Current.GetWinFormsColor("menu-checked"); } public static void RunTask(Action action) diff --git a/src/Misc/CSharpScriptHost.cs b/src/Misc/CSharpScriptHost.cs index 0145124..7470064 100644 --- a/src/Misc/CSharpScriptHost.cs +++ b/src/Misc/CSharpScriptHost.cs @@ -10,6 +10,8 @@ using System.Text; using Microsoft.CSharp; +using static mpvnet.Global; + namespace mpvnet { class CSharpScriptHost @@ -66,7 +68,7 @@ namespace mpvnet i.Line + "\n" + "Error Number: " + i.ErrorNumber + "\n" + i.ErrorText); if (errors.Count() > 0) - Terminal.WriteError(string.Join("\n\n", errors), Path.GetFileName(file)); + Terminal.WriteError(string.Join(BR2, errors), Path.GetFileName(file)); } static string GetMD5(string code) diff --git a/src/Misc/CorePlayer.cs b/src/Misc/CorePlayer.cs index 12afa83..484a419 100644 --- a/src/Misc/CorePlayer.cs +++ b/src/Misc/CorePlayer.cs @@ -144,12 +144,12 @@ namespace mpvnet mpv_error err = mpv_initialize(Handle); if (err < 0) - throw new Exception("mpv_initialize error\n\n" + GetError(err)); + throw new Exception("mpv_initialize error" + BR2 + GetError(err) + BR); err = mpv_observe_property(Handle, 0, "video-rotate", mpv_format.MPV_FORMAT_INT64); if (err < 0) - throw new Exception("mpv_observe_property video-rotate error\n\n" + GetError(err)); + throw new Exception("mpv_observe_property video-rotate error" + BR2 + GetError(err) + BR); Initialized?.Invoke(); InvokeAsync(InitializedAsync); @@ -929,7 +929,7 @@ namespace mpvnet Terminal.WriteError(msg); Terminal.WriteError(GetError(err)); - throw new Exception(string.Join(BR2, messages) + BR2 + GetError(err)); + throw new Exception(string.Join(BR2, messages) + BR2 + GetError(err) + BR); } } diff --git a/src/Misc/Extension.cs b/src/Misc/Extension.cs index f2a879d..c593679 100644 --- a/src/Misc/Extension.cs +++ b/src/Misc/Extension.cs @@ -33,10 +33,10 @@ namespace mpvnet if (knownExtensions.Contains(Path.GetFileName(extDir))) catalog.Catalogs.Add(new DirectoryCatalog(extDir, Path.GetFileName(extDir) + ".dll")); else - Terminal.WriteError("Failed to load extension:\n\n" + extDir + - "\n\nOnly extensions that ship with mpv.net are allowed in \\extensions" + - "\n\nUser extensions have to use \\extensions" + - "\n\nNever copy or install a new mpv.net version over a old mpv.net version."); + Terminal.WriteError("Failed to load extension:" + BR2 + extDir + + BR2 + "Only extensions that ship with mpv.net are allowed in \\extensions" + + BR2 + "User extensions have to use \\extensions" + + BR2 + "Never copy or install a new mpv.net version over a old mpv.net version."); } } diff --git a/src/Misc/Msg.cs b/src/Misc/Msg.cs index d4cc5bc..b5053c5 100644 --- a/src/Misc/Msg.cs +++ b/src/Misc/Msg.cs @@ -2,6 +2,8 @@ using System; using System.Windows.Forms; +using static mpvnet.Global; + public class Msg { public static void ShowInfo(object title, object content = null) @@ -33,7 +35,7 @@ public class Msg public static DialogResult Show(object title, object content, MessageBoxIcon icon, MessageBoxButtons buttons = MessageBoxButtons.OK) { - string msg = (title?.ToString().TrimEx() + "\n\n" + content?.ToString().TrimEx()).Trim(); + string msg = (title?.ToString().TrimEx() + BR2 + content?.ToString().TrimEx()).Trim(); return MessageBox.Show(msg, Application.ProductName, buttons, icon); } } diff --git a/src/Misc/Theme.cs b/src/Misc/Theme.cs index afba4c3..d261eff 100644 --- a/src/Misc/Theme.cs +++ b/src/Misc/Theme.cs @@ -14,10 +14,10 @@ namespace mpvnet public static Theme Current { get; set; } - public static Brush Foreground { get; set; } - public static Brush Foreground2 { get; set; } - public static Brush Background { get; set; } - public static Brush Heading { get; set; } + public Brush Foreground { get; set; } + public Brush Foreground2 { get; set; } + public Brush Background { get; set; } + public Brush Heading { get; set; } public System.Drawing.Color GetWinFormsColor(string key) { @@ -31,6 +31,8 @@ namespace mpvnet public static void Init(string customContent, string defaultContent, string activeTheme) { + Current = null; + DefaultThemes = Load(defaultContent); CustomThemes = Load(customContent); @@ -65,10 +67,10 @@ namespace mpvnet if (Current == null) Current = DefaultThemes[0]; - Foreground = Current.GetBrush("foreground"); - Foreground2 = Current.GetBrush("foreground2"); - Background = Current.GetBrush("background"); - Heading = Current.GetBrush("heading"); + Current.Foreground = Current.GetBrush("foreground"); + Current.Foreground2 = Current.GetBrush("foreground2"); + Current.Background = Current.GetBrush("background"); + Current.Heading = Current.GetBrush("heading"); } static List Load(string content) diff --git a/src/Resources/input.conf.txt b/src/Resources/input.conf.txt index ebca746..41a30ae 100644 --- a/src/Resources/input.conf.txt +++ b/src/Resources/input.conf.txt @@ -44,8 +44,8 @@ _ ignore #menu: - Enter cycle fullscreen #menu: Toggle Fullscreen - F11 playlist-prev #menu: Navigate > Previous File - F12 playlist-next #menu: Navigate > Next File + F11 playlist-prev; set pause no #menu: Navigate > Previous File + F12 playlist-next; set pause no #menu: Navigate > Next File _ ignore #menu: Navigate > - Home script-message mpv.net playlist-first #menu: Navigate > First File End script-message mpv.net playlist-last #menu: Navigate > Last File diff --git a/src/Scripts/C-Sharp/rate-file.cs b/src/Scripts/C-Sharp/rate-file.cs index f9a91ce..c0858d9 100644 --- a/src/Scripts/C-Sharp/rate-file.cs +++ b/src/Scripts/C-Sharp/rate-file.cs @@ -3,12 +3,12 @@ // In input.conf add: -// KP0 script-message rate-file 0 #menu: Extensions > Rating > 0stars -// KP1 script-message rate-file 1 #menu: Extensions > Rating > 1stars -// KP2 script-message rate-file 2 #menu: Extensions > Rating > 2stars -// KP3 script-message rate-file 3 #menu: Extensions > Rating > 3stars -// KP4 script-message rate-file 4 #menu: Extensions > Rating > 4stars -// KP5 script-message rate-file 5 #menu: Extensions > Rating > 5stars +// KP0 script-message rate-file 0 #menu: Script > Rating > 0stars +// KP1 script-message rate-file 1 #menu: Script > Rating > 1stars +// KP2 script-message rate-file 2 #menu: Script > Rating > 2stars +// KP3 script-message rate-file 3 #menu: Script > Rating > 3stars +// KP4 script-message rate-file 4 #menu: Script > Rating > 4stars +// KP5 script-message rate-file 5 #menu: Script > Rating > 5stars using System; using System.Collections.Generic; diff --git a/src/WPF/AboutWindow.xaml b/src/WPF/AboutWindow.xaml index 5370cdc..79a98a5 100644 --- a/src/WPF/AboutWindow.xaml +++ b/src/WPF/AboutWindow.xaml @@ -1,19 +1,20 @@ - + diff --git a/src/WPF/AboutWindow.xaml.cs b/src/WPF/AboutWindow.xaml.cs index 13fd5ac..149f12d 100644 --- a/src/WPF/AboutWindow.xaml.cs +++ b/src/WPF/AboutWindow.xaml.cs @@ -9,10 +9,15 @@ namespace mpvnet public AboutWindow() { InitializeComponent(); + DataContext = this; ContentBlock.Text = App.Version; } protected override void OnPreviewKeyDown(KeyEventArgs e) => Close(); protected override void OnMouseDown(MouseButtonEventArgs e) => Close(); + + public Theme Theme { + get => Theme.Current; + } } } diff --git a/src/WPF/CommandPaletteWindow.xaml b/src/WPF/CommandPaletteWindow.xaml index 159b3f4..ebe5be3 100644 --- a/src/WPF/CommandPaletteWindow.xaml +++ b/src/WPF/CommandPaletteWindow.xaml @@ -1,19 +1,19 @@ - + @@ -21,17 +21,21 @@ - + - + diff --git a/src/WPF/SearchTextBoxUserControl.xaml.cs b/src/WPF/SearchTextBoxUserControl.xaml.cs index 58482aa..b40d0ec 100644 --- a/src/WPF/SearchTextBoxUserControl.xaml.cs +++ b/src/WPF/SearchTextBoxUserControl.xaml.cs @@ -3,6 +3,8 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using mpvnet; + namespace Controls { public partial class SearchTextBoxUserControl : UserControl @@ -10,9 +12,17 @@ namespace Controls public SearchTextBoxUserControl() { InitializeComponent(); + DataContext = this; } - public string Text { get => SearchTextBox.Text; set => SearchTextBox.Text = value; } + public Theme Theme { + get => Theme.Current; + } + + public string Text { + get => SearchTextBox.Text; + set => SearchTextBox.Text = value; + } string _HintText; diff --git a/src/WPF/SetupWindow.xaml b/src/WPF/SetupWindow.xaml index 26eadc6..39287a2 100644 --- a/src/WPF/SetupWindow.xaml +++ b/src/WPF/SetupWindow.xaml @@ -1,17 +1,19 @@ - +