Skip to content

Commit

Permalink
Respect filter options for default filters (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
srwi committed Sep 14, 2024
1 parent a322bf6 commit e32dd20
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 72 deletions.
24 changes: 17 additions & 7 deletions EverythingToolbar/Data/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
public class Filter
{
public string Name { get; set; }
public string Icon { get; set; }
public bool IsMatchCase { get; set; }
public bool IsMatchWholeWord { get; set; }
public bool IsMatchPath { get; set; }
public bool IsRegExEnabled { get; set; }
public string Search { get; set; }
public string Macro { get; set; }
public string Icon { get; set; } = "";
public string Search { get; set; } = "";
public string Macro { get; set; } = "";
public bool IsMatchCase { get; set; } = false;
public bool IsMatchWholeWord { get; set; } = false;
public bool IsMatchPath { get; set; } = false;
public bool IsRegExEnabled { get; set; } = false;

public override bool Equals(object obj)
{
Expand All @@ -26,6 +26,16 @@ public override int GetHashCode()
return Name.GetHashCode();
}

public void Reset()
{
IsMatchCase = false;
IsMatchWholeWord = false;
IsMatchPath = false;
IsRegExEnabled = false;
Search = "";
Macro = "";
}

public string GetSearchPrefix()
{
if (string.IsNullOrEmpty(Search))
Expand Down
8 changes: 6 additions & 2 deletions EverythingToolbar/EverythingSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")

private void OnSettingChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ToolbarSettings.User.IsRegExEnabled))
if (e.PropertyName == nameof(ToolbarSettings.User.IsRegExEnabled) ||
e.PropertyName == nameof(ToolbarSettings.User.IsImportFilters))
{
CurrentFilter = FilterLoader.Instance.DefaultFilters[0];
}

if (e.PropertyName == nameof(ToolbarSettings.User.IsMatchCase) ||
e.PropertyName == nameof(ToolbarSettings.User.IsRegExEnabled) ||
Expand All @@ -122,7 +125,8 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e)
e.PropertyName == nameof(ToolbarSettings.User.IsHideEmptySearchResults) ||
e.PropertyName == nameof(ToolbarSettings.User.SortBy) ||
e.PropertyName == nameof(ToolbarSettings.User.IsSortDescending) ||
e.PropertyName == nameof(ToolbarSettings.User.IsThumbnailsEnabled))
e.PropertyName == nameof(ToolbarSettings.User.IsThumbnailsEnabled) ||
e.PropertyName == nameof(ToolbarSettings.User.IsImportFilters))
{
QueryBatch(append: false);
}
Expand Down
109 changes: 46 additions & 63 deletions EverythingToolbar/Helpers/FilterLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using Castle.Core.Internal;
using EverythingToolbar.Data;
using EverythingToolbar.Properties;
using Microsoft.VisualBasic.FileIO;
Expand All @@ -18,32 +19,16 @@ internal class FilterLoader : INotifyPropertyChanged
{
new Filter {
Name = Resources.DefaultFilterAll,
Icon = Utils.GetWindowsVersion() >= Utils.WindowsVersion.Windows10 ? "\xE71D " : "",
IsMatchCase = false,
IsMatchWholeWord = false,
IsMatchPath = false,
IsRegExEnabled = false,
Macro = "",
Search = ""
Icon = Utils.GetWindowsVersion() >= Utils.WindowsVersion.Windows10 ? "\xE71D " : ""
},
new Filter {
Name = Resources.DefaultFilterFile,
Icon = Utils.GetWindowsVersion() >= Utils.WindowsVersion.Windows10 ? "\xE7C3 " : "",
IsMatchCase = false,
IsMatchWholeWord = false,
IsMatchPath = false,
IsRegExEnabled = false,
Macro = "",
Search = "file:"
},
new Filter {
Name = Resources.DefaultFilterFolder,
Icon = Utils.GetWindowsVersion() >= Utils.WindowsVersion.Windows10 ? "\xE8B7 " : "",
IsMatchCase = false,
IsMatchWholeWord = false,
IsMatchPath = false,
IsRegExEnabled = false,
Macro = "",
Search = "folder:"
}
};
Expand All @@ -62,63 +47,42 @@ public ObservableCollection<Filter> DefaultFilters
{
new Filter {
Name = Resources.UserFilterAudio,
Icon = "",
IsMatchCase = false,
IsMatchWholeWord = false,
IsMatchPath = false,
IsRegExEnabled = false,
Macro = "audio",
Search = "ext:aac;ac3;aif;aifc;aiff;au;cda;dts;fla;flac;it;m1a;m2a;m3u;m4a;mid;midi;mka;mod;mp2;mp3;mpa;ogg;ra;rmi;spc;rmi;snd;umx;voc;wav;wma;xm"
Search = "ext:aac;ac3;aif;aifc;aiff;au;cda;dts;fla;flac;it;m1a;m2a;m3u;m4a;mid;" +
"midi;mka;mod;mp2;mp3;mpa;ogg;ra;rmi;spc;rmi;snd;umx;voc;wav;wma;xm"
},
new Filter {
Name = Resources.UserFilterCompressed,
Icon = "",
IsMatchCase = false,
IsMatchWholeWord = false,
IsMatchPath = false,
IsRegExEnabled = false,
Macro = "zip",
Search = "ext:7z;ace;arj;bz2;cab;gz;gzip;jar;r00;r01;r02;r03;r04;r05;r06;r07;r08;r09;r10;r11;r12;r13;r14;r15;r16;r17;r18;r19;r20;r21;r22;r23;r24;r25;r26;r27;r28;r29;rar;tar;tgz;z;zip"
Search = "ext:7z;ace;arj;bz2;cab;gz;gzip;jar;r00;r01;r02;r03;r04;r05;r06;r07;" +
"r08;r09;r10;r11;r12;r13;r14;r15;r16;r17;r18;r19;r20;r21;r22;r23;r24;" +
"r25;r26;r27;r28;r29;rar;tar;tgz;z;zip"
},
new Filter {
Name = Resources.UserFilterDocument,
Icon = "",
IsMatchCase = false,
IsMatchWholeWord = false,
IsMatchPath = false,
IsRegExEnabled = false,
Macro = "doc",
Search = "ext:c;chm;cpp;csv;cxx;doc;docm;docx;dot;dotm;dotx;h;hpp;htm;html;hxx;ini;java;lua;mht;mhtml;odt;pdf;potx;potm;ppam;ppsm;ppsx;pps;ppt;pptm;pptx;rtf;sldm;sldx;thmx;txt;vsd;wpd;wps;wri;xlam;xls;xlsb;xlsm;xlsx;xltm;xltx;xml"
Search = "ext:c;chm;cpp;csv;cxx;doc;docm;docx;dot;dotm;dotx;h;hpp;htm;html;hxx;" +
"ini;java;lua;mht;mhtml;odt;pdf;potx;potm;ppam;ppsm;ppsx;pps;ppt;pptm;" +
"pptx;rtf;sldm;sldx;thmx;txt;vsd;wpd;wps;wri;xlam;xls;xlsb;xlsm;xlsx;xltm;xltx;xml"
},
new Filter {
Name = Resources.UserFilterExecutable,
Icon = "",
IsMatchCase = false,
IsMatchWholeWord = false,
IsMatchPath = false,
IsRegExEnabled = false,
Macro = "exe",
Search = "ext:bat;cmd;exe;msi;msp;scr"
},
new Filter {
Name = Resources.UserFilterPicture,
Icon = "",
IsMatchCase = false,
IsMatchWholeWord = false,
IsMatchPath = false,
IsRegExEnabled = false,
Macro = "pic",
Search = "ext:ani;bmp;gif;ico;jpe;jpeg;jpg;pcx;png;psd;tga;tif;tiff;webp;wmf"
},
new Filter {
Name = Resources.UserFilterVideo,
Icon = "",
IsMatchCase = false,
IsMatchWholeWord = false,
IsMatchPath = false,
IsRegExEnabled = false,
Macro = "video",
Search = "ext:3g2;3gp;3gp2;3gpp;amr;amv;asf;avi;bdmv;bik;d2v;divx;drc;dsa;dsm;dss;dsv;evo;f4v;flc;fli;flic;flv;hdmov;ifo;ivf;m1v;m2p;m2t;m2ts;m2v;m4b;m4p;m4v;mkv;mp2v;mp4;mp4v;mpe;mpeg;mpg;mpls;mpv2;mpv4;mov;mts;ogm;ogv;pss;pva;qt;ram;ratdvd;rm;rmm;rmvb;roq;rpm;smil;smk;swf;tp;tpr;ts;vob;vp6;webm;wm;wmp;wmv"
Search = "ext:3g2;3gp;3gp2;3gpp;amr;amv;asf;avi;bdmv;bik;d2v;divx;drc;dsa;dsm;" +
"dss;dsv;evo;f4v;flc;fli;flic;flv;hdmov;ifo;ivf;m1v;m2p;m2t;m2ts;m2v;" +
"m4b;m4p;m4v;mkv;mp2v;mp4;mp4v;mpe;mpeg;mpg;mpls;mpv2;mpv4;mov;mts;ogm;" +
"ogv;pss;pva;qt;ram;ratdvd;rm;rmm;rmvb;roq;rpm;smil;smk;swf;tp;tpr;ts;" +
"vob;vp6;webm;wm;wmp;wmv"
}
};
private ObservableCollection<Filter> _userFiltersCache;
Expand All @@ -129,10 +93,10 @@ public ObservableCollection<Filter> UserFilters
if (ToolbarSettings.User.IsRegExEnabled)
return new ObservableCollection<Filter>();

