From 668497ec3cafacac905332a9cc2bb59d87da89f5 Mon Sep 17 00:00:00 2001 From: KevinZonda <33132228+KevinZonda@users.noreply.github.com> Date: Tue, 3 Nov 2020 00:58:29 +0000 Subject: [PATCH] [UI] support save mainwindow size --- .gitignore | 3 ++ .idea/.idea.NaiveSharp/.idea/contentModel.xml | 29 +++++++++------ NaiveSharp/ConstText/Path/Config.cs | 1 + NaiveSharp/Controller/Encoder.cs | 4 +-- NaiveSharp/Controller/Operation.cs | 4 +-- NaiveSharp/Model/Config.cs | 14 +++++++- NaiveSharp/Model/FormSize.cs | 21 +++++++++++ NaiveSharp/NaiveSharp.csproj | 1 + NaiveSharp/View/MainWindow.Designer.cs | 1 + NaiveSharp/View/MainWindow.cs | 35 ++++++++++++++----- NaiveSharp/View/MainWindowsEx.cs | 10 ------ NaiveSharp/View/Qr.cs | 7 ---- 12 files changed, 89 insertions(+), 41 deletions(-) create mode 100644 NaiveSharp/Model/FormSize.cs diff --git a/.gitignore b/.gitignore index dfcfd56..b70a594 100644 --- a/.gitignore +++ b/.gitignore @@ -348,3 +348,6 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ + +# Rider +.idea diff --git a/.idea/.idea.NaiveSharp/.idea/contentModel.xml b/.idea/.idea.NaiveSharp/.idea/contentModel.xml index ecf4c70..e17a3d5 100644 --- a/.idea/.idea.NaiveSharp/.idea/contentModel.xml +++ b/.idea/.idea.NaiveSharp/.idea/contentModel.xml @@ -1,24 +1,26 @@ - - - + + + - - - - - - - - + + + + + + + + + + @@ -55,10 +57,12 @@ + + @@ -76,6 +80,9 @@ + + + diff --git a/NaiveSharp/ConstText/Path/Config.cs b/NaiveSharp/ConstText/Path/Config.cs index 764f89b..8de5c24 100644 --- a/NaiveSharp/ConstText/Path/Config.cs +++ b/NaiveSharp/ConstText/Path/Config.cs @@ -4,6 +4,7 @@ public static partial class PATH { public const string CONFIG = @"config"; public const string CONFIG_INI = @"config\config.ini"; + public const string CONFIG_FORM = @"config\form.ns"; public const string CONFIG_NODE_NS = @"config\node.ns"; public const string CONFIG_NODELIST = @"config\list.ns"; public const string CONFIG_SELECT_NODE = @"config\selectnode.ns"; diff --git a/NaiveSharp/Controller/Encoder.cs b/NaiveSharp/Controller/Encoder.cs index 1583eb3..57ffb51 100644 --- a/NaiveSharp/Controller/Encoder.cs +++ b/NaiveSharp/Controller/Encoder.cs @@ -11,7 +11,7 @@ public static string ConvertToBase64(string str, bool exceptionReturnSourceData { try { - return Convert.ToBase64String((byte[]) Encoding.UTF8.GetBytes(str)); + return Convert.ToBase64String(Encoding.UTF8.GetBytes(str)); } catch { @@ -30,7 +30,7 @@ public static string ConvertFromBase64(string str, bool exceptionReturnSourceDat { try { - return Encoding.UTF8.GetString((byte[]) Convert.FromBase64String(str)); + return Encoding.UTF8.GetString(Convert.FromBase64String(str)); } catch { diff --git a/NaiveSharp/Controller/Operation.cs b/NaiveSharp/Controller/Operation.cs index 7cb3bf7..23a084d 100644 --- a/NaiveSharp/Controller/Operation.cs +++ b/NaiveSharp/Controller/Operation.cs @@ -1,9 +1,9 @@ -using NaiveSharp.ConstText; -using NaiveSharp.Model; +using NaiveSharp.Model; using System.Diagnostics; using System.IO; using System.Windows.Forms; +using PATH = NaiveSharp.ConstText.PATH; namespace NaiveSharp.Controller { diff --git a/NaiveSharp/Model/Config.cs b/NaiveSharp/Model/Config.cs index 65d9bf9..67585a4 100644 --- a/NaiveSharp/Model/Config.cs +++ b/NaiveSharp/Model/Config.cs @@ -1,4 +1,6 @@ -using NaiveSharp.Controller.Extension; +using System.IO; +using NaiveSharp.ConstText; +using NaiveSharp.Controller.Extension; namespace NaiveSharp.Model { @@ -26,6 +28,16 @@ public static string ConvertToNs() { return Controller.NaiveCmdBuilder.Proxy(Scheme, Username, Password, Host).ToBase64(); } + + public static void Save() + { + if (!File.Exists(PATH.CONFIG_INI)) + { + File.Create(PATH.CONFIG_INI).Close(); + } + + File.WriteAllText(PATH.CONFIG_INI, $"mode = {Config.RunMode}"); + } } } \ No newline at end of file diff --git a/NaiveSharp/Model/FormSize.cs b/NaiveSharp/Model/FormSize.cs new file mode 100644 index 0000000..316e58a --- /dev/null +++ b/NaiveSharp/Model/FormSize.cs @@ -0,0 +1,21 @@ +using System.IO; +using NaiveSharp.ConstText; + +namespace NaiveSharp.Model +{ + public class FormSize + { + public static int X; + public static int Y; + + public static void Save() + { + if (!File.Exists(PATH.CONFIG_FORM)) + { + File.Create(PATH.CONFIG_FORM).Close(); + } + + File.WriteAllText(PATH.CONFIG_FORM, $"{X},{Y}"); + } + } +} \ No newline at end of file diff --git a/NaiveSharp/NaiveSharp.csproj b/NaiveSharp/NaiveSharp.csproj index e1d03d6..ca5289a 100644 --- a/NaiveSharp/NaiveSharp.csproj +++ b/NaiveSharp/NaiveSharp.csproj @@ -129,6 +129,7 @@ + diff --git a/NaiveSharp/View/MainWindow.Designer.cs b/NaiveSharp/View/MainWindow.Designer.cs index 9f84e19..9b79f66 100644 --- a/NaiveSharp/View/MainWindow.Designer.cs +++ b/NaiveSharp/View/MainWindow.Designer.cs @@ -708,6 +708,7 @@ private void InitializeComponent() this.Text = "Naive# 0.6.5 Preview"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainWindow_FormClosing); this.Load += new System.EventHandler(this.MainWindows_Load); + this.ResizeEnd += new System.EventHandler(this.MainWindow_ResizeEnd); this.tlpProxyMode.ResumeLayout(false); this.tlpProxyMode.PerformLayout(); this.tlpScheme.ResumeLayout(false); diff --git a/NaiveSharp/View/MainWindow.cs b/NaiveSharp/View/MainWindow.cs index bdbc71e..1fe3057 100644 --- a/NaiveSharp/View/MainWindow.cs +++ b/NaiveSharp/View/MainWindow.cs @@ -14,6 +14,18 @@ public MainWindow() { CheckPath(); + if (File.Exists(ConstText.PATH.CONFIG_FORM)) + { + var c = File.ReadAllText(PATH.CONFIG_FORM).Replace(" ", "").Split(','); + if (c.Length == 2) + { + if (int.TryParse(c[0].Trim(), out int iTX)) + FormSize.X = iTX; + if (int.TryParse(c[1].Trim(), out int iTY)) + FormSize.Y = iTY; + } + } + // MessageBox.Show(File.ReadAllText(PATH.CONFIG_INI)); string runMode = LoadModeConfig(); @@ -74,6 +86,10 @@ public MainWindow() } } */ + if (Model.FormSize.X > 0) + this.Width = FormSize.X; + if (FormSize.Y > 0) + this.Height = FormSize.Y; } private void MainWindows_Load(object sender, EventArgs e) @@ -86,6 +102,13 @@ private void MainWindows_Load(object sender, EventArgs e) icnNotify.Visible = true; } + + private void MainWindow_ResizeEnd(object sender, EventArgs e) + { + FormSize.X = Width; + FormSize.Y = Height; + FormSize.Save(); + } #region ProxyMode @@ -97,7 +120,7 @@ private void rdoGlobal_CheckedChanged(object sender, EventArgs e) } SyncRunModeToView(SyncMode.RadioToTsm); - SaveConfig(); + Config.Save(); } private void rdoGfwlist_CheckedChanged(object sender, EventArgs e) @@ -108,7 +131,7 @@ private void rdoGfwlist_CheckedChanged(object sender, EventArgs e) } SyncRunModeToView(SyncMode.RadioToTsm); - SaveConfig(); + Config.Save(); } private void rdoGeoIP_CheckedChanged(object sender, EventArgs e) @@ -119,7 +142,7 @@ private void rdoGeoIP_CheckedChanged(object sender, EventArgs e) } SyncRunModeToView(SyncMode.RadioToTsm); - SaveConfig(); + Config.Save(); } private void rdoNone_CheckedChanged(object sender, EventArgs e) @@ -130,7 +153,7 @@ private void rdoNone_CheckedChanged(object sender, EventArgs e) } SyncRunModeToView(SyncMode.RadioToTsm); - SaveConfig(); + Config.Save(); } #endregion @@ -446,10 +469,6 @@ private void btnAddNode_Click(object sender, EventArgs e) tnc.Add(new TreeNode() {Text = "default", Tag = "naive+https://default:default@default#default"}); } - private void btnDelNode_Click(object sender, EventArgs e) - { - } - private void lblAddGroup_Click(object sender, EventArgs e) { string group = "Default"; diff --git a/NaiveSharp/View/MainWindowsEx.cs b/NaiveSharp/View/MainWindowsEx.cs index 66fef51..feed178 100644 --- a/NaiveSharp/View/MainWindowsEx.cs +++ b/NaiveSharp/View/MainWindowsEx.cs @@ -178,16 +178,6 @@ private static string LoadModeConfig() return "global"; } - private static void SaveConfig() - { - if (!File.Exists(PATH.CONFIG_INI)) - { - File.Create(PATH.CONFIG_INI).Close(); - } - - File.WriteAllText(PATH.CONFIG_INI, $"mode = {Config.RunMode}"); - } - private void CheckPath() { CheckDirectory(PATH.CONFIG); diff --git a/NaiveSharp/View/Qr.cs b/NaiveSharp/View/Qr.cs index 3dd9afd..90126c8 100644 --- a/NaiveSharp/View/Qr.cs +++ b/NaiveSharp/View/Qr.cs @@ -1,11 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms;