diff --git a/ShareX.HelpersLib/Extensions/Extensions.cs b/ShareX.HelpersLib/Extensions/Extensions.cs index 4c9ba9e99..8ec804d9c 100644 --- a/ShareX.HelpersLib/Extensions/Extensions.cs +++ b/ShareX.HelpersLib/Extensions/Extensions.cs @@ -52,19 +52,6 @@ public static void ForEach(this IEnumerable source, Action action) } } - public static IEnumerable Zip(this IEnumerable first, - IEnumerable second, Func resultSelector) - { - using (IEnumerator e1 = first.GetEnumerator()) - using (IEnumerator e2 = second.GetEnumerator()) - { - while (e1.MoveNext() && e2.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current); - } - } - } - public static byte[] GetBytes(this Image img) { using (MemoryStream ms = new MemoryStream()) diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index e1bb17feb..dc8a04e26 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -43,7 +43,7 @@ public partial class HistoryForm : Form private HistoryItem[] allHistoryItems; private string defaultTitle; private Dictionary typeNamesLocaleLookup; - string[] cbTypeFilterSelectionLocalized; + private string[] allTypeNames; public HistoryForm(string historyPath, HistorySettings settings, Action uploadFile = null, Action editImage = null) { @@ -57,7 +57,7 @@ public HistoryForm(string historyPath, HistorySettings settings, Action 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); + typeNamesLocaleLookup = typeNames.Zip(typeTranslations, (key, val) => new { key, val }).ToDictionary(e => e.key, e => e.val); UpdateTitle(); @@ -122,15 +122,17 @@ private void RefreshHistoryItems(bool mockData = false) allHistoryItems = GetHistoryItems(mockData); ApplyFilterSimple(); - if (lvHistory.Items.Count > 0) + cbTypeFilterSelection.Items.Clear(); + cbHostFilterSelection.Items.Clear(); + + if (allHistoryItems.Length > 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(); + allTypeNames = allHistoryItems.Select(x => x.Type).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray(); + cbTypeFilterSelection.Items.AddRange(allTypeNames.Select(x => typeNamesLocaleLookup.TryGetValue(x, out string value) ? value : x).ToArray()); cbHostFilterSelection.Items.AddRange(allHistoryItems.Select(x => x.Host).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray()); - ResetFilters(); } + + ResetFilters(); } private HistoryItem[] him_GetHistoryItems() @@ -197,13 +199,16 @@ private void ApplyFilterAdvanced() FilterDate = cbDateFilter.Checked, FromDate = dtpFilterFrom.Value.Date, ToDate = dtpFilterTo.Value.Date, - FilterType = cbTypeFilter.Checked, FilterHost = cbHostFilter.Checked, Host = cbHostFilterSelection.Text, MaxItemCount = Settings.MaxItemCount }; - if (cbTypeFilterSelectionLocalized.IsValidIndex(cbTypeFilterSelection.SelectedIndex)) - filter.Type = cbTypeFilterSelectionLocalized[cbTypeFilterSelection.SelectedIndex]; + + if (cbTypeFilter.Checked && allTypeNames.IsValidIndex(cbTypeFilterSelection.SelectedIndex)) + { + filter.FilterType = true; + filter.Type = allTypeNames[cbTypeFilterSelection.SelectedIndex]; + } ApplyFilter(filter); }