From cf7893b6cbffd4f083c67c810a83f09bd98c1141 Mon Sep 17 00:00:00 2001 From: Jaex Date: Tue, 9 Apr 2019 12:04:07 +0300 Subject: [PATCH] Support wildcard in image history form search --- ShareX.HistoryLib/Forms/HistoryForm.cs | 2 +- ShareX.HistoryLib/Forms/ImageHistoryForm.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index 00af465c2..615fc1926 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -151,7 +151,7 @@ private HistoryItem[] ApplyFilters(HistoryItem[] historyItems) if (!string.IsNullOrEmpty(filenameFilter)) { string pattern = Regex.Escape(filenameFilter).Replace("\\?", ".").Replace("\\*", ".*"); - Regex regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); + Regex regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); result = result.Where(x => x.Filename != null && regex.IsMatch(x.Filename)); } diff --git a/ShareX.HistoryLib/Forms/ImageHistoryForm.cs b/ShareX.HistoryLib/Forms/ImageHistoryForm.cs index 7ff922c6b..75919541e 100644 --- a/ShareX.HistoryLib/Forms/ImageHistoryForm.cs +++ b/ShareX.HistoryLib/Forms/ImageHistoryForm.cs @@ -29,6 +29,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Windows.Forms; using View = Manina.Windows.Forms.View; @@ -106,12 +107,20 @@ private IEnumerable GetHistoryItems() List historyItems = history.GetHistoryItems(); List filteredHistoryItems = new List(); + Regex regex = null; + + if (!string.IsNullOrEmpty(SearchText)) + { + string pattern = Regex.Escape(SearchText).Replace("\\?", ".").Replace("\\*", ".*"); + regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); + } + for (int i = historyItems.Count - 1; i >= 0; i--) { HistoryItem hi = historyItems[i]; if (!string.IsNullOrEmpty(hi.Filepath) && Helpers.IsImageFile(hi.Filepath) && - (string.IsNullOrEmpty(SearchText) || hi.Filename.Contains(SearchText, StringComparison.InvariantCultureIgnoreCase)) && + (regex == null || regex.IsMatch(hi.Filename)) && (!Settings.FilterMissingFiles || File.Exists(hi.Filepath))) { filteredHistoryItems.Add(hi);