From 5c328322816ea896295a387ba786ac5e7563c171 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Wed, 25 Feb 2015 23:32:57 -1000 Subject: [PATCH] Make directories sort before files in sort order. Change identifiers to match existing style. --- NBTExplorer/Controllers/NodeTreeController.cs | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/NBTExplorer/Controllers/NodeTreeController.cs b/NBTExplorer/Controllers/NodeTreeController.cs index b02b07f..7173a03 100644 --- a/NBTExplorer/Controllers/NodeTreeController.cs +++ b/NBTExplorer/Controllers/NodeTreeController.cs @@ -23,7 +23,7 @@ namespace NBTExplorer.Controllers public class NodeTreeComparer : IComparer { - public int orderForTag(TagType tagID) + public int OrderForTag(TagType tagID) { switch (tagID) { @@ -44,6 +44,18 @@ namespace NBTExplorer.Controllers } } + public int OrderForNode(object node) + { + if (node is DirectoryDataNode) + { + return 0; + } + else + { + return 1; + } + } + public int Compare(object x, object y) { TreeNode tx = x as TreeNode; @@ -53,12 +65,20 @@ namespace NBTExplorer.Controllers if (dx == null || dy == null) { - return tx.Text.CompareTo(ty.Text); + int nodeOrder = this.OrderForNode(tx.Tag).CompareTo(this.OrderForNode(ty.Tag)); + if (nodeOrder != 0) + { + return nodeOrder; + } + else + { + return tx.Text.CompareTo(ty.Text); + } } TagType idx = dx.Tag.GetTagType(); TagType idy = dy.Tag.GetTagType(); - int tagOrder = this.orderForTag(idx).CompareTo(this.orderForTag(idy)); + int tagOrder = this.OrderForTag(idx).CompareTo(this.OrderForTag(idy)); if (tagOrder != 0) { return tagOrder;