diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index a13f96153..318fba338 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -82,11 +82,6 @@ public HistoryForm(string historyPath, int maxItemCount, int splitterDistance = private void RefreshHistoryItems() { - if (history == null) - { - history = new HistoryManager(HistoryPath); - } - allHistoryItems = GetHistoryItems(); ApplyFiltersAndAdd(); } @@ -98,6 +93,11 @@ private HistoryItem[] him_GetHistoryItems() private HistoryItem[] GetHistoryItems() { + if (history == null) + { + history = new HistoryManager(HistoryPath); + } + IEnumerable tempHistoryItems = history.GetHistoryItems(); tempHistoryItems = tempHistoryItems.Reverse(); diff --git a/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs b/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs index 911041760..b3004e2de 100644 --- a/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs +++ b/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs @@ -35,8 +35,8 @@ private void InitializeComponent() this.tslSearch = new System.Windows.Forms.ToolStripLabel(); this.tstbSearch = new System.Windows.Forms.ToolStripTextBox(); this.tsbSearch = new System.Windows.Forms.ToolStripButton(); - this.tsbSettings = new System.Windows.Forms.ToolStripButton(); this.tss1 = new System.Windows.Forms.ToolStripSeparator(); + this.tsbSettings = new System.Windows.Forms.ToolStripButton(); this.tscMain.ContentPanel.SuspendLayout(); this.tscMain.TopToolStripPanel.SuspendLayout(); this.tscMain.SuspendLayout(); @@ -113,6 +113,11 @@ private void InitializeComponent() this.tsbSearch.Name = "tsbSearch"; this.tsbSearch.Click += new System.EventHandler(this.tsbSearch_Click); // + // tss1 + // + this.tss1.Name = "tss1"; + resources.ApplyResources(this.tss1, "tss1"); + // // tsbSettings // this.tsbSettings.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; @@ -120,11 +125,6 @@ private void InitializeComponent() this.tsbSettings.Name = "tsbSettings"; this.tsbSettings.Click += new System.EventHandler(this.tsbSettings_Click); // - // tss1 - // - this.tss1.Name = "tss1"; - resources.ApplyResources(this.tss1, "tss1"); - // // ImageHistoryForm // resources.ApplyResources(this, "$this"); diff --git a/ShareX.HistoryLib/Forms/ImageHistoryForm.cs b/ShareX.HistoryLib/Forms/ImageHistoryForm.cs index a9f7d7b10..3d9fb659f 100644 --- a/ShareX.HistoryLib/Forms/ImageHistoryForm.cs +++ b/ShareX.HistoryLib/Forms/ImageHistoryForm.cs @@ -62,6 +62,11 @@ public ImageHistoryForm(string historyPath, ImageHistorySettings settings, Actio defaultTitle = Text; + if (Settings.RememberSearchText) + { + tstbSearch.Text = Settings.SearchText; + } + Settings.WindowState.AutoHandleFormState(this); } @@ -72,25 +77,36 @@ private void UpdateTitle(int total, int filtered) private void RefreshHistoryItems() { - SearchText = tstbSearch.Text; - - if (history == null) - { - history = new HistoryManager(HistoryPath); - } - + UpdateSearchText(); ilvImages.Items.Clear(); ImageListViewItem[] ilvItems = GetHistoryItems().Select(hi => new ImageListViewItem(hi.Filepath) { Tag = hi }).ToArray(); ilvImages.Items.AddRange(ilvItems); } + private void UpdateSearchText() + { + SearchText = tstbSearch.Text; + + if (Settings.RememberSearchText) + { + Settings.SearchText = SearchText; + } + else + { + Settings.SearchText = ""; + } + } + private IEnumerable GetHistoryItems() { + if (history == null) + { + history = new HistoryManager(HistoryPath); + } + List historyItems = history.GetHistoryItems(); List filteredHistoryItems = new List(); - int itemCount = 0; - for (int i = historyItems.Count - 1; i >= 0; i--) { HistoryItem hi = historyItems[i]; @@ -100,16 +116,14 @@ private IEnumerable GetHistoryItems() { filteredHistoryItems.Add(hi); - itemCount++; - - if (Settings.MaxItemCount > 0 && itemCount >= Settings.MaxItemCount) + if (Settings.MaxItemCount > 0 && filteredHistoryItems.Count >= Settings.MaxItemCount) { break; } } } - UpdateTitle(historyItems.Count, itemCount); + UpdateTitle(historyItems.Count, filteredHistoryItems.Count); return filteredHistoryItems; } diff --git a/ShareX.HistoryLib/Forms/ImageHistoryForm.resx b/ShareX.HistoryLib/Forms/ImageHistoryForm.resx index 9d4204526..5d0591d5c 100644 --- a/ShareX.HistoryLib/Forms/ImageHistoryForm.resx +++ b/ShareX.HistoryLib/Forms/ImageHistoryForm.resx @@ -228,6 +228,9 @@ 23, 22 + + Search + Search @@ -247,7 +250,7 @@ 3, 0 - 441, 25 + 472, 25 0 @@ -321,18 +324,18 @@ System.Windows.Forms.ToolStripButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tsbSettings - - - System.Windows.Forms.ToolStripButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - tss1 System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsbSettings + + + System.Windows.Forms.ToolStripButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + ImageHistoryForm diff --git a/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.Designer.cs b/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.Designer.cs index 146c78aa8..02ee02dc1 100644 --- a/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.Designer.cs +++ b/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.Designer.cs @@ -36,6 +36,7 @@ private void InitializeComponent() this.nudThumbnailSize = new System.Windows.Forms.NumericUpDown(); this.nudMaximumImageLimit = new System.Windows.Forms.NumericUpDown(); this.lblThumbnailSizeUnit = new System.Windows.Forms.Label(); + this.cbRememberSearchText = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.nudThumbnailSize)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudMaximumImageLimit)).BeginInit(); this.SuspendLayout(); @@ -100,11 +101,19 @@ private void InitializeComponent() resources.ApplyResources(this.lblThumbnailSizeUnit, "lblThumbnailSizeUnit"); this.lblThumbnailSizeUnit.Name = "lblThumbnailSizeUnit"; // + // cbRememberSearchText + // + resources.ApplyResources(this.cbRememberSearchText, "cbRememberSearchText"); + this.cbRememberSearchText.Name = "cbRememberSearchText"; + this.cbRememberSearchText.UseVisualStyleBackColor = true; + this.cbRememberSearchText.CheckedChanged += new System.EventHandler(this.cbRememberSearchText_CheckedChanged); + // // ImageHistorySettingsForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.Window; + this.Controls.Add(this.cbRememberSearchText); this.Controls.Add(this.lblThumbnailSizeUnit); this.Controls.Add(this.nudMaximumImageLimit); this.Controls.Add(this.nudThumbnailSize); @@ -131,5 +140,6 @@ private void InitializeComponent() private System.Windows.Forms.NumericUpDown nudThumbnailSize; private System.Windows.Forms.NumericUpDown nudMaximumImageLimit; private System.Windows.Forms.Label lblThumbnailSizeUnit; + private System.Windows.Forms.CheckBox cbRememberSearchText; } } \ No newline at end of file diff --git a/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.cs b/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.cs index 51654c459..60a14cb7b 100644 --- a/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.cs +++ b/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.cs @@ -50,6 +50,7 @@ public ImageHistorySettingsForm(ImageHistorySettings settings) cbViewMode.SelectedIndex = Settings.ViewMode; nudThumbnailSize.SetValue(Settings.ThumbnailSize.Width); nudMaximumImageLimit.SetValue(Settings.MaxItemCount); + cbRememberSearchText.Checked = Settings.RememberSearchText; } private void cbViewMode_SelectedIndexChanged(object sender, EventArgs e) @@ -66,5 +67,10 @@ private void nudMaximumImageLimit_ValueChanged(object sender, EventArgs e) { Settings.MaxItemCount = (int)nudMaximumImageLimit.Value; } + + private void cbRememberSearchText_CheckedChanged(object sender, EventArgs e) + { + Settings.RememberSearchText = cbRememberSearchText.Checked; + } } } \ No newline at end of file diff --git a/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.resx b/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.resx index 24dd245c2..743939c4f 100644 --- a/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.resx +++ b/ShareX.HistoryLib/Forms/ImageHistorySettingsForm.resx @@ -144,7 +144,7 @@ $this - 6 + 7 True @@ -171,7 +171,7 @@ $this - 5 + 6 True @@ -198,7 +198,7 @@ $this - 4 + 5 8, 24 @@ -219,7 +219,7 @@ $this - 3 + 4 8, 72 @@ -244,7 +244,7 @@ $this - 2 + 3 8, 120 @@ -268,7 +268,7 @@ $this - 1 + 2 True @@ -295,6 +295,36 @@ $this + 1 + + + True + + + NoControl + + + 8, 152 + + + 132, 17 + + + 7 + + + Remember search text + + + cbRememberSearchText + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 diff --git a/ShareX.HistoryLib/ImageHistorySettings.cs b/ShareX.HistoryLib/ImageHistorySettings.cs index a4cd9ea93..b48d3da72 100644 --- a/ShareX.HistoryLib/ImageHistorySettings.cs +++ b/ShareX.HistoryLib/ImageHistorySettings.cs @@ -39,5 +39,7 @@ public class ImageHistorySettings public int ViewMode { get; set; } = 3; public Size ThumbnailSize { get; set; } = new Size(150, 150); public int MaxItemCount { get; set; } = 250; + public bool RememberSearchText { get; set; } = false; + public string SearchText { get; set; } = ""; } } \ No newline at end of file