From 1e094cae32349bb3cb04ea20aaece58e9e9db843 Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 2 Aug 2021 18:21:09 +0300 Subject: [PATCH] Added remember window state option to history forms --- .../Forms/HistoryForm.Designer.cs | 1 + ShareX.HistoryLib/Forms/HistoryForm.cs | 23 ++++++++++++++----- ShareX.HistoryLib/Forms/HistoryForm.resx | 2 +- .../Forms/ImageHistoryForm.Designer.cs | 1 + ShareX.HistoryLib/Forms/ImageHistoryForm.cs | 13 ++++++++++- ShareX.HistoryLib/HistorySettings.cs | 1 + ShareX.HistoryLib/ImageHistorySettings.cs | 1 + 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs b/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs index 13703b25e..851e9ae38 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs @@ -338,6 +338,7 @@ private void InitializeComponent() this.Controls.Add(this.scMain); this.KeyPreview = true; this.Name = "HistoryForm"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.HistoryForm_FormClosing); this.Shown += new System.EventHandler(this.HistoryForm_Shown); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.HistoryForm_KeyDown); this.Resize += new System.EventHandler(this.HistoryForm_Resize); diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index b3caa3860..8ddec5003 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -73,11 +73,6 @@ public HistoryForm(string historyPath, HistorySettings settings, Action pbThumbnail.Reset(); lvHistory.FillLastColumn(); - if (Settings.SplitterDistance > 0) - { - scMain.SplitterDistance = Settings.SplitterDistance; - } - if (Settings.RememberSearchText) { tstbSearch.Text = Settings.SearchText; @@ -85,7 +80,15 @@ public HistoryForm(string historyPath, HistorySettings settings, Action ShareXResources.ApplyTheme(this); - Settings.WindowState.AutoHandleFormState(this); + if (Settings.RememberWindowState) + { + Settings.WindowState.ApplyFormState(this); + + if (Settings.SplitterDistance > 0) + { + scMain.SplitterDistance = Settings.SplitterDistance; + } + } } private void ResetFilters() @@ -371,6 +374,14 @@ private void HistoryForm_Resize(object sender, EventArgs e) Refresh(); } + private void HistoryForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (Settings.RememberWindowState) + { + Settings.WindowState.UpdateFormState(this); + } + } + private void HistoryForm_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyData) diff --git a/ShareX.HistoryLib/Forms/HistoryForm.resx b/ShareX.HistoryLib/Forms/HistoryForm.resx index e695194b2..b0ca29330 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.resx +++ b/ShareX.HistoryLib/Forms/HistoryForm.resx @@ -712,7 +712,7 @@ 3, 0 - 485, 25 + 454, 25 0 diff --git a/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs b/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs index 172dc3fca..b084fb5ef 100644 --- a/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs +++ b/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs @@ -156,6 +156,7 @@ private void InitializeComponent() this.Controls.Add(this.tscMain); this.KeyPreview = true; this.Name = "ImageHistoryForm"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ImageHistoryForm_FormClosing); this.Shown += new System.EventHandler(this.ImageHistoryForm_Shown); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ImageHistoryForm_KeyDown); this.tscMain.ContentPanel.ResumeLayout(false); diff --git a/ShareX.HistoryLib/Forms/ImageHistoryForm.cs b/ShareX.HistoryLib/Forms/ImageHistoryForm.cs index f05f1761f..679be2ee5 100644 --- a/ShareX.HistoryLib/Forms/ImageHistoryForm.cs +++ b/ShareX.HistoryLib/Forms/ImageHistoryForm.cs @@ -83,7 +83,10 @@ public ImageHistoryForm(string historyPath, ImageHistorySettings settings, Actio ShareXResources.ApplyTheme(this); - Settings.WindowState.AutoHandleFormState(this); + if (Settings.RememberWindowState) + { + Settings.WindowState.ApplyFormState(this); + } } private void UpdateTitle(int total, int filtered) @@ -168,6 +171,14 @@ private void ImageHistoryForm_Shown(object sender, EventArgs e) RefreshHistoryItems(); } + private void ImageHistoryForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (Settings.RememberWindowState) + { + Settings.WindowState.UpdateFormState(this); + } + } + private void ImageHistoryForm_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F5) diff --git a/ShareX.HistoryLib/HistorySettings.cs b/ShareX.HistoryLib/HistorySettings.cs index f05d06564..46f6166c3 100644 --- a/ShareX.HistoryLib/HistorySettings.cs +++ b/ShareX.HistoryLib/HistorySettings.cs @@ -29,6 +29,7 @@ namespace ShareX.HistoryLib { public class HistorySettings { + public bool RememberWindowState { get; set; } = true; public WindowState WindowState { get; set; } = new WindowState(); public int SplitterDistance { get; set; } = 550; public int MaxItemCount { get; set; } = 0; diff --git a/ShareX.HistoryLib/ImageHistorySettings.cs b/ShareX.HistoryLib/ImageHistorySettings.cs index 8a053644e..e7af82ed0 100644 --- a/ShareX.HistoryLib/ImageHistorySettings.cs +++ b/ShareX.HistoryLib/ImageHistorySettings.cs @@ -30,6 +30,7 @@ namespace ShareX.HistoryLib { public class ImageHistorySettings { + public bool RememberWindowState { get; set; } = true; public WindowState WindowState { get; set; } = new WindowState(); public int ViewMode { get; set; } = 3; public Size ThumbnailSize { get; set; } = new Size(150, 150);