Browse Source

Added an option to filter GAC entries by version in addition to name.

pull/112/head
Artur Zgodziski 15 years ago
parent
commit
a2e11b76be
  1. 32
      ILSpy/OpenFromGacDialog.xaml.cs

32
ILSpy/OpenFromGacDialog.xaml.cs

@ -39,6 +39,7 @@ namespace ICSharpCode.ILSpy
{ {
ObservableCollection<GacEntry> gacEntries = new ObservableCollection<GacEntry>(); ObservableCollection<GacEntry> gacEntries = new ObservableCollection<GacEntry>();
ObservableCollection<GacEntry> filteredEntries = new ObservableCollection<GacEntry>(); ObservableCollection<GacEntry> filteredEntries = new ObservableCollection<GacEntry>();
Predicate<GacEntry> filterMethod = _ => true;
volatile bool cancelFetchThread; volatile bool cancelFetchThread;
public OpenFromGacDialog() public OpenFromGacDialog()
@ -62,6 +63,7 @@ namespace ICSharpCode.ILSpy
{ {
readonly AssemblyNameReference r; readonly AssemblyNameReference r;
readonly string fileName; readonly string fileName;
string formattedVersion;
public GacEntry(AssemblyNameReference r, string fileName) public GacEntry(AssemblyNameReference r, string fileName)
{ {
@ -85,6 +87,14 @@ namespace ICSharpCode.ILSpy
get { return r.Version; } get { return r.Version; }
} }
public string FormattedVersion {
get {
if (formattedVersion == null)
formattedVersion = Version.ToString();
return formattedVersion;
}
}
public string Culture { public string Culture {
get { return r.Culture; } get { return r.Culture; }
} }
@ -132,20 +142,28 @@ namespace ICSharpCode.ILSpy
void AddNewEntry(GacEntry entry) void AddNewEntry(GacEntry entry)
{ {
gacEntries.Add(entry); gacEntries.Add(entry);
string filter = filterTextBox.Text; if (filterMethod(entry))
if (string.IsNullOrEmpty(filter) || entry.ShortName.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)
filteredEntries.Add(entry); filteredEntries.Add(entry);
} }
#endregion #endregion
void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e) void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
{ {
string filter = filterTextBox.Text; string filterString = filterTextBox.Text.Trim();
filteredEntries.Clear(); if (filterString.Length == 0)
foreach (GacEntry entry in gacEntries) { filterMethod = _ => true;
if (string.IsNullOrEmpty(filter) || entry.ShortName.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0) else {
filteredEntries.Add(entry); var elements = filterString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
filterMethod = entry => elements.All(el => Contains(entry.FullName, el) || Contains(entry.FormattedVersion, el));
} }
filteredEntries.Clear();
filteredEntries.AddRange(gacEntries.Where(entry => filterMethod(entry)));
}
static bool Contains(string s, string subString)
{
return s.IndexOf(subString, StringComparison.OrdinalIgnoreCase) >= 0;
} }
void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)

Loading…
Cancel
Save