Browse Source

manually merge #488 - Change type search to match FullNames in addition to just the type name

pull/550/head
Siegfried Pammer 11 years ago
parent
commit
d942200adf
  1. 37
      ILSpy/SearchPane.cs
  2. 5
      ILSpy/SearchStrategies.cs

37
ILSpy/SearchPane.cs

@ -55,17 +55,13 @@ namespace ICSharpCode.ILSpy
} }
} }
public const int SearchMode_Type = 0;
public const int SearchMode_Member = 1;
public const int SearchMode_Literal = 2;
private SearchPane() private SearchPane()
{ {
InitializeComponent(); InitializeComponent();
searchModeComboBox.Items.Add(new { Image = Images.Class, Name = "Type" }); searchModeComboBox.Items.Add(new { Image = Images.Class, Name = "Type" });
searchModeComboBox.Items.Add(new { Image = Images.Property, Name = "Member" }); searchModeComboBox.Items.Add(new { Image = Images.Property, Name = "Member" });
searchModeComboBox.Items.Add(new { Image = Images.Literal, Name = "Constant" }); searchModeComboBox.Items.Add(new { Image = Images.Literal, Name = "Constant" });
searchModeComboBox.SelectedIndex = SearchMode_Type; searchModeComboBox.SelectedIndex = (int)SearchMode.Type;
MainWindow.Instance.CurrentAssemblyListChanged += MainWindow_Instance_CurrentAssemblyListChanged; MainWindow.Instance.CurrentAssemblyListChanged += MainWindow_Instance_CurrentAssemblyListChanged;
} }
@ -129,7 +125,7 @@ namespace ICSharpCode.ILSpy
listBox.ItemsSource = null; listBox.ItemsSource = null;
} else { } else {
MainWindow mainWindow = MainWindow.Instance; MainWindow mainWindow = MainWindow.Instance;
currentSearch = new RunningSearch(mainWindow.CurrentAssemblyList.GetAssemblies(), searchTerm, searchModeComboBox.SelectedIndex, mainWindow.CurrentLanguage); currentSearch = new RunningSearch(mainWindow.CurrentAssemblyList.GetAssemblies(), searchTerm, (SearchMode)searchModeComboBox.SelectedIndex, mainWindow.CurrentLanguage);
listBox.ItemsSource = currentSearch.Results; listBox.ItemsSource = currentSearch.Results;
new Thread(currentSearch.Run).Start(); new Thread(currentSearch.Run).Start();
} }
@ -166,13 +162,13 @@ namespace ICSharpCode.ILSpy
{ {
base.OnKeyDown(e); base.OnKeyDown(e);
if (e.Key == Key.T && e.KeyboardDevice.Modifiers == ModifierKeys.Control) { if (e.Key == Key.T && e.KeyboardDevice.Modifiers == ModifierKeys.Control) {
searchModeComboBox.SelectedIndex = SearchMode_Type; searchModeComboBox.SelectedIndex = (int)SearchMode.Type;
e.Handled = true; e.Handled = true;
} else if (e.Key == Key.M && e.KeyboardDevice.Modifiers == ModifierKeys.Control) { } else if (e.Key == Key.M && e.KeyboardDevice.Modifiers == ModifierKeys.Control) {
searchModeComboBox.SelectedIndex = SearchMode_Member; searchModeComboBox.SelectedIndex = (int)SearchMode.Member;
e.Handled = true; e.Handled = true;
} else if (e.Key == Key.S && e.KeyboardDevice.Modifiers == ModifierKeys.Control) { } else if (e.Key == Key.S && e.KeyboardDevice.Modifiers == ModifierKeys.Control) {
searchModeComboBox.SelectedIndex = SearchMode_Literal; searchModeComboBox.SelectedIndex = (int)SearchMode.Literal;
e.Handled = true; e.Handled = true;
} }
} }
@ -192,12 +188,12 @@ namespace ICSharpCode.ILSpy
readonly CancellationTokenSource cts = new CancellationTokenSource(); readonly CancellationTokenSource cts = new CancellationTokenSource();
readonly LoadedAssembly[] assemblies; readonly LoadedAssembly[] assemblies;
readonly string[] searchTerm; readonly string[] searchTerm;
readonly int searchMode; readonly SearchMode searchMode;
readonly Language language; readonly Language language;
public readonly ObservableCollection<SearchResult> Results = new ObservableCollection<SearchResult>(); public readonly ObservableCollection<SearchResult> Results = new ObservableCollection<SearchResult>();
int resultCount; int resultCount;
public RunningSearch(LoadedAssembly[] assemblies, string searchTerm, int searchMode, Language language) public RunningSearch(LoadedAssembly[] assemblies, string searchTerm, SearchMode searchMode, Language language)
{ {
this.dispatcher = Dispatcher.CurrentDispatcher; this.dispatcher = Dispatcher.CurrentDispatcher;
this.assemblies = assemblies; this.assemblies = assemblies;
@ -248,8 +244,8 @@ namespace ICSharpCode.ILSpy
new Action(delegate { this.Results.Insert(this.Results.Count - 1, result); })); new Action(delegate { this.Results.Insert(this.Results.Count - 1, result); }));
cts.Token.ThrowIfCancellationRequested(); cts.Token.ThrowIfCancellationRequested();
} }
AbstractSearchStrategy GetSearchStrategy(int mode, string[] terms) AbstractSearchStrategy GetSearchStrategy(SearchMode mode, string[] terms)
{ {
if (terms.Length == 1) { if (terms.Length == 1) {
if (terms[0].StartsWith("t:")) if (terms[0].StartsWith("t:"))
@ -263,11 +259,11 @@ namespace ICSharpCode.ILSpy
} }
switch (mode) { switch (mode) {
case SearchMode_Type: case SearchMode.Type:
return new TypeSearchStrategy(terms); return new TypeSearchStrategy(terms);
case SearchMode_Member: case SearchMode.Member:
return new MemberSearchStrategy(terms); return new MemberSearchStrategy(terms);
case SearchMode_Literal: case SearchMode.Literal:
return new LiteralSearchStrategy(terms); return new LiteralSearchStrategy(terms);
} }
@ -305,4 +301,11 @@ namespace ICSharpCode.ILSpy
{ {
} }
} }
public enum SearchMode
{
Type,
Member,
Literal
}
} }

5
ILSpy/SearchStrategies.cs

@ -316,9 +316,8 @@ namespace ICSharpCode.ILSpy
public override void Search(TypeDefinition type, Language language, Action<SearchResult> addResult) public override void Search(TypeDefinition type, Language language, Action<SearchResult> addResult)
{ {
if (IsMatch(type.Name)) { if (IsMatch(type.Name) || IsMatch(type.FullName)) {
addResult(new SearchResult addResult(new SearchResult {
{
Member = type, Member = type,
Image = TypeTreeNode.GetIcon(type), Image = TypeTreeNode.GetIcon(type),
Name = language.TypeToString(type, includeNamespace: false), Name = language.TypeToString(type, includeNamespace: false),

Loading…
Cancel
Save