forked from mirrors/NBTExplorer
ExplorerBar on find/replace
This commit is contained in:
parent
26a727e41e
commit
a8cf67b8f4
13 changed files with 226 additions and 25 deletions
106
Controllers/ExplorerBarController.cs
Normal file
106
Controllers/ExplorerBarController.cs
Normal file
|
@ -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<DataNode> ancestry = new List<DataNode>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using NBTExplorer.Model;
|
using NBTExplorer.Model;
|
||||||
using Substrate.Nbt;
|
|
||||||
using NBTExplorer.Windows;
|
|
||||||
using NBTExplorer.Vendor.MultiSelectTreeView;
|
using NBTExplorer.Vendor.MultiSelectTreeView;
|
||||||
using System.IO;
|
using NBTExplorer.Windows;
|
||||||
|
using Substrate.Nbt;
|
||||||
|
|
||||||
namespace NBTExplorer.Controllers
|
namespace NBTExplorer.Controllers
|
||||||
{
|
{
|
||||||
|
@ -54,6 +53,16 @@ namespace NBTExplorer.Controllers
|
||||||
get { return _nodeTree; }
|
get { return _nodeTree; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IconRegistry IconRegistry
|
||||||
|
{
|
||||||
|
get { return _iconRegistry; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageList IconList
|
||||||
|
{
|
||||||
|
get { return _multiTree.ImageList; }
|
||||||
|
}
|
||||||
|
|
||||||
public bool ShowVirtualRoot { get; set; }
|
public bool ShowVirtualRoot { get; set; }
|
||||||
|
|
||||||
public string VirtualRootDisplay
|
public string VirtualRootDisplay
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
using System;
|
using System.Windows.Forms;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using NBTExplorer.Windows;
|
|
||||||
using NBTExplorer.Model.Search;
|
using NBTExplorer.Model.Search;
|
||||||
using Substrate.Nbt;
|
using NBTExplorer.Windows;
|
||||||
using NBTExplorer.Windows.Search;
|
using NBTExplorer.Windows.Search;
|
||||||
using System.Drawing;
|
using Substrate.Nbt;
|
||||||
|
|
||||||
namespace NBTExplorer.Controllers
|
namespace NBTExplorer.Controllers
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,6 +41,11 @@ namespace NBTExplorer.Model
|
||||||
get { return !IsExpanded; }
|
get { return !IsExpanded; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsContainerType
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
public override string NodePathName
|
public override string NodePathName
|
||||||
{
|
{
|
||||||
get { return Path.GetFileName(_path); }
|
get { return Path.GetFileName(_path); }
|
||||||
|
|
|
@ -195,6 +195,11 @@ namespace NBTExplorer.Model
|
||||||
get { return ""; }
|
get { return ""; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool IsContainerType
|
||||||
|
{
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool HasUnexpandedChildren
|
public virtual bool HasUnexpandedChildren
|
||||||
{
|
{
|
||||||
get { return false; }
|
get { return false; }
|
||||||
|
|
|
@ -26,7 +26,9 @@ namespace NBTExplorer.Model
|
||||||
{
|
{
|
||||||
get
|
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('\\'));
|
int sepIndex = Math.Max(name.LastIndexOf('/'), name.LastIndexOf('\\'));
|
||||||
|
|
||||||
return (sepIndex > 0) ? name.Substring(sepIndex + 1) : name;
|
return (sepIndex > 0) ? name.Substring(sepIndex + 1) : name;
|
||||||
|
@ -43,6 +45,11 @@ namespace NBTExplorer.Model
|
||||||
get { return !IsExpanded; }
|
get { return !IsExpanded; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsContainerType
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
protected override void ExpandCore ()
|
protected override void ExpandCore ()
|
||||||
{
|
{
|
||||||
foreach (string dirpath in Directory.GetDirectories(_path)) {
|
foreach (string dirpath in Directory.GetDirectories(_path)) {
|
||||||
|
|
|
@ -95,6 +95,11 @@ namespace NBTExplorer.Model
|
||||||
get { return !IsExpanded; }
|
get { return !IsExpanded; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsContainerType
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
protected override void ExpandCore ()
|
protected override void ExpandCore ()
|
||||||
{
|
{
|
||||||
if (_tree == null) {
|
if (_tree == null) {
|
||||||
|
|
|
@ -76,6 +76,11 @@ namespace NBTExplorer.Model
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsContainerType
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsNamedContainer
|
public bool IsNamedContainer
|
||||||
{
|
{
|
||||||
get { return true; }
|
get { return true; }
|
||||||
|
|
|
@ -42,6 +42,11 @@ namespace NBTExplorer.Model
|
||||||
get { return !IsExpanded; }
|
get { return !IsExpanded; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsContainerType
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
public override string NodePathName
|
public override string NodePathName
|
||||||
{
|
{
|
||||||
get { return Path.GetFileName(_path); }
|
get { return Path.GetFileName(_path); }
|
||||||
|
|
|
@ -66,6 +66,11 @@ namespace NBTExplorer.Model
|
||||||
get { return !IsExpanded && TagCount > 0; }
|
get { return !IsExpanded && TagCount > 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsContainerType
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
public override string NodeDisplay
|
public override string NodeDisplay
|
||||||
{
|
{
|
||||||
get { return NodeDisplayPrefix + TagCount + ((TagCount == 1) ? " entry" : " entries"); }
|
get { return NodeDisplayPrefix + TagCount + ((TagCount == 1) ? " entry" : " entries"); }
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Controllers\ExplorerBarController.cs" />
|
||||||
<Compile Include="Controllers\NodeTreeController.cs" />
|
<Compile Include="Controllers\NodeTreeController.cs" />
|
||||||
<Compile Include="FormRegistry.cs" />
|
<Compile Include="FormRegistry.cs" />
|
||||||
<Compile Include="Controllers\RuleTreeController.cs" />
|
<Compile Include="Controllers\RuleTreeController.cs" />
|
||||||
|
@ -95,12 +96,6 @@
|
||||||
<Compile Include="Windows\CancelSearchForm.Designer.cs">
|
<Compile Include="Windows\CancelSearchForm.Designer.cs">
|
||||||
<DependentUpon>CancelSearchForm.cs</DependentUpon>
|
<DependentUpon>CancelSearchForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Windows\ExplorerBar.cs">
|
|
||||||
<SubType>UserControl</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Windows\ExplorerBar.Designer.cs">
|
|
||||||
<DependentUpon>ExplorerBar.cs</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Windows\FindReplace.cs">
|
<Compile Include="Windows\FindReplace.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -232,15 +227,10 @@
|
||||||
<Compile Include="Windows\Search\ValueRuleForm.Designer.cs">
|
<Compile Include="Windows\Search\ValueRuleForm.Designer.cs">
|
||||||
<DependentUpon>ValueRuleForm.cs</DependentUpon>
|
<DependentUpon>ValueRuleForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Windows\ToolStripExplorerButton.cs">
|
<Compile Include="Windows\ToolStripExplorerRenderer.cs" />
|
||||||
<SubType>Component</SubType>
|
|
||||||
</Compile>
|
|
||||||
<EmbeddedResource Include="Windows\CancelSearchForm.resx">
|
<EmbeddedResource Include="Windows\CancelSearchForm.resx">
|
||||||
<DependentUpon>CancelSearchForm.cs</DependentUpon>
|
<DependentUpon>CancelSearchForm.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Windows\ExplorerBar.resx">
|
|
||||||
<DependentUpon>ExplorerBar.cs</DependentUpon>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<EmbeddedResource Include="Windows\FindReplace.resx">
|
<EmbeddedResource Include="Windows\FindReplace.resx">
|
||||||
<DependentUpon>FindReplace.cs</DependentUpon>
|
<DependentUpon>FindReplace.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
@ -305,7 +295,6 @@
|
||||||
<None Include="Resources\arrow-270.png" />
|
<None Include="Resources\arrow-270.png" />
|
||||||
<Content Include="Vendor\Be.Windows.Forms.HexBox\HexBox.bmp" />
|
<Content Include="Vendor\Be.Windows.Forms.HexBox\HexBox.bmp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|
|
@ -22,6 +22,8 @@ namespace NBTExplorer.Windows
|
||||||
private RuleTreeController _findController;
|
private RuleTreeController _findController;
|
||||||
private NodeTreeController _replaceController;
|
private NodeTreeController _replaceController;
|
||||||
|
|
||||||
|
private ExplorerBarController _explorerManager;
|
||||||
|
|
||||||
public FindReplace (MainForm main, NodeTreeController controller, DataNode searchRoot)
|
public FindReplace (MainForm main, NodeTreeController controller, DataNode searchRoot)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -38,6 +40,13 @@ namespace NBTExplorer.Windows
|
||||||
_replaceController.VirtualRootDisplay = "Replacement Tags";
|
_replaceController.VirtualRootDisplay = "Replacement Tags";
|
||||||
|
|
||||||
_explorerStrip.Renderer = new ToolStripExplorerRenderer();
|
_explorerStrip.Renderer = new ToolStripExplorerRenderer();
|
||||||
|
_explorerStrip.ImageList = _mainController.IconList;
|
||||||
|
|
||||||
|
_explorerManager = new ExplorerBarController(_explorerStrip, _mainController.IconRegistry, _mainController.IconList, searchRoot);
|
||||||
|
_explorerManager.SearchRootChanged += (s, e) => {
|
||||||
|
_mainSearchRoot = _explorerManager.SearchRoot;
|
||||||
|
Reset();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Find Toolbar Buttons
|
#region Find Toolbar Buttons
|
||||||
|
@ -163,6 +172,12 @@ namespace NBTExplorer.Windows
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private void Reset ()
|
||||||
|
{
|
||||||
|
_searchForm = null;
|
||||||
|
_searchState = null;
|
||||||
|
}
|
||||||
|
|
||||||
private CancelSearchForm _searchForm;
|
private CancelSearchForm _searchForm;
|
||||||
private ContainerRuleSearchStateWin _searchState;
|
private ContainerRuleSearchStateWin _searchState;
|
||||||
|
|
||||||
|
|
49
Windows/ToolStripExplorerRenderer.cs
Normal file
49
Windows/ToolStripExplorerRenderer.cs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NBTExplorer.Windows
|
||||||
|
{
|
||||||
|
class ToolStripExplorerRenderer : ToolStripProfessionalRenderer
|
||||||
|
{
|
||||||
|
protected override void OnRenderSplitButtonBackground (ToolStripItemRenderEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnRenderSplitButtonBackground(e);
|
||||||
|
|
||||||
|
ToolStripSplitButton button = e.Item as ToolStripSplitButton;
|
||||||
|
Graphics g = e.Graphics;
|
||||||
|
|
||||||
|
if (button == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Rectangle bounds = new Rectangle(Point.Empty, button.Size);
|
||||||
|
Rectangle arrowButtonBounds = new Rectangle(button.DropDownButtonBounds.X + 1, button.DropDownButtonBounds.Y + 1,
|
||||||
|
button.DropDownButtonBounds.Width - 2, button.DropDownButtonBounds.Height - 2);
|
||||||
|
|
||||||
|
using (Brush brush = new SolidBrush(ColorTable.ToolStripGradientEnd)) {
|
||||||
|
g.FillRectangle(brush, arrowButtonBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button.Pressed)
|
||||||
|
DrawArrow(new ToolStripArrowRenderEventArgs(g, button, arrowButtonBounds, SystemColors.ControlText, ArrowDirection.Down));
|
||||||
|
else
|
||||||
|
DrawArrow(new ToolStripArrowRenderEventArgs(g, button, arrowButtonBounds, SystemColors.ControlText, ArrowDirection.Right));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnRenderToolStripBackground (ToolStripRenderEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.ToolStrip is ToolStripDropDown || e.ToolStrip is MenuStrip || e.ToolStrip is StatusStrip)
|
||||||
|
base.OnRenderToolStripBackground(e);
|
||||||
|
else {
|
||||||
|
using (Brush brush = new SolidBrush(ColorTable.ToolStripGradientEnd)) {
|
||||||
|
e.Graphics.FillRectangle(brush, e.ToolStrip.Bounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnRenderToolStripBorder (ToolStripRenderEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.ToolStrip is ToolStripDropDown || e.ToolStrip is MenuStrip || e.ToolStrip is StatusStrip)
|
||||||
|
base.OnRenderToolStripBorder(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue