mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Support wildcard in image history form search
This commit is contained in:
parent
457e13b7bb
commit
cf7893b6cb
2 changed files with 11 additions and 2 deletions
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue