Compare commits

...

1 commit

Author SHA1 Message Date
Justin Aquadro
08e15c56a2 Started work on better multi-ui support 2013-11-17 12:50:19 -05:00
3 changed files with 406 additions and 121 deletions

View file

@ -0,0 +1,298 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NBTExplorer.Vendor.MultiSelectTreeView;
namespace NBTExplorer.Common
{
abstract class TreeViewController
{
public abstract TreeNodeCollectionController Nodes { get; }
public abstract TreeNodeController SelectedNode { get; set; }
public abstract List<TreeNodeController> SelectedNodes { get; }
public abstract TreeNodeController CreateDefaultNode ();
}
public abstract class TreeNodeController : IEquatable<TreeNodeController>
{
public abstract ContextMenuStrip ContextMenu { get; set; }
public abstract Image Icon { get; set; }
public abstract bool IsExpanded { get; }
public abstract TreeNodeCollectionController Nodes { get; }
public abstract TreeNodeController Parent { get; }
public abstract Image SelectedIcon { get; set; }
public abstract object Tag { get; set; }
public abstract string Text { get; set; }
public abstract void Collapse ();
public abstract void EnsureVisible();
public abstract void Expand ();
public abstract void ExpandAll ();
public abstract void Remove ();
public abstract bool Equals (TreeNodeController other);
}
abstract class TreeNodeCollectionController : IEnumerable<TreeNodeController>
{
public abstract TreeNodeController this[int index] { get; }
public abstract int Count { get; }
public abstract int Add (TreeNodeController node);
public abstract void Clear ();
public abstract void Remove (TreeNodeController node);
public abstract IEnumerator<TreeNodeController> GetEnumerator ();
public virtual int Add ()
{
return Add(new TreeNodeControllerWin());
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
{
return GetEnumerator();
}
}
class TreeNodeControllerWin : TreeNodeController
{
private TreeNode _node;
private TreeNodeCollectionControllerWin _collection;
public TreeNodeControllerWin ()
{
_node = new TreeNode();
_collection = new TreeNodeCollectionControllerWin(_node.Nodes);
}
public TreeNodeControllerWin (TreeNode node)
{
_node = node;
_collection = new TreeNodeCollectionControllerWin(_node.Nodes);
}
public TreeNode Node
{
get { return _node; }
}
public override ContextMenuStrip ContextMenu
{
get { return _node.ContextMenuStrip; }
set { _node.ContextMenuStrip = value; }
}
public override TreeNodeCollectionController Nodes
{
get { return _collection; }
}
public override object Tag
{
get { return _node.Tag; }
set { _node.Tag = value; }
}
public override string Text
{
get { return _node.Text; }
set { _node.Text = value; }
}
public override bool IsExpanded
{
get { return _node.IsExpanded; }
}
public override Image Icon
{
get
{
if (_node.TreeView.ImageList == null)
return null;
if (_node.ImageIndex < 0 || _node.ImageIndex >= _node.TreeView.ImageList.Images.Count)
return null;
return _node.TreeView.ImageList.Images[_node.ImageIndex];
}
set
{
if (_node.TreeView.ImageList == null)
return;
int index = -1;
for (int i = 0; i < _node.TreeView.ImageList.Images.Count; i++) {
if (_node.TreeView.ImageList.Images[i] == value)
index = i;
}
if (index != -1)
_node.ImageIndex = index;
}
}
public override Image SelectedIcon
{
get
{
if (_node.TreeView.ImageList == null)
return null;
if (_node.SelectedImageIndex < 0 || _node.SelectedImageIndex >= _node.TreeView.ImageList.Images.Count)
return null;
return _node.TreeView.ImageList.Images[_node.SelectedImageIndex];
}
set
{
if (_node.TreeView.ImageList == null)
return;
int index = -1;
for (int i = 0; i < _node.TreeView.ImageList.Images.Count; i++) {
if (_node.TreeView.ImageList.Images[i] == value)
index = i;
}
if (index != -1)
_node.SelectedImageIndex = index;
}
}
public override void Collapse ()
{
_node.Collapse();
}
public override void EnsureVisible ()
{
_node.EnsureVisible();
}
public override void Expand ()
{
_node.Expand();
}
public override void ExpandAll ()
{
_node.ExpandAll();
}
public override void Remove ()
{
_node.Remove();
}
public override bool Equals (TreeNodeController other)
{
TreeNodeControllerWin nodewin = other as TreeNodeControllerWin;
if (nodewin == null)
return false;
return _node.Equals(nodewin._node);
}
}
class TreeNodeCollectionControllerWin : TreeNodeCollectionController
{
private TreeNodeCollection _collection;
public TreeNodeCollectionControllerWin (TreeNodeCollection collection)
{
_collection = collection;
}
public override TreeNodeController this[int index]
{
get { return new TreeNodeControllerWin(_collection[index]); }
}
public override int Count
{
get { return _collection.Count; }
}
public override int Add (TreeNodeController node)
{
TreeNodeControllerWin nodewin = node as TreeNodeControllerWin;
if (nodewin == null)
throw new ArgumentException("Expected node to be a Windows concrete type");
return _collection.Add(nodewin.Node);
}
public override void Clear ()
{
_collection.Clear();
}
public override void Remove (TreeNodeController node)
{
TreeNodeControllerWin nodewin = node as TreeNodeControllerWin;
if (nodewin == null)
throw new ArgumentException("Expected node to be a Windows concrete type");
_collection.Remove(nodewin.Node);
}
public override IEnumerator<TreeNodeController> GetEnumerator ()
{
foreach (TreeNode node in _collection)
yield return new TreeNodeControllerWin(node);
}
}
class TreeViewControllerWin : TreeViewController
{
private TreeView _treeView;
private MultiSelectTreeView _multiView;
private TreeNodeCollectionController _collection;
public TreeViewControllerWin (TreeView view)
{
_treeView = view;
_multiView = view as MultiSelectTreeView;
_collection = new TreeNodeCollectionControllerWin(_treeView.Nodes);
}
public override TreeNodeCollectionController Nodes
{
get { return _collection; }
}
public override TreeNodeController SelectedNode
{
get
{
TreeNode selected = (_multiView != null) ? _multiView.SelectedNode : _treeView.SelectedNode;
if (selected == null)
return null;
return new TreeNodeControllerWin(selected);
}
set
{
TreeNodeControllerWin nodewin = value as TreeNodeControllerWin;
if (nodewin == null)
throw new ArgumentException("Expected node to be a Windows concrete type");
if (_multiView != null)
_multiView.SelectedNode = nodewin.Node;
_treeView.SelectedNode = nodewin.Node;
}
}
public override List<TreeNodeController> SelectedNodes
{
get { return null; }
}
public override TreeNodeController CreateDefaultNode ()
{
return new TreeNodeControllerWin();
}
}
}

View file

@ -1,7 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Windows.Forms; using NBTExplorer.Common;
//using System.Windows.Forms;
using NBTExplorer.Model; using NBTExplorer.Model;
using NBTExplorer.Vendor.MultiSelectTreeView; using NBTExplorer.Vendor.MultiSelectTreeView;
using NBTExplorer.Windows; using NBTExplorer.Windows;
@ -22,18 +23,19 @@ namespace NBTExplorer.Controllers
public class NodeTreeController public class NodeTreeController
{ {
private TreeView _nodeTree; //private TreeView _nodeTree;
private MultiSelectTreeView _multiTree; //private MultiSelectTreeView _multiTree;
private TreeViewController _tree;
private IconRegistry _iconRegistry; private IconRegistry _iconRegistry;
//private TagCompoundDataNode _rootData; //private TagCompoundDataNode _rootData;
private RootDataNode _rootData; private RootDataNode _rootData;
public NodeTreeController (TreeView nodeTree) public NodeTreeController (TreeViewController nodeTree)
{ {
_nodeTree = nodeTree; _tree = nodeTree;
_multiTree = nodeTree as MultiSelectTreeView;
InitializeIconRegistry(); InitializeIconRegistry();
ShowVirtualRoot = true; ShowVirtualRoot = true;
@ -48,9 +50,9 @@ namespace NBTExplorer.Controllers
get { return _rootData; } get { return _rootData; }
} }
public TreeView Tree public TreeViewController Tree
{ {
get { return _nodeTree; } get { return _tree; }
} }
public IconRegistry IconRegistry public IconRegistry IconRegistry
@ -58,10 +60,10 @@ namespace NBTExplorer.Controllers
get { return _iconRegistry; } get { return _iconRegistry; }
} }
public ImageList IconList /*public ImageList IconList
{ {
get { return _multiTree.ImageList; } get { return _multiTree.ImageList; }
} }*/
public bool ShowVirtualRoot { get; set; } public bool ShowVirtualRoot { get; set; }
@ -71,8 +73,8 @@ namespace NBTExplorer.Controllers
set set
{ {
_rootData.SetDisplayName(value); _rootData.SetDisplayName(value);
if (ShowVirtualRoot && _nodeTree.Nodes.Count > 0) if (ShowVirtualRoot && _tree.Nodes.Count > 0)
UpdateNodeText(_nodeTree.Nodes[0]); UpdateNodeText(_tree.Nodes[0]);
} }
} }
@ -105,22 +107,16 @@ namespace NBTExplorer.Controllers
} }
private TreeNode SelectedNode private TreeNodeController SelectedNode
{ {
get get { return _tree.SelectedNode; }
{
if (_multiTree != null)
return _multiTree.SelectedNode;
else
return _nodeTree.SelectedNode;
}
} }
#region Load / Save #region Load / Save
public void Save () public void Save ()
{ {
foreach (TreeNode node in _nodeTree.Nodes) { foreach (var node in _tree.Nodes) {
DataNode dataNode = node.Tag as DataNode; DataNode dataNode = node.Tag as DataNode;
if (dataNode != null) if (dataNode != null)
dataNode.Save(); dataNode.Save();
@ -131,14 +127,14 @@ namespace NBTExplorer.Controllers
public int OpenPaths (string[] paths) public int OpenPaths (string[] paths)
{ {
_nodeTree.Nodes.Clear(); _tree.Nodes.Clear();
int failCount = 0; int failCount = 0;
foreach (string path in paths) { foreach (string path in paths) {
if (Directory.Exists(path)) { if (Directory.Exists(path)) {
DirectoryDataNode node = new DirectoryDataNode(path); DirectoryDataNode node = new DirectoryDataNode(path);
_nodeTree.Nodes.Add(CreateUnexpandedNode(node)); _tree.Nodes.Add(CreateUnexpandedNode(node));
} }
else if (File.Exists(path)) { else if (File.Exists(path)) {
DataNode node = null; DataNode node = null;
@ -148,14 +144,14 @@ namespace NBTExplorer.Controllers
} }
if (node != null) if (node != null)
_nodeTree.Nodes.Add(CreateUnexpandedNode(node)); _tree.Nodes.Add(CreateUnexpandedNode(node));
else else
failCount++; failCount++;
} }
} }
if (_nodeTree.Nodes.Count > 0) { if (_tree.Nodes.Count > 0) {
_nodeTree.Nodes[0].Expand(); _tree.Nodes[0].Expand();
} }
OnSelectionInvalidated(); OnSelectionInvalidated();
@ -165,7 +161,7 @@ namespace NBTExplorer.Controllers
#endregion #endregion
public void CreateNode (TreeNode node, TagType type) public void CreateNode (TreeNodeController node, TagType type)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -183,16 +179,16 @@ namespace NBTExplorer.Controllers
public void CreateNode (TagType type) public void CreateNode (TagType type)
{ {
if (SelectedNode == null || _nodeTree.Nodes.Count == 0) if (SelectedNode == null || _tree.Nodes.Count == 0)
return; return;
if (SelectedNode == null) if (SelectedNode == null)
CreateNode(_nodeTree.Nodes[0], type); CreateNode(_tree.Nodes[0], type);
else else
CreateNode(SelectedNode, type); CreateNode(SelectedNode, type);
} }
public void DeleteNode (TreeNode node) public void DeleteNode (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -210,7 +206,7 @@ namespace NBTExplorer.Controllers
} }
} }
private bool DeleteNode (IList<TreeNode> nodes) private bool DeleteNode (IList<TreeNodeController> nodes)
{ {
bool? elideChildren = null; bool? elideChildren = null;
if (!CanOperateOnNodesEx(nodes, Predicates.DeleteNodePred, out elideChildren)) if (!CanOperateOnNodesEx(nodes, Predicates.DeleteNodePred, out elideChildren))
@ -220,7 +216,7 @@ namespace NBTExplorer.Controllers
nodes = ElideChildren(nodes); nodes = ElideChildren(nodes);
bool selectionModified = false; bool selectionModified = false;
foreach (TreeNode node in nodes) { foreach (var node in nodes) {
DataNode dataNode = node.Tag as DataNode; DataNode dataNode = node.Tag as DataNode;
if (dataNode.DeleteNode()) { if (dataNode.DeleteNode()) {
UpdateNodeText(node.Parent); UpdateNodeText(node.Parent);
@ -237,24 +233,19 @@ namespace NBTExplorer.Controllers
return true; return true;
} }
private bool RemoveNodeFromSelection (TreeNode node) private bool RemoveNodeFromSelection (TreeNodeController node)
{ {
bool selectionModified = false; bool selectionModified = false;
if (_multiTree != null) { if (_tree.SelectedNodes != null) {
if (_multiTree.SelectedNodes.Contains(node)) { if (_tree.SelectedNodes.Contains(node)) {
_multiTree.SelectedNodes.Remove(node); _tree.SelectedNodes.Remove(node);
selectionModified = true;
}
if (_multiTree.SelectedNode == node) {
_multiTree.SelectedNode = null;
selectionModified = true; selectionModified = true;
} }
} }
if (_nodeTree.SelectedNode == node) { if (_tree.SelectedNode == node) {
_nodeTree.SelectedNode = null; _tree.SelectedNode = null;
selectionModified = true; selectionModified = true;
} }
@ -263,13 +254,13 @@ namespace NBTExplorer.Controllers
public void DeleteSelection () public void DeleteSelection ()
{ {
if (_multiTree != null) if (_tree.SelectedNodes != null && _tree.SelectedNodes.Count > 0)
DeleteNode(_multiTree.SelectedNodes); DeleteNode(_tree.SelectedNodes);
else else
DeleteNode(SelectedNode); DeleteNode(SelectedNode);
} }
public void EditNode (TreeNode node) public void EditNode (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -289,7 +280,7 @@ namespace NBTExplorer.Controllers
EditNode(SelectedNode); EditNode(SelectedNode);
} }
private void RenameNode (TreeNode node) private void RenameNode (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -309,7 +300,7 @@ namespace NBTExplorer.Controllers
RenameNode(SelectedNode); RenameNode(SelectedNode);
} }
private void RefreshNode (TreeNode node) private void RefreshNode (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -333,7 +324,7 @@ namespace NBTExplorer.Controllers
RefreshNode(SelectedNode); RefreshNode(SelectedNode);
} }
private void ExpandToEdge (TreeNode node) private void ExpandToEdge (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -343,12 +334,12 @@ namespace NBTExplorer.Controllers
if (!node.IsExpanded) if (!node.IsExpanded)
node.Expand(); node.Expand();
foreach (TreeNode child in node.Nodes) foreach (var child in node.Nodes)
ExpandToEdge(child); ExpandToEdge(child);
} }
} }
private void CopyNode (TreeNode node) private void CopyNode (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -360,7 +351,7 @@ namespace NBTExplorer.Controllers
dataNode.CopyNode(); dataNode.CopyNode();
} }
private void CutNode (TreeNode node) private void CutNode (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -378,7 +369,7 @@ namespace NBTExplorer.Controllers
} }
} }
private void PasteNode (TreeNode node) private void PasteNode (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -410,7 +401,7 @@ namespace NBTExplorer.Controllers
PasteNode(SelectedNode); PasteNode(SelectedNode);
} }
public void MoveNodeUp (TreeNode node) public void MoveNodeUp (TreeNodeController node)
{ {
if (node == null) if (node == null)
return; return;
@ -425,7 +416,7 @@ namespace NBTExplorer.Controllers
} }
} }
public void MoveNodeDown (TreeNode node) public void MoveNodeDown (TreeNodeController node)
{ {
if (node == null) if (node == null)
return; return;
@ -458,7 +449,7 @@ namespace NBTExplorer.Controllers
} }
}*/ }*/
public void ExpandNode (TreeNode node) public void ExpandNode (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -485,7 +476,7 @@ namespace NBTExplorer.Controllers
SelectedNode.Expand(); SelectedNode.Expand();
} }
public void CollapseNode (TreeNode node) public void CollapseNode (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -495,11 +486,11 @@ namespace NBTExplorer.Controllers
return; return;
backNode.Collapse(); backNode.Collapse();
node.Name = backNode.NodeDisplay; node.Text = backNode.NodeDisplay;
node.Nodes.Clear(); node.Nodes.Clear();
if (backNode.HasUnexpandedChildren) if (backNode.HasUnexpandedChildren)
node.Nodes.Add(new TreeNode()); node.Nodes.Add();
} }
public void CollapseSelectedNode () public void CollapseSelectedNode ()
@ -507,7 +498,7 @@ namespace NBTExplorer.Controllers
CollapseNode(SelectedNode); CollapseNode(SelectedNode);
} }
private TreeNode GetRootFromDataNodePath (DataNode node, out Stack<DataNode> hierarchy) private TreeNodeController GetRootFromDataNodePath (DataNode node, out Stack<DataNode> hierarchy)
{ {
hierarchy = new Stack<DataNode>(); hierarchy = new Stack<DataNode>();
while (node != null) { while (node != null) {
@ -516,8 +507,8 @@ namespace NBTExplorer.Controllers
} }
DataNode rootDataNode = hierarchy.Pop(); DataNode rootDataNode = hierarchy.Pop();
TreeNode frontNode = null; TreeNodeController frontNode = null;
foreach (TreeNode child in _nodeTree.Nodes) { foreach (var child in _tree.Nodes) {
if (child.Tag == rootDataNode) if (child.Tag == rootDataNode)
frontNode = child; frontNode = child;
} }
@ -525,22 +516,22 @@ namespace NBTExplorer.Controllers
return frontNode; return frontNode;
} }
private TreeNode FindFrontNode (DataNode node) private TreeNodeController FindFrontNode (DataNode node)
{ {
Stack<DataNode> hierarchy; Stack<DataNode> hierarchy;
TreeNode frontNode = GetRootFromDataNodePath(node, out hierarchy); TreeNodeController frontNode = GetRootFromDataNodePath(node, out hierarchy);
if (frontNode == null) if (frontNode == null)
return null; return null;
while (hierarchy.Count > 0) { while (hierarchy.Count > 0) {
if (!frontNode.IsExpanded) { if (!frontNode.IsExpanded) {
frontNode.Nodes.Add(new TreeNode()); frontNode.Nodes.Add();
frontNode.Expand(); frontNode.Expand();
} }
DataNode childData = hierarchy.Pop(); DataNode childData = hierarchy.Pop();
foreach (TreeNode childFront in frontNode.Nodes) { foreach (var childFront in frontNode.Nodes) {
if (childFront.Tag == childData) { if (childFront.Tag == childData) {
frontNode = childFront; frontNode = childFront;
break; break;
@ -554,7 +545,7 @@ namespace NBTExplorer.Controllers
public void CollapseBelow (DataNode node) public void CollapseBelow (DataNode node)
{ {
Stack<DataNode> hierarchy; Stack<DataNode> hierarchy;
TreeNode frontNode = GetRootFromDataNodePath(node, out hierarchy); TreeNodeController frontNode = GetRootFromDataNodePath(node, out hierarchy);
if (frontNode == null) if (frontNode == null)
return; return;
@ -564,7 +555,7 @@ namespace NBTExplorer.Controllers
return; return;
DataNode childData = hierarchy.Pop(); DataNode childData = hierarchy.Pop();
foreach (TreeNode childFront in frontNode.Nodes) { foreach (var childFront in frontNode.Nodes) {
if (childFront.Tag == childData) { if (childFront.Tag == childData) {
frontNode = childFront; frontNode = childFront;
break; break;
@ -578,17 +569,12 @@ namespace NBTExplorer.Controllers
public void SelectNode (DataNode node) public void SelectNode (DataNode node)
{ {
if (_multiTree != null) { _tree.SelectedNode = FindFrontNode(node);
_multiTree.SelectedNode = FindFrontNode(node);
}
else {
_nodeTree.SelectedNode = FindFrontNode(node);
}
} }
public void ScrollNode (DataNode node) public void ScrollNode (DataNode node)
{ {
TreeNode treeNode = FindFrontNode(node); TreeNodeController treeNode = FindFrontNode(node);
if (treeNode != null) if (treeNode != null)
treeNode.EnsureVisible(); treeNode.EnsureVisible();
} }
@ -596,26 +582,26 @@ namespace NBTExplorer.Controllers
public void RefreshRootNodes () public void RefreshRootNodes ()
{ {
if (ShowVirtualRoot) { if (ShowVirtualRoot) {
_nodeTree.Nodes.Clear(); _tree.Nodes.Clear();
_nodeTree.Nodes.Add(CreateUnexpandedNode(_rootData)); _tree.Nodes.Add(CreateUnexpandedNode(_rootData));
return; return;
} }
if (_rootData.HasUnexpandedChildren) if (_rootData.HasUnexpandedChildren)
_rootData.Expand(); _rootData.Expand();
Dictionary<DataNode, TreeNode> currentNodes = new Dictionary<DataNode, TreeNode>(); Dictionary<DataNode, TreeNodeController> currentNodes = new Dictionary<DataNode, TreeNodeController>();
foreach (TreeNode child in _nodeTree.Nodes) { foreach (var child in _tree.Nodes) {
if (child.Tag is DataNode) if (child.Tag is DataNode)
currentNodes.Add(child.Tag as DataNode, child); currentNodes.Add(child.Tag as DataNode, child);
} }
_nodeTree.Nodes.Clear(); _tree.Nodes.Clear();
foreach (DataNode child in _rootData.Nodes) { foreach (DataNode child in _rootData.Nodes) {
if (!currentNodes.ContainsKey(child)) if (!currentNodes.ContainsKey(child))
_nodeTree.Nodes.Add(CreateUnexpandedNode(child)); _tree.Nodes.Add(CreateUnexpandedNode(child));
else else
_nodeTree.Nodes.Add(currentNodes[child]); _tree.Nodes.Add(currentNodes[child]);
} }
//if (_nodeTree.Nodes.Count == 0 && _rootData.HasUnexpandedChildren) { //if (_nodeTree.Nodes.Count == 0 && _rootData.HasUnexpandedChildren) {
@ -624,10 +610,10 @@ namespace NBTExplorer.Controllers
//} //}
} }
public void RefreshChildNodes (TreeNode node, DataNode dataNode) public void RefreshChildNodes (TreeNodeController node, DataNode dataNode)
{ {
Dictionary<DataNode, TreeNode> currentNodes = new Dictionary<DataNode, TreeNode>(); Dictionary<DataNode, TreeNodeController> currentNodes = new Dictionary<DataNode, TreeNodeController>();
foreach (TreeNode child in node.Nodes) { foreach (var child in node.Nodes) {
if (child.Tag is DataNode) if (child.Tag is DataNode)
currentNodes.Add(child.Tag as DataNode, child); currentNodes.Add(child.Tag as DataNode, child);
} }
@ -640,8 +626,8 @@ namespace NBTExplorer.Controllers
node.Nodes.Add(currentNodes[child]); node.Nodes.Add(currentNodes[child]);
} }
foreach (TreeNode child in node.Nodes) foreach (var child in node.Nodes)
child.ContextMenuStrip = BuildNodeContextMenu(child, child.Tag as DataNode); child.ContextMenu = BuildNodeContextMenu(child, child.Tag as DataNode);
if (node.Nodes.Count == 0 && dataNode.HasUnexpandedChildren) { if (node.Nodes.Count == 0 && dataNode.HasUnexpandedChildren) {
ExpandNode(node); ExpandNode(node);
@ -651,7 +637,7 @@ namespace NBTExplorer.Controllers
public void RefreshTreeNode (DataNode dataNode) public void RefreshTreeNode (DataNode dataNode)
{ {
TreeNode node = FindFrontNode(dataNode); TreeNodeController node = FindFrontNode(dataNode);
RefreshChildNodes(node, dataNode); RefreshChildNodes(node, dataNode);
} }
@ -679,7 +665,7 @@ namespace NBTExplorer.Controllers
_iconRegistry.Register(typeof(RootDataNode), 16); _iconRegistry.Register(typeof(RootDataNode), 16);
} }
private void UpdateNodeText (TreeNode node) private void UpdateNodeText (TreeNodeController node)
{ {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return; return;
@ -690,7 +676,7 @@ namespace NBTExplorer.Controllers
public bool CheckModifications () public bool CheckModifications ()
{ {
foreach (TreeNode node in _nodeTree.Nodes) { foreach (var node in _tree.Nodes) {
DataNode dataNode = node.Tag as DataNode; DataNode dataNode = node.Tag as DataNode;
if (dataNode != null && dataNode.IsModified) if (dataNode != null && dataNode.IsModified)
return true; return true;
@ -699,21 +685,21 @@ namespace NBTExplorer.Controllers
return false; return false;
} }
private TreeNode CreateUnexpandedNode (DataNode node) private TreeNodeController CreateUnexpandedNode (DataNode node)
{ {
TreeNode frontNode = new TreeNode(node.NodeDisplay); TreeNodeController frontNode = _tree.CreateDefaultNode();
frontNode.ImageIndex = _iconRegistry.Lookup(node.GetType()); frontNode.Text = node.NodeDisplay;
frontNode.SelectedImageIndex = frontNode.ImageIndex; frontNode.Icon = _iconRegistry.Lookup(node.GetType());
frontNode.SelectedIcon = frontNode.Icon;
frontNode.Tag = node; frontNode.Tag = node;
//frontNode.ContextMenuStrip = BuildNodeContextMenu(node);
if (node.HasUnexpandedChildren || node.Nodes.Count > 0) if (node.HasUnexpandedChildren || node.Nodes.Count > 0)
frontNode.Nodes.Add(new TreeNode()); frontNode.Nodes.Add();
return frontNode; return frontNode;
} }
public ContextMenuStrip BuildNodeContextMenu (TreeNode frontNode, DataNode node) public ContextMenuStrip BuildNodeContextMenu (TreeNodeController frontNode, DataNode node)
{ {
if (node == null) if (node == null)
return null; return null;
@ -756,28 +742,28 @@ namespace NBTExplorer.Controllers
private void _contextCollapse_Click (object sender, EventArgs e) private void _contextCollapse_Click (object sender, EventArgs e)
{ {
if (_multiTree.SelectedNode != null) if (_tree.SelectedNode != null)
_multiTree.SelectedNode.Collapse(); _tree.SelectedNode.Collapse();
} }
private void _contextExpand_Click (object sender, EventArgs e) private void _contextExpand_Click (object sender, EventArgs e)
{ {
if (_multiTree.SelectedNode != null) if (_tree.SelectedNode != null)
_multiTree.SelectedNode.Expand(); _tree.SelectedNode.Expand();
} }
private void _contextExpandChildren_Click (object sender, EventArgs e) private void _contextExpandChildren_Click (object sender, EventArgs e)
{ {
if (_multiTree.SelectedNode != null) { if (_tree.SelectedNode != null) {
foreach (TreeNode node in _multiTree.SelectedNode.Nodes) foreach (var node in _tree.SelectedNode.Nodes)
node.Expand(); node.Expand();
} }
} }
private void _contextExpandTree_Click (object sender, EventArgs e) private void _contextExpandTree_Click (object sender, EventArgs e)
{ {
if (_multiTree.SelectedNode != null) { if (_tree.SelectedNode != null) {
_multiTree.SelectedNode.ExpandAll(); _tree.SelectedNode.ExpandAll();
} }
} }
@ -936,24 +922,24 @@ namespace NBTExplorer.Controllers
public bool CanOperateOnSelection (DataNodePredicate pred) public bool CanOperateOnSelection (DataNodePredicate pred)
{ {
if (_multiTree != null) if (_tree.SelectedNodes != null)
return CanOperateOnNodes(_multiTree.SelectedNodes, pred); return CanOperateOnNodes(_tree.SelectedNodes, pred);
else else
return CanOperateOnNodes(new List<TreeNode>() { _nodeTree.SelectedNode }, pred); return CanOperateOnNodes(new List<TreeNodeController>() { _tree.SelectedNode }, pred);
} }
private bool CanOperateOnNodes (IList<TreeNode> nodes, DataNodePredicate pred) private bool CanOperateOnNodes (IList<TreeNodeController> nodes, DataNodePredicate pred)
{ {
bool? elideChildren = null; bool? elideChildren = null;
return CanOperateOnNodesEx(nodes, pred, out elideChildren); return CanOperateOnNodesEx(nodes, pred, out elideChildren);
} }
private bool CanOperateOnNodesEx (IList<TreeNode> nodes, DataNodePredicate pred, out bool? elideChildren) private bool CanOperateOnNodesEx (IList<TreeNodeController> nodes, DataNodePredicate pred, out bool? elideChildren)
{ {
GroupCapabilities caps = GroupCapabilities.All; GroupCapabilities caps = GroupCapabilities.All;
elideChildren = null; elideChildren = null;
foreach (TreeNode node in nodes) { foreach (var node in nodes) {
if (node == null || !(node.Tag is DataNode)) if (node == null || !(node.Tag is DataNode))
return false; return false;
@ -977,12 +963,12 @@ namespace NBTExplorer.Controllers
return true; return true;
} }
private IList<TreeNode> ElideChildren (IList<TreeNode> nodes) private IList<TreeNodeController> ElideChildren (IList<TreeNodeController> nodes)
{ {
List<TreeNode> filtered = new List<TreeNode>(); List<TreeNodeController> filtered = new List<TreeNodeController>();
foreach (TreeNode node in nodes) { foreach (TreeNodeController node in nodes) {
TreeNode parent = node.Parent; TreeNodeController parent = node.Parent;
bool foundParent = false; bool foundParent = false;
while (parent != null) { while (parent != null) {
@ -1000,10 +986,10 @@ namespace NBTExplorer.Controllers
return filtered; return filtered;
} }
private bool CommonContainer (IEnumerable<TreeNode> nodes) private bool CommonContainer (IEnumerable<TreeNodeController> nodes)
{ {
object container = null; object container = null;
foreach (TreeNode node in nodes) { foreach (var node in nodes) {
DataNode dataNode = node.Tag as DataNode; DataNode dataNode = node.Tag as DataNode;
if (container == null) if (container == null)
container = dataNode.Parent; container = dataNode.Parent;
@ -1015,10 +1001,10 @@ namespace NBTExplorer.Controllers
return true; return true;
} }
private bool CommonType (IEnumerable<TreeNode> nodes) private bool CommonType (IEnumerable<TreeNodeController> nodes)
{ {
Type datatype = null; Type datatype = null;
foreach (TreeNode node in nodes) { foreach (var node in nodes) {
DataNode dataNode = node.Tag as DataNode; DataNode dataNode = node.Tag as DataNode;
if (datatype == null) if (datatype == null)
datatype = dataNode.GetType(); datatype = dataNode.GetType();
@ -1030,7 +1016,7 @@ namespace NBTExplorer.Controllers
return true; return true;
} }
private bool SufficientCapabilities (IEnumerable<TreeNode> nodes, GroupCapabilities commonCaps) private bool SufficientCapabilities (IEnumerable<TreeNodeController> nodes, GroupCapabilities commonCaps)
{ {
bool commonContainer = CommonContainer(nodes); bool commonContainer = CommonContainer(nodes);
bool commonType = CommonType(nodes); bool commonType = CommonType(nodes);

View file

@ -96,8 +96,9 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Common\TreeViewController.cs" />
<Compile Include="Controllers\ExplorerBarController.cs" /> <Compile Include="Controllers\ExplorerBarController.cs" />
<Compile Include="Controllers\NodeTreeController.cs" /> <None Include="Controllers\NodeTreeController.cs" />
<Compile Include="FormRegistry.cs" /> <Compile Include="FormRegistry.cs" />
<Compile Include="Controllers\RuleTreeController.cs" /> <Compile Include="Controllers\RuleTreeController.cs" />
<Compile Include="Model\Search\SearchRule.cs" /> <Compile Include="Model\Search\SearchRule.cs" />