diff --git a/Controllers/ExplorerBarController.cs b/Controllers/ExplorerBarController.cs new file mode 100644 index 0000000..49d35a0 --- /dev/null +++ b/Controllers/ExplorerBarController.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; +using NBTExplorer.Model; +using NBTExplorer.Windows; + +namespace NBTExplorer.Controllers +{ + class ExplorerBarController + { + private ToolStrip _explorerStrip; + private DataNode _rootNode; + private IconRegistry _registry; + private ImageList _iconList; + + public ExplorerBarController (ToolStrip toolStrip, IconRegistry registry, ImageList iconList, DataNode rootNode) + { + _explorerStrip = toolStrip; + _registry = registry; + _iconList = iconList; + _rootNode = rootNode; + + Initialize(); + } + + private void Initialize () + { + _explorerStrip.Items.Clear(); + + List ancestry = new List(); + DataNode node = _rootNode; + + while (node != null) { + ancestry.Add(node); + node = node.Parent; + } + + ancestry.Reverse(); + + foreach (DataNode item in ancestry) { + ToolStripSplitButton itemButton = new ToolStripSplitButton(item.NodePathName) { + Tag = item, + }; + itemButton.ButtonClick += (s, e) => { + ToolStripSplitButton button = s as ToolStripSplitButton; + if (button != null) + SearchRoot = button.Tag as DataNode; + }; + itemButton.DropDown.ImageList = _iconList; + + if (_explorerStrip.Items.Count == 0) + itemButton.ImageIndex = _registry.Lookup(item.GetType()); + + if (!item.IsExpanded) + item.Expand(); + + foreach (DataNode subItem in item.Nodes) { + if (!subItem.IsContainerType) + continue; + + ToolStripMenuItem menuItem = new ToolStripMenuItem(subItem.NodePathName) { + ImageIndex = _registry.Lookup(subItem.GetType()), + Tag = subItem, + }; + menuItem.Click += (s, e) => { + ToolStripMenuItem mItem = s as ToolStripMenuItem; + if (mItem != null) + SearchRoot = mItem.Tag as DataNode; + }; + + if (ancestry.Contains(subItem)) + menuItem.Font = new Font(menuItem.Font, FontStyle.Bold); + + itemButton.DropDownItems.Add(menuItem); + } + + _explorerStrip.Items.Add(itemButton); + } + } + + public DataNode SearchRoot + { + get { return _rootNode; } + set + { + if (_rootNode == value) + return; + + _rootNode = value; + Initialize(); + + OnSearchRootChanged(); + } + } + + public event EventHandler SearchRootChanged; + + protected virtual void OnSearchRootChanged () + { + var ev = SearchRootChanged; + if (ev != null) + ev(this, EventArgs.Empty); + } + } +} diff --git a/Controllers/NodeTreeController.cs b/Controllers/NodeTreeController.cs index ce8a2a4..3179027 100644 --- a/Controllers/NodeTreeController.cs +++ b/Controllers/NodeTreeController.cs @@ -1,12 +1,11 @@ using System; using System.Collections.Generic; -using System.Text; +using System.IO; using System.Windows.Forms; using NBTExplorer.Model; -using Substrate.Nbt; -using NBTExplorer.Windows; using NBTExplorer.Vendor.MultiSelectTreeView; -using System.IO; +using NBTExplorer.Windows; +using Substrate.Nbt; namespace NBTExplorer.Controllers { @@ -54,6 +53,16 @@ namespace NBTExplorer.Controllers get { return _nodeTree; } } + public IconRegistry IconRegistry + { + get { return _iconRegistry; } + } + + public ImageList IconList + { + get { return _multiTree.ImageList; } + } + public bool ShowVirtualRoot { get; set; } public string VirtualRootDisplay diff --git a/Controllers/RuleTreeController.cs b/Controllers/RuleTreeController.cs index 5fb8fc3..eec9d81 100644 --- a/Controllers/RuleTreeController.cs +++ b/Controllers/RuleTreeController.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Windows.Forms; -using NBTExplorer.Windows; +using System.Windows.Forms; using NBTExplorer.Model.Search; -using Substrate.Nbt; +using NBTExplorer.Windows; using NBTExplorer.Windows.Search; -using System.Drawing; +using Substrate.Nbt; namespace NBTExplorer.Controllers { diff --git a/Model/CubicRegionDataNode.cs b/Model/CubicRegionDataNode.cs index 55c5785..b3f6c82 100644 --- a/Model/CubicRegionDataNode.cs +++ b/Model/CubicRegionDataNode.cs @@ -41,6 +41,11 @@ namespace NBTExplorer.Model get { return !IsExpanded; } } + public override bool IsContainerType + { + get { return true; } + } + public override string NodePathName { get { return Path.GetFileName(_path); } diff --git a/Model/DataNode.cs b/Model/DataNode.cs index 996c270..e0d377b 100644 --- a/Model/DataNode.cs +++ b/Model/DataNode.cs @@ -195,6 +195,11 @@ namespace NBTExplorer.Model get { return ""; } } + public virtual bool IsContainerType + { + get { return false; } + } + public virtual bool HasUnexpandedChildren { get { return false; } diff --git a/Model/DirectoryDataNode.cs b/Model/DirectoryDataNode.cs index 3b7b9c5..1a92ac7 100644 --- a/Model/DirectoryDataNode.cs +++ b/Model/DirectoryDataNode.cs @@ -26,7 +26,9 @@ namespace NBTExplorer.Model { get { - string name = Path.GetDirectoryName(_path); + string path = (_path.EndsWith("/") || _path.EndsWith("\\")) ? _path : _path + '/'; + + string name = Path.GetDirectoryName(path); int sepIndex = Math.Max(name.LastIndexOf('/'), name.LastIndexOf('\\')); return (sepIndex > 0) ? name.Substring(sepIndex + 1) : name; @@ -43,6 +45,11 @@ namespace NBTExplorer.Model get { return !IsExpanded; } } + public override bool IsContainerType + { + get { return true; } + } + protected override void ExpandCore () { foreach (string dirpath in Directory.GetDirectories(_path)) { diff --git a/Model/NbtFileDataNode.cs b/Model/NbtFileDataNode.cs index c3bb464..e40f6d3 100644 --- a/Model/NbtFileDataNode.cs +++ b/Model/NbtFileDataNode.cs @@ -95,6 +95,11 @@ namespace NBTExplorer.Model get { return !IsExpanded; } } + public override bool IsContainerType + { + get { return true; } + } + protected override void ExpandCore () { if (_tree == null) { diff --git a/Model/RegionChunkDataNode.cs b/Model/RegionChunkDataNode.cs index 19ce0b7..c5c2962 100644 --- a/Model/RegionChunkDataNode.cs +++ b/Model/RegionChunkDataNode.cs @@ -76,6 +76,11 @@ namespace NBTExplorer.Model } } + public override bool IsContainerType + { + get { return true; } + } + public bool IsNamedContainer { get { return true; } diff --git a/Model/RegionFileDataNode.cs b/Model/RegionFileDataNode.cs index d043b9e..91524f0 100644 --- a/Model/RegionFileDataNode.cs +++ b/Model/RegionFileDataNode.cs @@ -42,6 +42,11 @@ namespace NBTExplorer.Model get { return !IsExpanded; } } + public override bool IsContainerType + { + get { return true; } + } + public override string NodePathName { get { return Path.GetFileName(_path); } diff --git a/Model/TagDataNode.cs b/Model/TagDataNode.cs index 34d96e3..2878e3f 100644 --- a/Model/TagDataNode.cs +++ b/Model/TagDataNode.cs @@ -66,6 +66,11 @@ namespace NBTExplorer.Model get { return !IsExpanded && TagCount > 0; } } + public override bool IsContainerType + { + get { return true; } + } + public override string NodeDisplay { get { return NodeDisplayPrefix + TagCount + ((TagCount == 1) ? " entry" : " entries"); } diff --git a/NBTExplorer.csproj b/NBTExplorer.csproj index 8239c3d..de02d09 100644 --- a/NBTExplorer.csproj +++ b/NBTExplorer.csproj @@ -81,6 +81,7 @@ + @@ -95,12 +96,6 @@ CancelSearchForm.cs - - UserControl - - - ExplorerBar.cs - Form @@ -232,15 +227,10 @@ ValueRuleForm.cs - - Component - + CancelSearchForm.cs - - ExplorerBar.cs - FindReplace.cs @@ -305,7 +295,6 @@ -