if (ToolbarSettings.User.IsImportFilters)
return _userFiltersCache ?? LoadFilters();
if (ToolbarSettings.User.IsImportFilters && _userFiltersCache.IsNullOrEmpty())
LoadFilters();

return DefaultUserFilters;
return _userFiltersCache ?? DefaultUserFilters;
}
}

Expand All @@ -145,8 +109,8 @@ private FilterLoader()
{
if (ToolbarSettings.User.FiltersPath == "")
ToolbarSettings.User.FiltersPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Everything",
"Filters.csv");
"Everything",
"Filters.csv");
ToolbarSettings.User.PropertyChanged += OnSettingsChanged;

NotifyFiltersChanged();
Expand Down Expand Up @@ -177,6 +141,8 @@ private void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
{
StopFileWatcher();
_userFiltersCache = null;
foreach (var filter in DefaultFilters)
filter.Reset();
}

NotifyFiltersChanged();
Expand All @@ -191,7 +157,7 @@ private void NotifyFiltersChanged()
NotifyPropertyChanged(nameof(UserFilters));
}

private ObservableCollection<Filter> LoadFilters()
private void LoadFilters()
{
var filters = new ObservableCollection<Filter>();

Expand All @@ -217,7 +183,7 @@ private ObservableCollection<Filter> LoadFilters()
else
{
ToolbarSettings.User.IsImportFilters = false;
return DefaultUserFilters;
return;
}
}
}
Expand All @@ -241,9 +207,26 @@ private ObservableCollection<Filter> LoadFilters()

var filter = header.Zip(fields, (h, f) => new { h, f }).ToDictionary(x => x.h, x => x.f);

// Skip default filters
if (filter["Name"] == "EVERYTHING" || filter["Name"] == "FOLDER")
if (filter["Name"] == "EVERYTHING")
{
_defaultFilters[0].IsMatchCase = filter["Case"] == "1";
_defaultFilters[0].IsMatchWholeWord = filter["Whole Word"] == "1";
_defaultFilters[0].IsMatchPath = filter["Path"] == "1";
_defaultFilters[0].IsRegExEnabled = filter["Regex"] == "1";
_defaultFilters[0].Search = filter["Search"];
_defaultFilters[0].Macro = filter["Macro"];
continue;
}
if (filter["Name"] == "FOLDER")
{
_defaultFilters[2].IsMatchCase = filter["Case"] == "1";
_defaultFilters[2].IsMatchWholeWord = filter["Whole Word"] == "1";
_defaultFilters[2].IsMatchPath = filter["Path"] == "1";
_defaultFilters[2].IsRegExEnabled = filter["Regex"] == "1";
_defaultFilters[2].Search = filter["Search"];
_defaultFilters[2].Macro = filter["Macro"];
continue;
}

// Everything's default filters are uppercase
filter["Name"] = filter["Name"].Replace("AUDIO", Resources.UserFilterAudio);
Expand All @@ -265,15 +248,13 @@ private ObservableCollection<Filter> LoadFilters()
});
}
}
_userFiltersCache = filters;
}
catch (Exception e)
{
Logger.Error(e, "Parsing Filters.csv failed.");
return DefaultUserFilters;
}

_userFiltersCache = filters;
return filters;
}

private void StopFileWatcher()
Expand Down Expand Up @@ -310,12 +291,14 @@ private void OnFileRenamed(object sender, RenamedEventArgs e)
CreateFileWatcher();
LoadFilters();
NotifyFiltersChanged();
EverythingSearch.Instance.Reset();
}

private void OnFileChanged(object source, FileSystemEventArgs e)
{
LoadFilters();
NotifyFiltersChanged();
EverythingSearch.Instance.Reset();
}

public Filter GetLastFilter()
Expand Down

0 comments on commit e32dd20

Please sign in to comment.