Skip to content

Commit

Permalink
Merge pull request #149 from SlavaRa/develop
Browse files Browse the repository at this point in the history
Ignore case in Outline Mode for Type Explorer
  • Loading branch information
SlavaRa authored Jun 23, 2016
2 parents e3b3f3e + 22cc5ef commit 1a53373
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 136 deletions.
8 changes: 4 additions & 4 deletions QuickNavigate.Tests/Collections/ComparersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public void TestSortNameAndPackage0()
"a.Sprite",
"b.Sprite"
});
List<TypeNode> nodes = matches.Select(match => new TypeNode(new ClassModel() {InFile = FileModel.Ignore}, 0)
var nodes = matches.Select(match => new ClassNode(new ClassModel {InFile = FileModel.Ignore}, 0)
{
Package = match.Substring(0, match.LastIndexOf(".")),
Name = match.Substring(match.LastIndexOf(".") + 1)
}).ToList();
List<TypeNode> nodes0 = nodes.Where(node => node.Name.ToLower() == "sprite").ToList();
List<TypeNode> nodes1 = nodes.Where(node => node.Name.ToLower() != "sprite" && node.Name.ToLower().StartsWith("sprite")).ToList();
List<TypeNode> nodes2 = nodes.Where(node => node.Name.ToLower() != "sprite" && !node.Name.ToLower().StartsWith("sprite")).ToList();
var nodes0 = nodes.Where(node => node.Name.ToLower() == "sprite").ToList();
var nodes1 = nodes.Where(node => node.Name.ToLower() != "sprite" && node.Name.ToLower().StartsWith("sprite")).ToList();
var nodes2 = nodes.Where(node => node.Name.ToLower() != "sprite" && !node.Name.ToLower().StartsWith("sprite")).ToList();
nodes0.Sort(TypeExplorerNodeComparer.Package);
Assert.AreEqual("Sprite", nodes0[0].Name);
Assert.AreEqual("a", nodes0[0].Package);
Expand Down
6 changes: 3 additions & 3 deletions QuickNavigate.Tests/Forms/TypeExplorerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void TestNewTypeNode()
},
Name = "TestClass"
};
TypeNode node = new TypeNode(model, 0);
ClassNode node = new ClassNode(model, 0);
Assert.AreEqual(model, node.Model);
Assert.IsFalse(node.IsPrivate);
Assert.IsNull(node.Module);
Expand All @@ -39,7 +39,7 @@ public void TestNewTypeNodeWithClassFromSWC()
},
Name = "DisplayObject"
};
TypeNode node = new TypeNode(model, 0);
ClassNode node = new ClassNode(model, 0);
Assert.AreEqual("playerglobal.swc", node.Module);
Assert.AreEqual("DisplayObject", node.Text);
Assert.AreEqual("flash.display", node.In);
Expand All @@ -58,7 +58,7 @@ public void TestNewTypeNodeWithPrivateClass()
Name = "TestClass2",
Access = Visibility.Private
};
TypeNode node = new TypeNode(model, 0);
ClassNode node = new ClassNode(model, 0);
Assert.IsTrue(node.IsPrivate);
Assert.AreEqual("TestClass2", node.Text);
Assert.AreEqual("test.TestClass", node.In);
Expand Down
3 changes: 2 additions & 1 deletion QuickNavigate.Tests/QuickNavigate.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>QuickNavigate.Tests</RootNamespace>
<AssemblyName>QuickNavigate.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
12 changes: 6 additions & 6 deletions QuickNavigate/Collections/Comparers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace QuickNavigate.Collections
{
public class NodeNameComparer : IComparer<TypeNode>
public class NodeNameComparer : IComparer<ClassNode>
{
/// <summary>
/// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
Expand All @@ -14,13 +14,13 @@ public class NodeNameComparer : IComparer<TypeNode>
/// Value Condition Less than zero<paramref name="x"/> is less than <paramref name="y"/>.Zero<paramref name="x"/> equals <paramref name="y"/>.Greater than zero<paramref name="x"/> is greater than <paramref name="y"/>.
/// </returns>
/// <param name="x">The first object to compare.</param><param name="y">The second object to compare.</param>
public int Compare(TypeNode x, TypeNode y)
public int Compare(ClassNode x, ClassNode y)
{
return StringComparer.Ordinal.Compare(x.Name.ToLower(), y.Name.ToLower());
}
}

public class NodePackageComparer : IComparer<TypeNode>
public class NodePackageComparer : IComparer<ClassNode>
{
/// <summary>
/// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
Expand All @@ -30,15 +30,15 @@ public class NodePackageComparer : IComparer<TypeNode>
/// Value Condition Less than zero<paramref name="x"/> is less than <paramref name="y"/>.Zero<paramref name="x"/> equals <paramref name="y"/>.Greater than zero<paramref name="x"/> is greater than <paramref name="y"/>.
/// </returns>
/// <param name="x">The first object to compare.</param><param name="y">The second object to compare.</param>
public int Compare(TypeNode x, TypeNode y)
public int Compare(ClassNode x, ClassNode y)
{
return x.Package.Length == y.Package.Length
? StringComparer.Ordinal.Compare(x.Package, y.Package)
: x.Package.Length.CompareTo(y.Package.Length);
}
}

public class NodeNamePackageComparer : IComparer<TypeNode>
public class NodeNamePackageComparer : IComparer<ClassNode>
{
/// <summary>
/// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
Expand All @@ -48,7 +48,7 @@ public class NodeNamePackageComparer : IComparer<TypeNode>
/// Value Condition Less than zero<paramref name="x"/> is less than <paramref name="y"/>.Zero<paramref name="x"/> equals <paramref name="y"/>.Greater than zero<paramref name="x"/> is greater than <paramref name="y"/>.
/// </returns>
/// <param name="x">The first object to compare.</param><param name="y">The second object to compare.</param>
public int Compare(TypeNode x, TypeNode y) => StringComparer.OrdinalIgnoreCase.Compare($"{x.Name}{x.Package}", $"{y.Name}{y.Package}");
public int Compare(ClassNode x, ClassNode y) => StringComparer.OrdinalIgnoreCase.Compare($"{x.Name}{x.Package}", $"{y.Name}{y.Package}");
}

public static class TypeExplorerNodeComparer
Expand Down
4 changes: 2 additions & 2 deletions QuickNavigate/Forms/ClassHierarchyForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected override void ShowContextMenu()
protected override void ShowContextMenu(Point position)
{
if (SelectedNode == null) return;
var classModel = ((TypeNode) SelectedNode).Model;
var classModel = ((ClassNode) SelectedNode).Model;
ContextMenuStrip.Items.Clear();
ContextMenuStrip.Items.Add(QuickContextMenuItem.GotoPositionOrLineMenuItem);
ContextMenuStrip.Items.Add(QuickContextMenuItem.ShowInQuickOutlineMenuItem);
Expand Down Expand Up @@ -251,7 +251,7 @@ protected override void OnKeyDown(KeyEventArgs e)

protected override void OnTreeNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
var node = e.Node as TypeNode;
var node = e.Node as ClassNode;
if (node == null) return;
tree.SelectedNode = node;
base.OnTreeNodeMouseClick(sender, e);
Expand Down
63 changes: 43 additions & 20 deletions QuickNavigate/Forms/Nodes.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,83 @@
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using ASCompletion;
using ASCompletion.Model;
using JetBrains.Annotations;

namespace QuickNavigate.Forms
{
public class TypeNode : TreeNode
public class NodeFactory
{
public static TreeNode CreateTreeNode(FileModel inFile, bool isHaxe, MemberModel it)
{
var flags = it.Flags;
var icon = PluginUI.GetIcon(flags, it.Access);
var constrDecl = isHaxe && (flags & FlagType.Constructor) > 0 ? "new" : it.FullName;
var node = new MemberNode(it.ToString(), icon, icon)
{
InFile = inFile,
Tag = $"{constrDecl}@{it.LineFrom}"
};
return node;
}

public static TreeNode CreateTreeNode(ClassModel classModel)
{
return new ClassNode(classModel, PluginUI.GetIcon(classModel.Flags, classModel.Access));
}
}

public class MemberNode : TreeNode
{
public FileModel InFile;

public MemberNode(string text, int imageIndex, int selectedImageIndex) : base(text, imageIndex, selectedImageIndex)
{
}
}

public class ClassNode : TreeNode
{
public ClassModel Model;
public FileModel InFile;
public new string Name;
public string In;
public string NameInLowercase;
public string Package;
public string Module;
public bool IsPrivate;

public TypeNode([NotNull] ClassModel model, int icon) : this(model, icon, icon)
public ClassNode([NotNull] ClassModel model, int icon) : this(model, icon, icon)
{
}

public TypeNode([NotNull] ClassModel model, int imageIndex, int selectedImageIndex)
public ClassNode([NotNull] ClassModel model, int imageIndex, int selectedImageIndex)
{
Model = model;
Name = model.Name;
var inFile = model.InFile;
Package = inFile != null ? inFile.Package : string.Empty;
InFile = model.InFile;
Package = InFile != null ? InFile.Package : string.Empty;
IsPrivate = (model.Access & Visibility.Private) > 0;
Text = Name;
Tag = "class";
In = Package;
if (!string.IsNullOrEmpty(Package))
{
if (IsPrivate) In = $"{Package}.{Path.GetFileNameWithoutExtension(inFile.FileName)}";
if (IsPrivate) In = $"{Package}.{Path.GetFileNameWithoutExtension(InFile.FileName)}";
}
else if (IsPrivate) In = Path.GetFileNameWithoutExtension(inFile.FileName);
else if (IsPrivate) In = Path.GetFileNameWithoutExtension(InFile.FileName);
ImageIndex = imageIndex;
SelectedImageIndex = selectedImageIndex;
if (inFile == null) return;
var match = Regex.Match(inFile.FileName, @"\S*.swc", RegexOptions.Compiled);
if (InFile == null) return;
var match = Regex.Match(InFile.FileName, @"\S*.swc", RegexOptions.Compiled);
if (match.Success) Module = Path.GetFileName(match.Value);
}
}

public class MemberNode : TreeNode
{
public FileModel InFile;

public MemberNode(string text, int imageIndex, int selectedImageIndex) : base(text, imageIndex, selectedImageIndex)
{
}
}

class ClassHierarchyNode : TypeNode
class ClassHierarchyNode : ClassNode
{
public ClassHierarchyNode(ClassModel model, int imageIndex, int selectedImageIndex)
public ClassHierarchyNode([NotNull] ClassModel model, int imageIndex, int selectedImageIndex)
: base(model, imageIndex, selectedImageIndex)
{
Text = model.Type;
Expand Down
69 changes: 33 additions & 36 deletions QuickNavigate/Forms/QuickOutlineForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using ASCompletion;
using ASCompletion.Context;
using ASCompletion.Model;
using JetBrains.Annotations;
Expand Down Expand Up @@ -101,86 +100,84 @@ void RefreshTree()
{
tree.BeginUpdate();
tree.Nodes.Clear();
FillTree();
FillTree(input.Text.Trim());
tree.ExpandAll();
tree.EndUpdate();
}

void FillTree()
void FillTree(string search)
{
var isHaxe = InFile.haXe;
if (InFile.Members.Count > 0) AddMembers(tree.Nodes, InFile.Members, isHaxe);
foreach (var aClass in InFile.Classes)
if (InFile.Members.Count > 0) FillNodes(tree.Nodes, InFile, InFile.Members, isHaxe, search);
foreach (var classModel in InFile.Classes)
{
var icon = PluginUI.GetIcon(aClass.Flags, aClass.Access);
TreeNode node = new TypeNode(aClass, icon);
var node = NodeFactory.CreateTreeNode(classModel);
tree.Nodes.Add(node);
AddMembers(node.Nodes, aClass.Members, isHaxe, aClass.Equals(InClass));
FillNodes(node.Nodes, InFile, classModel.Members, isHaxe, classModel.Equals(InClass), search);
}
if (SelectedNode != null || tree.Nodes.Count == 0) return;
var search = input.Text.Trim();
if (search.Length == 0)
{
if (InClass.Equals(ClassModel.VoidClass)) tree.SelectedNode = tree.Nodes[0];
else tree.SelectedNode = tree.Nodes.OfType<TypeNode>().FirstOrDefault(it => it.Model.Equals(InClass));
if (InClass.Equals(ClassModel.VoidClass)) tree.SelectedNode = tree.TopNode;
else tree.SelectedNode = tree.Nodes.OfType<ClassNode>().FirstOrDefault(it => it.Model.Equals(InClass));
}
else
{
var nodes = tree.Nodes.OfType<TreeNode>().ToList().FindAll(it =>
var nodes = tree.Nodes.OfType<ClassNode>().ToList().FindAll(it =>
{
var word = ((TypeNode) it).Model.QualifiedName;
var word = it.Model.QualifiedName;
var score = PluginCore.Controls.CompletionList.SmartMatch(word, search, search.Length);
return score > 0 && score < 6;
});
tree.Nodes.Clear();
if (nodes.Count == 0) return;
tree.Nodes.AddRange(nodes.ToArray());
tree.SelectedNode = tree.Nodes[0];
tree.SelectedNode = tree.TopNode;
}
}

void AddMembers(TreeNodeCollection nodes, MemberList members, bool isHaxe)
void FillNodes(TreeNodeCollection nodes, FileModel inFile, MemberList members, bool isHaxe, string search)
{
AddMembers(nodes, members, isHaxe, true);
FillNodes(nodes, inFile, members, isHaxe, true, search);
}

void AddMembers(TreeNodeCollection nodes, MemberList members, bool isHaxe, bool currentClass)
void FillNodes(TreeNodeCollection nodes, FileModel inFile, MemberList members, bool isHaxe, bool currentClass, string search)
{
var items = members.Items.ToList();
if (CurrentFilter != null)
{
var flags = (FlagType) CurrentFilter.Tag;
items.RemoveAll(it => (it.Flags & flags) == 0);
}
var search = input.Text.Trim();
var searchIsNotEmpty = search.Length > 0;
if (searchIsNotEmpty) items = SearchUtil.FindAll(items, search);
var items = FilterTypes(members.Items.ToList());
items = SearchUtil.FindAll(items, search);
foreach (var it in items)
{
var flags = it.Flags;
var icon = PluginUI.GetIcon(flags, it.Access);
var constrDecl = isHaxe && (flags & FlagType.Constructor) > 0 ? "new" : it.FullName;
var node = new TreeNode(it.ToString(), icon, icon) {Tag = $"{constrDecl}@{it.LineFrom}"};
nodes.Add(node);
nodes.Add(NodeFactory.CreateTreeNode(inFile, isHaxe, it));
}
if ((searchIsNotEmpty && SelectedNode == null || currentClass) && nodes.Count > 0)
if ((search.Length > 0 && SelectedNode == null || currentClass) && nodes.Count > 0)
tree.SelectedNode = nodes[0];
}

[NotNull]
List<MemberModel> FilterTypes(List<MemberModel> list)
{
if (CurrentFilter != null)
{
var flags = (FlagType) CurrentFilter.Tag;
list.RemoveAll(it => (it.Flags & flags) == 0);
}
return list;
}

protected override void Navigate()
{
if (SelectedNode != null) DialogResult = DialogResult.OK;
}

protected override void ShowContextMenu()
{
if (!(SelectedNode is TypeNode)) return;
if (!(SelectedNode is ClassNode)) return;
ShowContextMenu(new Point(SelectedNode.Bounds.X, SelectedNode.Bounds.Bottom));
}

protected override void ShowContextMenu(Point position)
{
if (!(SelectedNode is TypeNode)) return;
if (!(SelectedNode is ClassNode)) return;
contextMenu.Items.Clear();
contextMenu.Items.Add(QuickContextMenuItem.ShowInClassHierarchyMenuItem);
contextMenu.Show(tree, position);
Expand Down Expand Up @@ -337,7 +334,7 @@ void OnInputKeyDown(object sender, KeyEventArgs e)
protected override void OnTreeNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button != MouseButtons.Right) return;
TreeNode node = e.Node as TypeNode;
TreeNode node = e.Node as ClassNode;
if (node == null || (string) node.Tag != "class") return;
tree.SelectedNode = node;
ShowContextMenu(new Point(e.Location.X, node.Bounds.Bottom));
Expand All @@ -364,7 +361,7 @@ void OnTreeDrawNode(object sender, DrawTreeNodeEventArgs e)
graphics.FillRectangle(new SolidBrush(fillBrush), x, bounds.Y, itemWidth, tree.ItemHeight);
var text = e.Node.Text;
graphics.DrawString(text, font, new SolidBrush(textBrush), bounds.Left, bounds.Top, StringFormat.GenericDefault);
var node = e.Node as TypeNode;
var node = e.Node as ClassNode;
if (node == null) return;
if (!string.IsNullOrEmpty(node.In))
{
Expand Down
Loading

0 comments on commit 1a53373

Please sign in to comment.