diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index b8e85abc2..87d8c88d8 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -42,7 +42,7 @@ namespace ShareX.HistoryLib public bool Favorites { get; private set; } private HistoryItemManager him; - private HistoryItem[] allHistoryItems; + private List allHistoryItems; private HistoryItem[] filteredHistoryItems; private string defaultTitle; private Dictionary typeNamesLocaleLookup; @@ -138,7 +138,7 @@ namespace ShareX.HistoryLib cbHostFilterSelection.Items.Clear(); tstbSearch.AutoCompleteCustomSource.Clear(); - if (allHistoryItems.Length > 0) + if (allHistoryItems.Count > 0) { allTypeNames = allHistoryItems.Select(x => x.Type).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToArray(); cbTypeFilterSelection.Items.AddRange(allTypeNames.Select(x => typeNamesLocaleLookup.TryGetValue(x, out string value) ? value : x).ToArray()); @@ -193,7 +193,7 @@ namespace ShareX.HistoryLib await RefreshHistoryItems(); } - private async Task GetHistoryItems(bool mockData = false) + private async Task> GetHistoryItems(bool mockData = false) { HistoryManager history; @@ -210,12 +210,12 @@ namespace ShareX.HistoryLib List historyItems = await history.GetHistoryItemsAsync(); historyItems.Reverse(); - return historyItems.ToArray(); + return historyItems; } private void ApplyFilter(HistoryFilter filter) { - if (allHistoryItems != null && allHistoryItems.Length > 0) + if (allHistoryItems != null && allHistoryItems.Count > 0) { IEnumerable historyItems = filter.ApplyFilter(allHistoryItems); filteredHistoryItems = historyItems.ToArray(); @@ -345,9 +345,9 @@ namespace ShareX.HistoryLib StringBuilder status = new StringBuilder(); status.Append(" ("); - status.AppendFormat(Resources.HistoryForm_UpdateItemCount_Total___0_, allHistoryItems.Length.ToString("N0")); + status.AppendFormat(Resources.HistoryForm_UpdateItemCount_Total___0_, allHistoryItems.Count.ToString("N0")); - if (allHistoryItems.Length > historyItems.Length) + if (allHistoryItems.Count > historyItems.Length) { status.AppendFormat(" - " + Resources.HistoryForm_UpdateItemCount___Filtered___0_, historyItems.Length.ToString("N0")); } @@ -401,67 +401,6 @@ namespace ShareX.HistoryLib } } - private string OutputStats(HistoryItem[] historyItems) - { - string empty = "(empty)"; - - StringBuilder sb = new StringBuilder(); - - sb.AppendLine(Resources.HistoryItemCounts); - sb.AppendLine(Resources.HistoryStats_Total + " " + historyItems.Length); - - IEnumerable types = historyItems. - GroupBy(x => x.Type). - OrderByDescending(x => x.Count()). - Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Length * 100)); - - sb.AppendLine(string.Join(Environment.NewLine, types)); - - sb.AppendLine(); - sb.AppendLine(Resources.HistoryStats_YearlyUsages); - - IEnumerable yearlyUsages = historyItems. - GroupBy(x => x.DateTime.Year). - OrderByDescending(x => x.Key). - Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Length * 100)); - - sb.AppendLine(string.Join(Environment.NewLine, yearlyUsages)); - - sb.AppendLine(); - sb.AppendLine(Resources.HistoryStats_FileExtensions); - - IEnumerable fileExtensions = historyItems. - Where(x => !string.IsNullOrEmpty(x.FileName) && !x.FileName.EndsWith(")")). - Select(x => FileHelpers.GetFileNameExtension(x.FileName)). - GroupBy(x => string.IsNullOrWhiteSpace(x) ? empty : x). - OrderByDescending(x => x.Count()). - Select(x => string.Format("[{0}] {1}", x.Count(), x.Key)); - - sb.AppendLine(string.Join(Environment.NewLine, fileExtensions)); - - sb.AppendLine(); - sb.AppendLine(Resources.HistoryStats_Hosts); - - IEnumerable hosts = historyItems. - GroupBy(x => string.IsNullOrWhiteSpace(x.Host) ? empty : x.Host). - OrderByDescending(x => x.Count()). - Select(x => string.Format("[{0}] {1}", x.Count(), x.Key)); - - sb.AppendLine(string.Join(Environment.NewLine, hosts)); - - sb.AppendLine(); - sb.AppendLine(Resources.ProcessNames); - - IEnumerable processNames = historyItems. - GroupBy(x => string.IsNullOrWhiteSpace(x.TagsProcessName) ? empty : x.TagsProcessName). - OrderByDescending(x => x.Count()). - Select(x => string.Format("[{0}] {1}", x.Count(), x.Key)); - - sb.Append(string.Join(Environment.NewLine, processNames)); - - return sb.ToString(); - } - #region Form events private async void HistoryForm_Shown(object sender, EventArgs e) @@ -526,7 +465,7 @@ namespace ShareX.HistoryLib private void tsbShowStats_Click(object sender, EventArgs e) { - string stats = OutputStats(allHistoryItems); + string stats = HistoryHelpers.OutputStats(allHistoryItems); OutputBox.Show(stats, Resources.HistoryStats); } diff --git a/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs b/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs index 6e5bb8859..8993e05e6 100644 --- a/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs +++ b/ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs @@ -28,10 +28,10 @@ /// private void InitializeComponent() { - Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader5 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.Name, "Name", 100, 0, true); - Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader6 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.FileSize, "Size", 100, 1, true); - Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader7 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.Dimensions, "Dimensions", 100, 2, true); - Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader8 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.FilePath, "Path", 100, 3, true); + Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader13 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.Name, "Name", 100, 0, true); + Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader14 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.FileSize, "Size", 100, 1, true); + Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader15 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.Dimensions, "Dimensions", 100, 2, true); + Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader16 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.FilePath, "Path", 100, 3, true); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ImageHistoryForm)); tscMain = new System.Windows.Forms.ToolStripContainer(); ilvImages = new Manina.Windows.Forms.ImageListView(); @@ -39,9 +39,11 @@ tslSearch = new System.Windows.Forms.ToolStripLabel(); tstbSearch = new System.Windows.Forms.ToolStripTextBox(); tsbSearch = new System.Windows.Forms.ToolStripButton(); + tsbFavorites = new System.Windows.Forms.ToolStripButton(); tss1 = new System.Windows.Forms.ToolStripSeparator(); tsbSettings = new System.Windows.Forms.ToolStripButton(); - tsbFavorites = new System.Windows.Forms.ToolStripButton(); + tss2 = new System.Windows.Forms.ToolStripSeparator(); + tsbShowStats = new System.Windows.Forms.ToolStripButton(); tscMain.ContentPanel.SuspendLayout(); tscMain.TopToolStripPanel.SuspendLayout(); tscMain.SuspendLayout(); @@ -69,27 +71,27 @@ ilvImages.AllowItemReorder = false; ilvImages.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; ilvImages.CacheLimit = "100MB"; - imageListViewColumnHeader5.Comparer = null; - imageListViewColumnHeader5.DisplayIndex = 0; - imageListViewColumnHeader5.Grouper = null; - imageListViewColumnHeader5.Key = ""; - imageListViewColumnHeader5.Type = Manina.Windows.Forms.ColumnType.Name; - imageListViewColumnHeader6.Comparer = null; - imageListViewColumnHeader6.DisplayIndex = 1; - imageListViewColumnHeader6.Grouper = null; - imageListViewColumnHeader6.Key = ""; - imageListViewColumnHeader6.Type = Manina.Windows.Forms.ColumnType.FileSize; - imageListViewColumnHeader7.Comparer = null; - imageListViewColumnHeader7.DisplayIndex = 2; - imageListViewColumnHeader7.Grouper = null; - imageListViewColumnHeader7.Key = ""; - imageListViewColumnHeader7.Type = Manina.Windows.Forms.ColumnType.Dimensions; - imageListViewColumnHeader8.Comparer = null; - imageListViewColumnHeader8.DisplayIndex = 3; - imageListViewColumnHeader8.Grouper = null; - imageListViewColumnHeader8.Key = ""; - imageListViewColumnHeader8.Type = Manina.Windows.Forms.ColumnType.FilePath; - ilvImages.Columns.AddRange(new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader[] { imageListViewColumnHeader5, imageListViewColumnHeader6, imageListViewColumnHeader7, imageListViewColumnHeader8 }); + imageListViewColumnHeader13.Comparer = null; + imageListViewColumnHeader13.DisplayIndex = 0; + imageListViewColumnHeader13.Grouper = null; + imageListViewColumnHeader13.Key = ""; + imageListViewColumnHeader13.Type = Manina.Windows.Forms.ColumnType.Name; + imageListViewColumnHeader14.Comparer = null; + imageListViewColumnHeader14.DisplayIndex = 1; + imageListViewColumnHeader14.Grouper = null; + imageListViewColumnHeader14.Key = ""; + imageListViewColumnHeader14.Type = Manina.Windows.Forms.ColumnType.FileSize; + imageListViewColumnHeader15.Comparer = null; + imageListViewColumnHeader15.DisplayIndex = 2; + imageListViewColumnHeader15.Grouper = null; + imageListViewColumnHeader15.Key = ""; + imageListViewColumnHeader15.Type = Manina.Windows.Forms.ColumnType.Dimensions; + imageListViewColumnHeader16.Comparer = null; + imageListViewColumnHeader16.DisplayIndex = 3; + imageListViewColumnHeader16.Grouper = null; + imageListViewColumnHeader16.Key = ""; + imageListViewColumnHeader16.Type = Manina.Windows.Forms.ColumnType.FilePath; + ilvImages.Columns.AddRange(new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader[] { imageListViewColumnHeader13, imageListViewColumnHeader14, imageListViewColumnHeader15, imageListViewColumnHeader16 }); resources.ApplyResources(ilvImages, "ilvImages"); ilvImages.Name = "ilvImages"; ilvImages.ThumbnailSize = new System.Drawing.Size(100, 100); @@ -102,7 +104,7 @@ // resources.ApplyResources(tsMain, "tsMain"); tsMain.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; - tsMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { tslSearch, tstbSearch, tsbSearch, tsbFavorites, tss1, tsbSettings }); + tsMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { tslSearch, tstbSearch, tsbSearch, tss1, tsbFavorites, tsbShowStats, tss2, tsbSettings }); tsMain.Name = "tsMain"; // // tslSearch @@ -127,6 +129,15 @@ tsbSearch.Name = "tsbSearch"; tsbSearch.Click += tsbSearch_Click; // + // tsbFavorites + // + tsbFavorites.CheckOnClick = true; + tsbFavorites.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + tsbFavorites.Image = Properties.Resources.star; + resources.ApplyResources(tsbFavorites, "tsbFavorites"); + tsbFavorites.Name = "tsbFavorites"; + tsbFavorites.Click += tsbFavorites_Click; + // // tss1 // tss1.Name = "tss1"; @@ -140,14 +151,18 @@ tsbSettings.Name = "tsbSettings"; tsbSettings.Click += tsbSettings_Click; // - // tsbFavorites + // tss2 // - tsbFavorites.CheckOnClick = true; - tsbFavorites.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; - tsbFavorites.Image = Properties.Resources.star; - resources.ApplyResources(tsbFavorites, "tsbFavorites"); - tsbFavorites.Name = "tsbFavorites"; - tsbFavorites.Click += tsbFavorites_Click; + tss2.Name = "tss2"; + resources.ApplyResources(tss2, "tss2"); + // + // tsbShowStats + // + tsbShowStats.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + tsbShowStats.Image = Properties.Resources.chart; + resources.ApplyResources(tsbShowStats, "tsbShowStats"); + tsbShowStats.Name = "tsbShowStats"; + tsbShowStats.Click += tsbShowStats_Click; // // ImageHistoryForm // @@ -181,5 +196,7 @@ private System.Windows.Forms.ToolStripSeparator tss1; private System.Windows.Forms.ToolStripButton tsbSettings; private System.Windows.Forms.ToolStripButton tsbFavorites; + private System.Windows.Forms.ToolStripSeparator tss2; + private System.Windows.Forms.ToolStripButton tsbShowStats; } } \ No newline at end of file diff --git a/ShareX.HistoryLib/Forms/ImageHistoryForm.cs b/ShareX.HistoryLib/Forms/ImageHistoryForm.cs index de3b6f163..373a18287 100644 --- a/ShareX.HistoryLib/Forms/ImageHistoryForm.cs +++ b/ShareX.HistoryLib/Forms/ImageHistoryForm.cs @@ -314,6 +314,12 @@ namespace ShareX.HistoryLib await RefreshHistoryItems(false); } + private void tsbShowStats_Click(object sender, EventArgs e) + { + string stats = HistoryHelpers.OutputStats(allHistoryItems); + OutputBox.Show(stats, Resources.HistoryStats); + } + private void tsbSettings_Click(object sender, EventArgs e) { using (ImageHistorySettingsForm form = new ImageHistorySettingsForm(Settings)) diff --git a/ShareX.HistoryLib/Forms/ImageHistoryForm.resx b/ShareX.HistoryLib/Forms/ImageHistoryForm.resx index 3cb902718..4f3f479e3 100644 --- a/ShareX.HistoryLib/Forms/ImageHistoryForm.resx +++ b/ShareX.HistoryLib/Forms/ImageHistoryForm.resx @@ -234,6 +234,9 @@ Search + + 6, 25 + Magenta @@ -243,7 +246,16 @@ Favorites - + + Magenta + + + 23, 22 + + + Show stats... + + 6, 25 @@ -259,7 +271,7 @@ 3, 0 - 456, 25 + 485, 25 0 @@ -333,6 +345,12 @@ System.Windows.Forms.ToolStripButton, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsbFavorites + + + System.Windows.Forms.ToolStripButton, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + tss1 @@ -345,10 +363,16 @@ System.Windows.Forms.ToolStripButton, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tsbFavorites + + tss2 - + + System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsbShowStats + + System.Windows.Forms.ToolStripButton, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/ShareX.HistoryLib/HistoryHelpers.cs b/ShareX.HistoryLib/HistoryHelpers.cs new file mode 100644 index 000000000..0d7b0bc2a --- /dev/null +++ b/ShareX.HistoryLib/HistoryHelpers.cs @@ -0,0 +1,98 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2025 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; +using ShareX.HistoryLib.Properties; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ShareX.HistoryLib +{ + public static class HistoryHelpers + { + public static string OutputStats(List historyItems) + { + string empty = "(empty)"; + + StringBuilder sb = new StringBuilder(); + + sb.AppendLine(Resources.HistoryItemCounts); + sb.AppendLine(Resources.HistoryStats_Total + " " + historyItems.Count); + + IEnumerable types = historyItems. + GroupBy(x => x.Type). + OrderByDescending(x => x.Count()). + Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Count * 100)); + + sb.AppendLine(string.Join(Environment.NewLine, types)); + + sb.AppendLine(); + sb.AppendLine(Resources.HistoryStats_YearlyUsages); + + IEnumerable yearlyUsages = historyItems. + GroupBy(x => x.DateTime.Year). + OrderByDescending(x => x.Key). + Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Count * 100)); + + sb.AppendLine(string.Join(Environment.NewLine, yearlyUsages)); + + sb.AppendLine(); + sb.AppendLine(Resources.HistoryStats_FileExtensions); + + IEnumerable fileExtensions = historyItems. + Where(x => !string.IsNullOrEmpty(x.FileName) && !x.FileName.EndsWith(")")). + Select(x => FileHelpers.GetFileNameExtension(x.FileName)). + GroupBy(x => string.IsNullOrWhiteSpace(x) ? empty : x). + OrderByDescending(x => x.Count()). + Select(x => string.Format("[{0}] {1}", x.Count(), x.Key)); + + sb.AppendLine(string.Join(Environment.NewLine, fileExtensions)); + + sb.AppendLine(); + sb.AppendLine(Resources.HistoryStats_Hosts); + + IEnumerable hosts = historyItems. + GroupBy(x => string.IsNullOrWhiteSpace(x.Host) ? empty : x.Host). + OrderByDescending(x => x.Count()). + Select(x => string.Format("[{0}] {1}", x.Count(), x.Key)); + + sb.AppendLine(string.Join(Environment.NewLine, hosts)); + + sb.AppendLine(); + sb.AppendLine(Resources.ProcessNames); + + IEnumerable processNames = historyItems. + GroupBy(x => string.IsNullOrWhiteSpace(x.TagsProcessName) ? empty : x.TagsProcessName). + OrderByDescending(x => x.Count()). + Select(x => string.Format("[{0}] {1}", x.Count(), x.Key)); + + sb.Append(string.Join(Environment.NewLine, processNames)); + + return sb.ToString(); + } + } +} \ No newline at end of file