Support wildcard in image history form search

This commit is contained in:
Jaex 2019-04-09 12:04:07 +03:00
parent 457e13b7bb
commit cf7893b6cb
2 changed files with 11 additions and 2 deletions

View file

@ -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));
}

View file

@ -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<HistoryItem> GetHistoryItems()
List<HistoryItem> historyItems = history.GetHistoryItems();
List<HistoryItem> filteredHistoryItems = new List<HistoryItem>();
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);