Skip to content

Commit

Permalink
fix #214 - GUI - Search for: "Everything"
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedpammer committed Apr 27, 2016
1 parent 2e04f29 commit a2cbd6d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ILSpy/SearchPane.cs
Expand Up @@ -58,14 +58,15 @@ public partial class SearchPane : UserControl, IPane
private SearchPane()
{
InitializeComponent();
searchModeComboBox.Items.Add(new { Image = Images.Library, Name = "Types and Members" });
searchModeComboBox.Items.Add(new { Image = Images.Class, Name = "Type" });
searchModeComboBox.Items.Add(new { Image = Images.Property, Name = "Member" });
searchModeComboBox.Items.Add(new { Image = Images.Method, Name = "Method" });
searchModeComboBox.Items.Add(new { Image = Images.Field, Name = "Field" });
searchModeComboBox.Items.Add(new { Image = Images.Property, Name = "Property" });
searchModeComboBox.Items.Add(new { Image = Images.Event, Name = "Event" });
searchModeComboBox.Items.Add(new { Image = Images.Literal, Name = "Constant" });
searchModeComboBox.SelectedIndex = (int)SearchMode.Type;
searchModeComboBox.SelectedIndex = (int)SearchMode.TypeAndMember;
ContextMenuProvider.Add(listBox);

MainWindow.Instance.CurrentAssemblyListChanged += MainWindow_Instance_CurrentAssemblyListChanged;
Expand Down Expand Up @@ -253,6 +254,9 @@ void AddResult(SearchResult result)
AbstractSearchStrategy GetSearchStrategy(SearchMode mode, string[] terms)
{
if (terms.Length == 1) {
if (terms[0].StartsWith("tm:", StringComparison.Ordinal))
return new TypeAndMemberSearchStrategy(terms[0].Substring(3));

if (terms[0].StartsWith("t:", StringComparison.Ordinal))
return new TypeSearchStrategy(terms[0].Substring(2));

Expand All @@ -277,6 +281,8 @@ AbstractSearchStrategy GetSearchStrategy(SearchMode mode, string[] terms)

switch (mode)
{
case SearchMode.TypeAndMember:
return new TypeAndMemberSearchStrategy(terms);
case SearchMode.Type:
return new TypeSearchStrategy(terms);
case SearchMode.Member:
Expand Down Expand Up @@ -333,6 +339,7 @@ public ShowSearchCommand()

public enum SearchMode
{
TypeAndMember,
Type,
Member,
Method,
Expand Down
49 changes: 49 additions & 0 deletions ILSpy/SearchStrategies.cs
Expand Up @@ -373,4 +373,53 @@ public override void Search(TypeDefinition type, Language language, Action<Searc
}
}

class TypeAndMemberSearchStrategy : AbstractSearchStrategy
{
public TypeAndMemberSearchStrategy(params string[] terms)
: base(terms)
{
}

public override void Search(TypeDefinition type, Language language, Action<SearchResult> addResult)
{
if (IsMatch(type.Name) || IsMatch(type.FullName))
{
addResult(new SearchResult
{
Member = type,
Image = TypeTreeNode.GetIcon(type),
Name = language.TypeToString(type, includeNamespace: false),
LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace,
Location = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace
});
}

foreach (TypeDefinition nestedType in type.NestedTypes)
{
Search(nestedType, language, addResult);
}

base.Search(type, language, addResult);
}

protected override bool IsMatch(FieldDefinition field)
{
return IsMatch(field.Name);
}

protected override bool IsMatch(PropertyDefinition property)
{
return IsMatch(property.Name);
}

protected override bool IsMatch(EventDefinition ev)
{
return IsMatch(ev.Name);
}

protected override bool IsMatch(MethodDefinition m)
{
return IsMatch(m.Name);
}
}
}

0 comments on commit a2cbd6d

Please sign in to comment.