From f8bc42085ba1097281c0ae35494e2f8e2aeeef7d Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 27 Sep 2020 15:39:38 +0300 Subject: [PATCH] Added maximum item limit option to history form --- .../Forms/HistoryForm.Designer.cs | 28 +++- ShareX.HistoryLib/Forms/HistoryForm.cs | 30 ++-- ShareX.HistoryLib/Forms/HistoryForm.resx | 141 +++++++++++++----- ShareX.HistoryLib/HistorySettings.cs | 2 +- 4 files changed, 148 insertions(+), 53 deletions(-) diff --git a/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs b/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs index e9f3e4501..a75b60aa6 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs @@ -56,12 +56,15 @@ private void InitializeComponent() this.cbDateFilter = new System.Windows.Forms.CheckBox(); this.dtpFilterTo = new System.Windows.Forms.DateTimePicker(); this.txtFilenameFilter = new System.Windows.Forms.TextBox(); + this.lblMaxItemCount = new System.Windows.Forms.Label(); + this.nudMaxItemCount = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.scMain)).BeginInit(); this.scMain.Panel1.SuspendLayout(); this.scMain.Panel2.SuspendLayout(); this.scMain.SuspendLayout(); this.pStats.SuspendLayout(); this.gbFilters.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nudMaxItemCount)).BeginInit(); this.SuspendLayout(); // // scMain @@ -77,8 +80,10 @@ private void InitializeComponent() // // scMain.Panel2 // - this.scMain.Panel2.Controls.Add(this.btnShowStats); + this.scMain.Panel2.Controls.Add(this.nudMaxItemCount); this.scMain.Panel2.Controls.Add(this.pbThumbnail); + this.scMain.Panel2.Controls.Add(this.btnShowStats); + this.scMain.Panel2.Controls.Add(this.lblMaxItemCount); this.scMain.Panel2.Controls.Add(this.gbFilters); this.scMain.SplitterColor = System.Drawing.Color.White; this.scMain.SplitterLineColor = System.Drawing.Color.FromArgb(((int)(((byte)(189)))), ((int)(((byte)(189)))), ((int)(((byte)(189))))); @@ -257,10 +262,25 @@ private void InitializeComponent() resources.ApplyResources(this.txtFilenameFilter, "txtFilenameFilter"); this.txtFilenameFilter.Name = "txtFilenameFilter"; // + // lblMaxItemCount + // + resources.ApplyResources(this.lblMaxItemCount, "lblMaxItemCount"); + this.lblMaxItemCount.Name = "lblMaxItemCount"; + // + // nudMaxItemCount + // + resources.ApplyResources(this.nudMaxItemCount, "nudMaxItemCount"); + this.nudMaxItemCount.Maximum = new decimal(new int[] { + 10000, + 0, + 0, + 0}); + this.nudMaxItemCount.Name = "nudMaxItemCount"; + this.nudMaxItemCount.ValueChanged += new System.EventHandler(this.nudMaxItemCount_ValueChanged); + // // HistoryForm // resources.ApplyResources(this, "$this"); - this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.BackColor = System.Drawing.SystemColors.Window; this.Controls.Add(this.scMain); @@ -271,11 +291,13 @@ private void InitializeComponent() this.Resize += new System.EventHandler(this.HistoryForm_Resize); this.scMain.Panel1.ResumeLayout(false); this.scMain.Panel2.ResumeLayout(false); + this.scMain.Panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.scMain)).EndInit(); this.scMain.ResumeLayout(false); this.pStats.ResumeLayout(false); this.gbFilters.ResumeLayout(false); this.gbFilters.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nudMaxItemCount)).EndInit(); this.ResumeLayout(false); } @@ -308,5 +330,7 @@ private void InitializeComponent() private System.Windows.Forms.Button btnShowStats; private System.Windows.Forms.RichTextBox rtbStats; private System.Windows.Forms.Panel pStats; + private System.Windows.Forms.Label lblMaxItemCount; + private System.Windows.Forms.NumericUpDown nudMaxItemCount; } } \ No newline at end of file diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index 1d0f9dbf3..ec7d6e059 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -79,6 +79,8 @@ public HistoryForm(string historyPath, HistorySettings settings, Action scMain.SplitterDistance = Settings.SplitterDistance; } + nudMaxItemCount.SetValue(Settings.MaxItemCount); + ShareXResources.ApplyTheme(this); Settings.WindowState.AutoHandleFormState(this); @@ -157,22 +159,23 @@ private HistoryItem[] GetHistoryItems() history = new HistoryManagerJSON(HistoryPath); } - IEnumerable tempHistoryItems = history.GetHistoryItems(); - tempHistoryItems = tempHistoryItems.Reverse(); - - if (Settings.MaxItemCount > 0) - { - tempHistoryItems = tempHistoryItems.Take(Settings.MaxItemCount); - } - - return tempHistoryItems.ToArray(); + List historyItems = history.GetHistoryItems(); + historyItems.Reverse(); + return historyItems.ToArray(); } private void ApplyFiltersAndAdd() { - if (allHistoryItems.Length > 0) + if (allHistoryItems != null && allHistoryItems.Length > 0) { - AddHistoryItems(ApplyFilters(allHistoryItems)); + HistoryItem[] historyItems = ApplyFilters(allHistoryItems); + + if (Settings.MaxItemCount > 0 && historyItems.Length > Settings.MaxItemCount) + { + historyItems = historyItems.Take(Settings.MaxItemCount).ToArray(); + } + + AddHistoryItems(historyItems); } } @@ -421,6 +424,11 @@ private void BtnShowStats_Click(object sender, EventArgs e) } } + private void nudMaxItemCount_ValueChanged(object sender, EventArgs e) + { + Settings.MaxItemCount = (int)nudMaxItemCount.Value; + } + private void lvHistory_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { UpdateControls(); diff --git a/ShareX.HistoryLib/Forms/HistoryForm.resx b/ShareX.HistoryLib/Forms/HistoryForm.resx index ed3de2511..a3dadeb22 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.resx +++ b/ShareX.HistoryLib/Forms/HistoryForm.resx @@ -141,6 +141,9 @@ 1 + + + rtbStats @@ -183,6 +186,9 @@ 0 + + + 24 @@ -220,7 +226,7 @@ lvHistory - ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null + ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.2.2.0, Culture=neutral, PublicKeyToken=null scMain.Panel1 @@ -243,6 +249,57 @@ 100 + + Bottom, Left + + + 224, 576 + + + 80, 20 + + + 7 + + + Center + + + nudMaxItemCount + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + scMain.Panel2 + + + 0 + + + Top, Bottom, Left, Right + + + 8, 8 + + + 404, 352 + + + 3 + + + pbThumbnail + + + ShareX.HelpersLib.MyPictureBox, ShareX.HelpersLib, Version=13.2.2.0, Culture=neutral, PublicKeyToken=null + + + scMain.Panel2 + + + 1 + Bottom, Left @@ -250,7 +307,7 @@ NoControl - 8, 608 + 8, 604 144, 24 @@ -271,34 +328,40 @@ scMain.Panel2 - 0 + 2 - - Top, Bottom, Left, Right + + Bottom, Left - - 8, 8 + + True - - 406, 352 + + 5, 580 - - 3 + + 96, 13 - - pbThumbnail + + 6 - - ShareX.HelpersLib.MyPictureBox, ShareX.HelpersLib, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null + + Maximum item limit: - + + lblMaxItemCount + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + scMain.Panel2 - - 1 + + 3 - Bottom, Left, Right + Bottom, Left True @@ -334,7 +397,7 @@ 96, 44 - 216, 20 + 296, 20 19 @@ -382,10 +445,10 @@ 2 - 168, 168 + 168, 142 - 144, 21 + 224, 21 16 @@ -406,7 +469,7 @@ NoControl - 168, 200 + 168, 168 144, 24 @@ -433,7 +496,7 @@ NoControl - 16, 200 + 16, 168 144, 24 @@ -457,10 +520,10 @@ 5 - 168, 142 + 168, 118 - 144, 21 + 224, 21 11 @@ -484,7 +547,7 @@ NoControl - 16, 170 + 16, 144 51, 17 @@ -514,7 +577,7 @@ NoControl - 16, 144 + 16, 120 53, 17 @@ -538,10 +601,10 @@ 8 - 96, 92 + 168, 70 - 216, 20 + 224, 20 2 @@ -565,7 +628,7 @@ NoControl - 13, 96 + 93, 74 33, 13 @@ -595,7 +658,7 @@ NoControl - 13, 120 + 93, 98 23, 13 @@ -649,10 +712,10 @@ 12 - 96, 116 + 168, 94 - 216, 20 + 224, 20 4 @@ -673,7 +736,7 @@ 96, 20 - 216, 20 + 296, 20 6 @@ -694,7 +757,7 @@ 8, 368 - 406, 234 + 404, 200 4 @@ -712,7 +775,7 @@ scMain.Panel2 - 2 + 4 scMain.Panel2 @@ -745,7 +808,7 @@ scMain - ShareX.HelpersLib.SplitContainerCustomSplitter, ShareX.HelpersLib, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null + ShareX.HelpersLib.SplitContainerCustomSplitter, ShareX.HelpersLib, Version=13.2.2.0, Culture=neutral, PublicKeyToken=null $this @@ -757,7 +820,7 @@ True - 6, 13 + 96, 96 981, 641 diff --git a/ShareX.HistoryLib/HistorySettings.cs b/ShareX.HistoryLib/HistorySettings.cs index 9445a0e7a..534591762 100644 --- a/ShareX.HistoryLib/HistorySettings.cs +++ b/ShareX.HistoryLib/HistorySettings.cs @@ -30,7 +30,7 @@ namespace ShareX.HistoryLib public class HistorySettings { public WindowState WindowState { get; set; } = new WindowState(); - public int MaxItemCount { get; set; } = 0; public int SplitterDistance { get; set; } = 550; + public int MaxItemCount { get; set; } = 0; } } \ No newline at end of file