mirror of
https://github.com/jaquadro/NBTExplorer.git
synced 2025-01-09 17:36:25 +00:00
Add new sort order to NBT Tree view.
Compounds first, then lists, then plain old data, then array types.
This commit is contained in:
parent
fc63457d8e
commit
d8229f7ec5
1 changed files with 54 additions and 2 deletions
|
@ -5,7 +5,8 @@ using System.Windows.Forms;
|
||||||
using NBTExplorer.Model;
|
using NBTExplorer.Model;
|
||||||
using NBTExplorer.Vendor.MultiSelectTreeView;
|
using NBTExplorer.Vendor.MultiSelectTreeView;
|
||||||
using NBTExplorer.Windows;
|
using NBTExplorer.Windows;
|
||||||
using Substrate.Nbt;
|
using Substrate.Nbt;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
namespace NBTExplorer.Controllers
|
namespace NBTExplorer.Controllers
|
||||||
{
|
{
|
||||||
|
@ -18,6 +19,56 @@ namespace NBTExplorer.Controllers
|
||||||
{
|
{
|
||||||
Message = message;
|
Message = message;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NodeTreeComparer : IComparer
|
||||||
|
{
|
||||||
|
public int orderForTag(TagType tagID)
|
||||||
|
{
|
||||||
|
switch (tagID)
|
||||||
|
{
|
||||||
|
case TagType.TAG_COMPOUND:
|
||||||
|
return 0;
|
||||||
|
case TagType.TAG_LIST:
|
||||||
|
return 1;
|
||||||
|
case TagType.TAG_BYTE:
|
||||||
|
case TagType.TAG_SHORT:
|
||||||
|
case TagType.TAG_INT:
|
||||||
|
case TagType.TAG_LONG:
|
||||||
|
case TagType.TAG_FLOAT:
|
||||||
|
case TagType.TAG_DOUBLE:
|
||||||
|
case TagType.TAG_STRING:
|
||||||
|
return 2;
|
||||||
|
default:
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Compare(object x, object y)
|
||||||
|
{
|
||||||
|
TreeNode tx = x as TreeNode;
|
||||||
|
TreeNode ty = y as TreeNode;
|
||||||
|
TagDataNode dx = tx.Tag as TagDataNode;
|
||||||
|
TagDataNode dy = ty.Tag as TagDataNode;
|
||||||
|
|
||||||
|
if (dx == null || dy == null)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
if (tagOrder != 0)
|
||||||
|
{
|
||||||
|
return tagOrder;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return dx.NodeDisplay.CompareTo(dy.NodeDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NodeTreeController
|
public class NodeTreeController
|
||||||
|
@ -32,7 +83,8 @@ namespace NBTExplorer.Controllers
|
||||||
|
|
||||||
public NodeTreeController (TreeView nodeTree)
|
public NodeTreeController (TreeView nodeTree)
|
||||||
{
|
{
|
||||||
_nodeTree = nodeTree;
|
_nodeTree = nodeTree;
|
||||||
|
nodeTree.TreeViewNodeSorter = new NodeTreeComparer();
|
||||||
_multiTree = nodeTree as MultiSelectTreeView;
|
_multiTree = nodeTree as MultiSelectTreeView;
|
||||||
|
|
||||||
InitializeIconRegistry();
|
InitializeIconRegistry();
|
||||||
|
|
Loading…
Reference in a new issue