ExplorerBar on find/replace

This commit is contained in:
Justin Aquadro 2013-10-29 22:17:07 -04:00
parent 26a727e41e
commit a8cf67b8f4
13 changed files with 226 additions and 25 deletions

View 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);
}
}
}

View file

@ -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

View file

@ -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
{

View file

@ -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); }

View file

@ -195,6 +195,11 @@ namespace NBTExplorer.Model
get { return ""; }
}
public virtual bool IsContainerType
{
get { return false; }
}
public virtual bool HasUnexpandedChildren
{
get { return false; }

View file

@ -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)) {

View file

@ -95,6 +95,11 @@ namespace NBTExplorer.Model
get { return !IsExpanded; }
}
public override bool IsContainerType
{
get { return true; }
}
protected override void ExpandCore ()
{
if (_tree == null) {

View file

@ -76,6 +76,11 @@ namespace NBTExplorer.Model
}
}
public override bool IsContainerType
{
get { return true; }
}
public bool IsNamedContainer
{
get { return true; }

View file

@ -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); }

View file

@ -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"); }

View file

@ -81,6 +81,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\ExplorerBarController.cs" />
<Compile Include="Controllers\NodeTreeController.cs" />
<Compile Include="FormRegistry.cs" />
<Compile Include="Controllers\RuleTreeController.cs" />
@ -95,12 +96,6 @@
<Compile Include="Windows\CancelSearchForm.Designer.cs">
<DependentUpon>CancelSearchForm.cs</DependentUpon>
</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">
<SubType>Form</SubType>
</Compile>
@ -232,15 +227,10 @@
<Compile Include="Windows\Search\ValueRuleForm.Designer.cs">
<DependentUpon>ValueRuleForm.cs</DependentUpon>
</Compile>
<Compile Include="Windows\ToolStripExplorerButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Windows\ToolStripExplorerRenderer.cs" />
<EmbeddedResource Include="Windows\CancelSearchForm.resx">
<DependentUpon>CancelSearchForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Windows\ExplorerBar.resx">
<DependentUpon>ExplorerBar.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Windows\FindReplace.resx">
<DependentUpon>FindReplace.cs</DependentUpon>
</EmbeddedResource>
@ -305,7 +295,6 @@
<None Include="Resources\arrow-270.png" />
<Content Include="Vendor\Be.Windows.Forms.HexBox\HexBox.bmp" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.

View file

@ -22,6 +22,8 @@ namespace NBTExplorer.Windows
private RuleTreeController _findController;
private NodeTreeController _replaceController;
private ExplorerBarController _explorerManager;
public FindReplace (MainForm main, NodeTreeController controller, DataNode searchRoot)
{
InitializeComponent();
@ -38,6 +40,13 @@ namespace NBTExplorer.Windows
_replaceController.VirtualRootDisplay = "Replacement Tags";
_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
@ -163,6 +172,12 @@ namespace NBTExplorer.Windows
#endregion
private void Reset ()
{
_searchForm = null;
_searchState = null;
}
private CancelSearchForm _searchForm;
private ContainerRuleSearchStateWin _searchState;

View 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);
}
}
}