From 6f7f127279acfb2b92067e32fb994de2eda14559 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Mon, 10 May 2021 13:11:39 +0200 Subject: [PATCH] reworked start-size option --- docs/Changelog.md | 6 +++ docs/Manual.md | 9 +++-- src/Misc/App.cs | 8 ++-- src/Misc/Commands.cs | 2 +- src/Misc/Help.cs | 20 ++++------ src/Misc/UpdateCheck.cs | 4 +- src/Resources/editor.toml.txt | 11 +++--- src/WPF/ConfWindow.xaml.cs | 2 +- src/WinForms/MainForm.cs | 72 +++++++++++++++++++++++++---------- src/mpv/Core.cs | 2 +- 10 files changed, 87 insertions(+), 49 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 0cd81a0..b8cc420 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,4 +1,10 @@ +5.4.8.9 Beta (???) +========================= + +- Reworked [start-size](Manual.md#--start-sizevalue) option. + + 5.4.8.8 Beta (2021-05-09) ========================= diff --git a/docs/Manual.md b/docs/Manual.md index 1b9acc6..1e347f0 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -217,11 +217,14 @@ Setting to remember the window height. **video** Window size is set to video resolution. -**previous** -Window size is remembered but only in the current session. Default +**previous-height** +Height is remembered in the current session. Default + +**always-height** +Height is always remembered. **always** -Window size is always remembered. +Size is always remembered. #### --start-threshold=\ diff --git a/src/Misc/App.cs b/src/Misc/App.cs index 583d455..5e83472 100644 --- a/src/Misc/App.cs +++ b/src/Misc/App.cs @@ -18,7 +18,7 @@ namespace mpvnet public static string DarkMode { get; set; } = "always"; public static string DarkTheme { get; set; } = "dark"; public static string LightTheme { get; set; } = "light"; - public static string StartSize { get; set; } = "previous"; + public static string StartSize { get; set; } = "previous-height"; public static bool RememberPosition { get; set; } public static bool DebugMode { get; set; } @@ -135,8 +135,8 @@ namespace mpvnet { if (RememberVolume) { - core.set_property_int("volume", RegistryHelp.GetInt(RegPath, "Volume", 70)); - core.set_property_string("mute", RegistryHelp.GetString(RegPath, "Mute", "no")); + core.set_property_int("volume", RegistryHelp.GetInt("Volume", 70)); + core.set_property_string("mute", RegistryHelp.GetString("Mute", "no")); } } @@ -196,7 +196,7 @@ namespace mpvnet public static void ShowSetup() { - int value = RegistryHelp.GetInt(RegistryHelp.ApplicationKey, Folder.Startup); + int value = RegistryHelp.GetInt(Folder.Startup); if (value != 1) { diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index 2bcdac1..85c219a 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -234,7 +234,7 @@ namespace mpvnet public static void ExecuteMpvCommand() // deprecated 2019 { InvokeOnMainThread(new Action(() => { - string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegistryHelp.GetString(App.RegPath, "RecentExecutedCommand")); + string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegistryHelp.GetString("RecentExecutedCommand")); if (string.IsNullOrEmpty(command)) return; diff --git a/src/Misc/Help.cs b/src/Misc/Help.cs index 409a411..f604c4f 100644 --- a/src/Misc/Help.cs +++ b/src/Misc/Help.cs @@ -173,15 +173,15 @@ namespace mpvnet regKey.SetValue(name, value); } - public static string GetString(string path, string name, string defaultValue = "") + public static string GetString(string name, string defaultValue = "") { - object value = GetValue(path, name, defaultValue); + object value = GetValue(ApplicationKey, name, defaultValue); return !(value is string) ? defaultValue : value.ToString(); } - public static int GetInt(string path, string name, int defaultValue = 0) + public static int GetInt(string name, int defaultValue = 0) { - object value = GetValue(path, name, defaultValue); + object value = GetValue(ApplicationKey, name, defaultValue); return !(value is int) ? defaultValue : (int)value; } @@ -193,22 +193,18 @@ namespace mpvnet public static void RemoveKey(string path) { - try - { + try { GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false); - } - catch { } + } catch { } } public static void RemoveValue(string path, string name) { - try - { + try { using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5), true)) if (regKey != null) regKey.DeleteValue(name, false); - } - catch { } + } catch { } } static RegistryKey GetRootKey(string path) diff --git a/src/Misc/UpdateCheck.cs b/src/Misc/UpdateCheck.cs index dafcb72..3d7783d 100644 --- a/src/Misc/UpdateCheck.cs +++ b/src/Misc/UpdateCheck.cs @@ -15,7 +15,7 @@ namespace mpvnet { public static void DailyCheck() { - if (App.UpdateCheck && RegistryHelp.GetInt(RegistryHelp.ApplicationKey, "UpdateCheckLast") + if (App.UpdateCheck && RegistryHelp.GetInt("UpdateCheckLast") != DateTime.Now.DayOfYear) CheckOnline(); @@ -44,7 +44,7 @@ namespace mpvnet return; } - if ((RegistryHelp.GetString(RegistryHelp.ApplicationKey, "UpdateCheckVersion") + if ((RegistryHelp.GetString("UpdateCheckVersion") != onlineVersion.ToString() || showUpToDateMessage) && Msg.ShowQuestion( $"New version {onlineVersion} is available, update now?") == MsgResult.OK) { diff --git a/src/Resources/editor.toml.txt b/src/Resources/editor.toml.txt index 8d717fc..d52ea20 100644 --- a/src/Resources/editor.toml.txt +++ b/src/Resources/editor.toml.txt @@ -339,12 +339,13 @@ help = " Maximum window height in percent. Default: 80" [[settings]] name = "start-size" file = "mpvnet" -default = "previous" +default = "previous-height" filter = "Screen" -help = "Setting to remember the window height. (mpv.net specific setting)" -options = [{ name = "video", help = "Window size is set to video resolution" }, - { name = "previous", help = "Window size is remembered but only in the current session" }, - { name = "always", help = "Window size is always remembered"}] +help = "Setting to remember the window size. (mpv.net specific setting)" +options = [{ name = "video", help = "Window size is set to video resolution" }, + { name = "previous-height", help = "Height is remembered in the current session" }, + { name = "always-height", help = "Height is always remembered" }, + { name = "always", help = "Size is always remembered" }] [[settings]] name = "start-threshold" diff --git a/src/WPF/ConfWindow.xaml.cs b/src/WPF/ConfWindow.xaml.cs index 660fb56..001330d 100644 --- a/src/WPF/ConfWindow.xaml.cs +++ b/src/WPF/ConfWindow.xaml.cs @@ -31,7 +31,7 @@ namespace mpvnet LoadConf(App.ConfPath); LoadSettings(); InitialContent = GetCompareString(); - SearchControl.Text = RegistryHelp.GetString(App.RegPath, "ConfigEditorSearch"); + SearchControl.Text = RegistryHelp.GetString("ConfigEditorSearch"); FilterListBox.SelectedItem = SearchControl.Text.TrimEnd(':'); } diff --git a/src/WinForms/MainForm.cs b/src/WinForms/MainForm.cs index 397991c..0442298 100644 --- a/src/WinForms/MainForm.cs +++ b/src/WinForms/MainForm.cs @@ -105,8 +105,8 @@ namespace mpvnet if (!core.Border) FormBorderStyle = FormBorderStyle.None; - int posX = RegistryHelp.GetInt(App.RegPath, "PosX"); - int posY = RegistryHelp.GetInt(App.RegPath, "PosY"); + int posX = RegistryHelp.GetInt("PosX"); + int posY = RegistryHelp.GetInt("PosY"); if (posX != 0 && posY != 0 && App.RememberPosition) { @@ -320,10 +320,11 @@ namespace mpvnet return null; } - void SetFormPosAndSize(double scale = 1, - bool force = false, - bool checkAutofitSmaller = true, - bool checkAutofitLarger = true) + void SetFormPosAndSize( + double scale = 1, + bool force = false, + bool checkAutofitSmaller = true, + bool checkAutofitLarger = true) { if (!force) { @@ -346,36 +347,66 @@ namespace mpvnet core.VideoSize = new Size((int)(autoFitHeight * (16 / 9f)), autoFitHeight); Size videoSize = core.VideoSize; + int height = videoSize.Height; + int width = videoSize.Width; + + if (App.StartSize == "previous") + App.StartSize = "previous-height"; if (core.WasInitialSizeSet || scale != 1) - height = ClientSize.Height; + { + if (App.StartSize == "always") + { + width = ClientSize.Width; + height = ClientSize.Height; + } + else if (App.StartSize == "always-height" || App.StartSize == "previous-height") + { + height = ClientSize.Height; + width = height * videoSize.Width / videoSize.Height; + } + } else { - int savedHeight = RegistryHelp.GetInt(App.RegPath, "Height"); + int savedHeight = RegistryHelp.GetInt("Height"); + int savedWidth = RegistryHelp.GetInt("Width"); - if (App.StartSize == "always" && savedHeight != 0) + if (App.StartSize == "always-height" && savedHeight != 0) + { height = savedHeight; - else - if (App.StartSize != "video") - height = autoFitHeight; + width = height * videoSize.Width / videoSize.Height; + } + else if (App.StartSize == "always" && savedHeight != 0) + { + height = savedHeight; + width = savedWidth; + } + else if (App.StartSize == "previous-height") + { + height = autoFitHeight; + width = height * videoSize.Width / videoSize.Height; + } core.WasInitialSizeSet = true; } height = Convert.ToInt32(height * scale); - SetSize(new Size(height * videoSize.Width / videoSize.Height, height), - videoSize, screen, checkAutofitSmaller, checkAutofitLarger); + width = Convert.ToInt32(width * scale); + + SetSize(new Size(width, height), videoSize, screen, checkAutofitSmaller, checkAutofitLarger); } - void SetSize(Size size, - Size videoSize, - Screen screen, - bool checkAutofitSmaller = true, - bool checkAutofitLarger = true) + void SetSize( + Size size, + Size videoSize, + Screen screen, + bool checkAutofitSmaller = true, + bool checkAutofitLarger = true) { int height = size.Height; - int width = size.Height * videoSize.Width / videoSize.Height; + int width = size.Width; + int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height); int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width); @@ -538,6 +569,7 @@ namespace mpvnet { RegistryHelp.SetValue(App.RegPath, "PosX", Left + Width / 2); RegistryHelp.SetValue(App.RegPath, "PosY", Top + Height / 2); + RegistryHelp.SetValue(App.RegPath, "Width", ClientSize.Width); RegistryHelp.SetValue(App.RegPath, "Height", ClientSize.Height); } } diff --git a/src/mpv/Core.cs b/src/mpv/Core.cs index 821f67e..d76dddd 100644 --- a/src/mpv/Core.cs +++ b/src/mpv/Core.cs @@ -193,7 +193,7 @@ namespace mpvnet _ConfigFolder = portableFolder; if (!Directory.Exists(_ConfigFolder)) - _ConfigFolder = RegistryHelp.GetString(App.RegPath, "ConfigFolder"); + _ConfigFolder = RegistryHelp.GetString("ConfigFolder"); if (!Directory.Exists(_ConfigFolder)) {