diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index 0920fe9e3..e1bb17feb 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -42,6 +42,8 @@ public partial class HistoryForm : Form private HistoryItemManager him; private HistoryItem[] allHistoryItems; private string defaultTitle; + private Dictionary typeNamesLocaleLookup; + string[] cbTypeFilterSelectionLocalized; public HistoryForm(string historyPath, HistorySettings settings, Action uploadFile = null, Action editImage = null) { @@ -52,6 +54,11 @@ public HistoryForm(string historyPath, HistorySettings settings, Action tsHistory.Renderer = new ToolStripRoundedEdgeRenderer(); defaultTitle = Text; + + string[] typeNames = Enum.GetNames(typeof(EDataType)); + string[] typeTranslations = Helpers.GetLocalizedEnumDescriptions(); + typeNamesLocaleLookup = Enumerable.Zip(typeNames, typeTranslations, (key, val) => new { key, val }).ToDictionary(e => e.key, e => e.val); + UpdateTitle(); // Mark the Date column as having a date; used for sorting @@ -114,6 +121,16 @@ private void RefreshHistoryItems(bool mockData = false) { allHistoryItems = GetHistoryItems(mockData); ApplyFilterSimple(); + + if (lvHistory.Items.Count > 0) + { + cbTypeFilterSelectionLocalized = allHistoryItems.Select(x => x.Type).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray(); + cbTypeFilterSelection.Items.Clear(); + cbTypeFilterSelection.Items.AddRange(cbTypeFilterSelectionLocalized.Select(x => typeNamesLocaleLookup.TryGetValue(x, out string value) ? value : x).ToArray()); + cbHostFilterSelection.Items.Clear(); + cbHostFilterSelection.Items.AddRange(allHistoryItems.Select(x => x.Host).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray()); + ResetFilters(); + } } private HistoryItem[] him_GetHistoryItems() @@ -181,11 +198,12 @@ private void ApplyFilterAdvanced() FromDate = dtpFilterFrom.Value.Date, ToDate = dtpFilterTo.Value.Date, FilterType = cbTypeFilter.Checked, - Type = cbTypeFilterSelection.Text, FilterHost = cbHostFilter.Checked, Host = cbHostFilterSelection.Text, MaxItemCount = Settings.MaxItemCount }; + if (cbTypeFilterSelectionLocalized.IsValidIndex(cbTypeFilterSelection.SelectedIndex)) + filter.Type = cbTypeFilterSelectionLocalized[cbTypeFilterSelection.SelectedIndex]; ApplyFilter(filter); } @@ -256,14 +274,10 @@ private void UpdateTitle(HistoryItem[] historyItems = null) status.AppendFormat(" - " + Resources.HistoryForm_UpdateItemCount___Filtered___0_, historyItems.Length.ToString("N0")); } - string[] typeNames = Enum.GetNames(typeof(EDataType)); - string[] typeTranslations = Helpers.GetLocalizedEnumDescriptions(); - Dictionary lookup = Enumerable.Zip(typeNames, typeTranslations, (key, val) => new { key, val }).ToDictionary(e => e.key, e => e.val); - IEnumerable types = historyItems. GroupBy(x => x.Type). OrderByDescending(x => x.Count()). - Select(x => string.Format(" - {0}: {1}", lookup.TryGetValue(x.Key, out string value) ? value : x.Key, x.Count())); + Select(x => string.Format(" - {0}: {1}", typeNamesLocaleLookup.TryGetValue(x.Key, out string value) ? value : x.Key, x.Count())); foreach (string type in types) { @@ -368,15 +382,6 @@ private void HistoryForm_Shown(object sender, EventArgs e) RefreshHistoryItems(); - if (lvHistory.Items.Count > 0) - { - cbTypeFilterSelection.Items.Clear(); - cbTypeFilterSelection.Items.AddRange(allHistoryItems.Select(x => x.Type).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray()); - cbHostFilterSelection.Items.Clear(); - cbHostFilterSelection.Items.AddRange(allHistoryItems.Select(x => x.Host).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray()); - ResetFilters(); - } - this.ForceActivate(); }