mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Code refactoring
This commit is contained in:
parent
96480288cd
commit
2fdee81291
2 changed files with 16 additions and 24 deletions
|
@ -52,19 +52,6 @@ public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first,
|
|
||||||
IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
|
|
||||||
{
|
|
||||||
using (IEnumerator<TFirst> e1 = first.GetEnumerator())
|
|
||||||
using (IEnumerator<TSecond> e2 = second.GetEnumerator())
|
|
||||||
{
|
|
||||||
while (e1.MoveNext() && e2.MoveNext())
|
|
||||||
{
|
|
||||||
yield return resultSelector(e1.Current, e2.Current);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] GetBytes(this Image img)
|
public static byte[] GetBytes(this Image img)
|
||||||
{
|
{
|
||||||
using (MemoryStream ms = new MemoryStream())
|
using (MemoryStream ms = new MemoryStream())
|
||||||
|
|
|
@ -43,7 +43,7 @@ public partial class HistoryForm : Form
|
||||||
private HistoryItem[] allHistoryItems;
|
private HistoryItem[] allHistoryItems;
|
||||||
private string defaultTitle;
|
private string defaultTitle;
|
||||||
private Dictionary<string, string> typeNamesLocaleLookup;
|
private Dictionary<string, string> typeNamesLocaleLookup;
|
||||||
string[] cbTypeFilterSelectionLocalized;
|
private string[] allTypeNames;
|
||||||
|
|
||||||
public HistoryForm(string historyPath, HistorySettings settings, Action<string> uploadFile = null, Action<string> editImage = null)
|
public HistoryForm(string historyPath, HistorySettings settings, Action<string> uploadFile = null, Action<string> editImage = null)
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ public HistoryForm(string historyPath, HistorySettings settings, Action<string>
|
||||||
|
|
||||||
string[] typeNames = Enum.GetNames(typeof(EDataType));
|
string[] typeNames = Enum.GetNames(typeof(EDataType));
|
||||||
string[] typeTranslations = Helpers.GetLocalizedEnumDescriptions<EDataType>();
|
string[] typeTranslations = Helpers.GetLocalizedEnumDescriptions<EDataType>();
|
||||||
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();
|
UpdateTitle();
|
||||||
|
|
||||||
|
@ -122,15 +122,17 @@ private void RefreshHistoryItems(bool mockData = false)
|
||||||
allHistoryItems = GetHistoryItems(mockData);
|
allHistoryItems = GetHistoryItems(mockData);
|
||||||
ApplyFilterSimple();
|
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();
|
allTypeNames = allHistoryItems.Select(x => x.Type).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray();
|
||||||
cbTypeFilterSelection.Items.Clear();
|
cbTypeFilterSelection.Items.AddRange(allTypeNames.Select(x => typeNamesLocaleLookup.TryGetValue(x, out string value) ? value : x).ToArray());
|
||||||
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());
|
cbHostFilterSelection.Items.AddRange(allHistoryItems.Select(x => x.Host).Distinct().Where(x => !string.IsNullOrEmpty(x)).ToArray());
|
||||||
ResetFilters();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResetFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
private HistoryItem[] him_GetHistoryItems()
|
private HistoryItem[] him_GetHistoryItems()
|
||||||
|
@ -197,13 +199,16 @@ private void ApplyFilterAdvanced()
|
||||||
FilterDate = cbDateFilter.Checked,
|
FilterDate = cbDateFilter.Checked,
|
||||||
FromDate = dtpFilterFrom.Value.Date,
|
FromDate = dtpFilterFrom.Value.Date,
|
||||||
ToDate = dtpFilterTo.Value.Date,
|
ToDate = dtpFilterTo.Value.Date,
|
||||||
FilterType = cbTypeFilter.Checked,
|
|
||||||
FilterHost = cbHostFilter.Checked,
|
FilterHost = cbHostFilter.Checked,
|
||||||
Host = cbHostFilterSelection.Text,
|
Host = cbHostFilterSelection.Text,
|
||||||
MaxItemCount = Settings.MaxItemCount
|
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);
|
ApplyFilter(filter);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue