Merge commit 'e0bc93eb59673def9477f386ad625652c1073c6f' into mac-ui

This commit is contained in:
Justin Aquadro 2012-11-09 00:22:16 -05:00
commit 45dac1389d
9 changed files with 158 additions and 48 deletions

View file

@ -40,7 +40,7 @@ namespace NBTExplorer.Model
public override bool CanPasteIntoNode public override bool CanPasteIntoNode
{ {
get { return NbtClipboardData.ContainsData; } get { return NbtClipboardController.ContainsData; }
} }
public override bool CreateNode (TagType type) public override bool CreateNode (TagType type)
@ -68,8 +68,8 @@ namespace NBTExplorer.Model
if (!CanPasteIntoNode) if (!CanPasteIntoNode)
return false; return false;
NbtClipboardData clipboard = NbtClipboardData.CopyFromClipboard(); NbtClipboardData clipboard = NbtClipboardController.CopyFromClipboard();
if (clipboard.Node == null) if (clipboard == null || clipboard.Node == null)
return false; return false;
string name = clipboard.Name; string name = clipboard.Name;

View file

@ -238,8 +238,7 @@ namespace NBTExplorer.Model
public override bool CopyNode () public override bool CopyNode ()
{ {
if (CanCopyNode) { if (CanCopyNode) {
NbtClipboardData clip = new NbtClipboardData(NodeName, Tag); NbtClipboardController.CopyToClipboard(new NbtClipboardData(NodeName, Tag));
clip.CopyToClipboard();
return true; return true;
} }
@ -249,8 +248,7 @@ namespace NBTExplorer.Model
public override bool CutNode () public override bool CutNode ()
{ {
if (CanCutNode) { if (CanCutNode) {
NbtClipboardData clip = new NbtClipboardData(NodeName, Tag); NbtClipboardController.CopyToClipboard(new NbtClipboardData(NodeName, Tag));
clip.CopyToClipboard();
TagParent.DeleteTag(Tag); TagParent.DeleteTag(Tag);
Parent.Nodes.Remove(this); Parent.Nodes.Remove(this);

View file

@ -40,9 +40,12 @@ namespace NBTExplorer.Model
{ {
get get
{ {
if (NbtClipboardData.ContainsData) { if (NbtClipboardController.ContainsData) {
TagNode node = NbtClipboardData.CopyFromClipboard().Node; NbtClipboardData data = NbtClipboardController.CopyFromClipboard();
if (node != null && node.GetTagType() == Tag.ValueType) if (data == null)
return false;
if (data.Node != null && data.Node.GetTagType() == Tag.ValueType)
return true; return true;
} }
@ -68,8 +71,8 @@ namespace NBTExplorer.Model
if (!CanPasteIntoNode) if (!CanPasteIntoNode)
return false; return false;
NbtClipboardData clipboard = NbtClipboardData.CopyFromClipboard(); NbtClipboardData clipboard = NbtClipboardController.CopyFromClipboard();
if (clipboard.Node == null) if (clipboard == null || clipboard.Node == null)
return false; return false;
AppendTag(clipboard.Node); AppendTag(clipboard.Node);

View file

@ -81,6 +81,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="FormRegistry.cs" /> <Compile Include="FormRegistry.cs" />
<Compile Include="NbtClipboardController.cs" />
<Compile Include="Windows\CancelSearchForm.cs"> <Compile Include="Windows\CancelSearchForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -192,6 +193,7 @@
<Compile Include="Vendor\Be.Windows.Forms.HexBox\NativeMethods.cs" /> <Compile Include="Vendor\Be.Windows.Forms.HexBox\NativeMethods.cs" />
<Compile Include="Vendor\Be.Windows.Forms.HexBox\Util.cs" /> <Compile Include="Vendor\Be.Windows.Forms.HexBox\Util.cs" />
<Compile Include="Windows\FormHandlers.cs" /> <Compile Include="Windows\FormHandlers.cs" />
<Compile Include="Windows\NbtClipboardControllerWin.cs" />
<EmbeddedResource Include="Windows\CancelSearchForm.resx"> <EmbeddedResource Include="Windows\CancelSearchForm.resx">
<DependentUpon>CancelSearchForm.cs</DependentUpon> <DependentUpon>CancelSearchForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

51
NbtClipboardController.cs Normal file
View file

@ -0,0 +1,51 @@
using System;
namespace NBTExplorer
{
public static class NbtClipboardController
{
private static INbtClipboardController _instance;
public static void Initialize (INbtClipboardController controller)
{
_instance = controller;
}
public static bool IsInitialized
{
get { return _instance != null; }
}
public static bool ContainsData
{
get
{
if (_instance == null)
return false;
return _instance.ContainsData;
}
}
public static NbtClipboardData CopyFromClipboard ()
{
if (_instance == null)
return null;
return _instance.CopyFromClipboard();
}
public static void CopyToClipboard (NbtClipboardData data)
{
if (_instance == null)
return;
_instance.CopyToClipboard(data);
}
}
public interface INbtClipboardController
{
bool ContainsData { get; }
void CopyToClipboard (NbtClipboardData data);
NbtClipboardData CopyFromClipboard ();
}
}

View file

@ -1,53 +1,51 @@
using System; using System;
using System.IO; using System.IO;
using System.Windows.Forms;
using Substrate.Nbt; using Substrate.Nbt;
namespace NBTExplorer namespace NBTExplorer
{ {
[Serializable]
public class NbtClipboardData public class NbtClipboardData
{ {
public string Name; private string _name;
private TagNode _node;
private byte[] _data; public string Name
[NonSerialized]
public TagNode Node;
public NbtClipboardData (String name, TagNode node)
{ {
Name = name; get { return _name; }
set { _name = value; }
}
public TagNode Node
{
get { return _node; }
set { _node = value; }
}
public NbtClipboardData (string name, TagNode node)
{
_name = name;
_node = node;
}
public static byte[] SerializeNode (TagNode node)
{
TagNodeCompound root = new TagNodeCompound(); TagNodeCompound root = new TagNodeCompound();
root.Add("root", node); root.Add("root", node);
NbtTree tree = new NbtTree(root); NbtTree tree = new NbtTree(root);
using (MemoryStream ms = new MemoryStream()) { using (MemoryStream ms = new MemoryStream()) {
tree.WriteTo(ms); tree.WriteTo(ms);
_data = new byte[ms.Length]; byte[] data = new byte[ms.Length];
Array.Copy(ms.GetBuffer(), _data, ms.Length); Array.Copy(ms.GetBuffer(), data, ms.Length);
return data;
} }
} }
public static bool ContainsData public static TagNode DeserializeNode (byte[] data)
{ {
get { return Clipboard.ContainsData(typeof(NbtClipboardData).FullName); }
}
public void CopyToClipboard ()
{
Clipboard.SetData(typeof(NbtClipboardData).FullName, this);
}
public static NbtClipboardData CopyFromClipboard ()
{
NbtClipboardData clip = Clipboard.GetData(typeof(NbtClipboardData).FullName) as NbtClipboardData;
if (clip == null)
return null;
NbtTree tree = new NbtTree(); NbtTree tree = new NbtTree();
using (MemoryStream ms = new MemoryStream(clip._data)) { using (MemoryStream ms = new MemoryStream(data)) {
tree.ReadFrom(ms); tree.ReadFrom(ms);
} }
@ -55,8 +53,7 @@ namespace NBTExplorer
if (root == null || !root.ContainsKey("root")) if (root == null || !root.ContainsKey("root"))
return null; return null;
clip.Node = root["root"]; return root["root"];
return clip;
} }
} }
} }

BIN
Resources/Dead_Bush_256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View file

@ -45,6 +45,7 @@ namespace NBTExplorer.Windows
InitializeComponent(); InitializeComponent();
InitializeIconRegistry(); InitializeIconRegistry();
FormHandlers.Register(); FormHandlers.Register();
NbtClipboardController.Initialize(new NbtClipboardControllerWin());
FormClosing += MainForm_Closing; FormClosing += MainForm_Closing;
@ -662,21 +663,21 @@ namespace NBTExplorer.Windows
_buttonAddTagString.Enabled = node.CanCreateTag(TagType.TAG_STRING); _buttonAddTagString.Enabled = node.CanCreateTag(TagType.TAG_STRING);
_buttonSave.Enabled = CheckModifications(); _buttonSave.Enabled = CheckModifications();
_buttonCopy.Enabled = node.CanCopyNode; _buttonCopy.Enabled = node.CanCopyNode && NbtClipboardController.IsInitialized;
_buttonCut.Enabled = node.CanCutNode; _buttonCut.Enabled = node.CanCutNode && NbtClipboardController.IsInitialized;
_buttonDelete.Enabled = node.CanDeleteNode; _buttonDelete.Enabled = node.CanDeleteNode;
_buttonEdit.Enabled = node.CanEditNode; _buttonEdit.Enabled = node.CanEditNode;
_buttonFindNext.Enabled = node.CanSearchNode || _searchState != null; _buttonFindNext.Enabled = node.CanSearchNode || _searchState != null;
_buttonPaste.Enabled = node.CanPasteIntoNode; _buttonPaste.Enabled = node.CanPasteIntoNode && NbtClipboardController.IsInitialized;
_buttonRename.Enabled = node.CanRenameNode; _buttonRename.Enabled = node.CanRenameNode;
_menuItemSave.Enabled = _buttonSave.Enabled; _menuItemSave.Enabled = _buttonSave.Enabled;
_menuItemCopy.Enabled = node.CanCopyNode; _menuItemCopy.Enabled = node.CanCopyNode && NbtClipboardController.IsInitialized;
_menuItemCut.Enabled = node.CanCutNode; _menuItemCut.Enabled = node.CanCutNode && NbtClipboardController.IsInitialized;
_menuItemDelete.Enabled = node.CanDeleteNode; _menuItemDelete.Enabled = node.CanDeleteNode;
_menuItemEditValue.Enabled = node.CanEditNode; _menuItemEditValue.Enabled = node.CanEditNode;
_menuItemFind.Enabled = node.CanSearchNode; _menuItemFind.Enabled = node.CanSearchNode;
_menuItemPaste.Enabled = node.CanPasteIntoNode; _menuItemPaste.Enabled = node.CanPasteIntoNode && NbtClipboardController.IsInitialized;
_menuItemRename.Enabled = node.CanRenameNode; _menuItemRename.Enabled = node.CanRenameNode;
_menuItemFind.Enabled = node.CanSearchNode; _menuItemFind.Enabled = node.CanSearchNode;
_menuItemFindNext.Enabled = _searchState != null; _menuItemFindNext.Enabled = _searchState != null;

View file

@ -0,0 +1,58 @@
using System;
using System.Windows.Forms;
using Substrate.Nbt;
namespace NBTExplorer.Windows
{
public class NbtClipboardControllerWin : INbtClipboardController
{
public bool ContainsData
{
get { return Clipboard.ContainsData(typeof(NbtClipboardDataWin).FullName); }
}
public void CopyToClipboard (NbtClipboardData data)
{
NbtClipboardDataWin dataWin = new NbtClipboardDataWin(data);
Clipboard.SetData(typeof(NbtClipboardDataWin).FullName, dataWin);
}
public NbtClipboardData CopyFromClipboard ()
{
NbtClipboardDataWin clip = Clipboard.GetData(typeof(NbtClipboardDataWin).FullName) as NbtClipboardDataWin;
if (clip == null)
return null;
TagNode node = clip.Node;
if (node == null)
return null;
return new NbtClipboardData(clip.Name, node);
}
}
[Serializable]
public class NbtClipboardDataWin
{
private string _name;
private byte[] _data;
public NbtClipboardDataWin (NbtClipboardData data)
{
Name = data.Name;
Node = data.Node;
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public TagNode Node
{
get { return NbtClipboardData.DeserializeNode(_data); }
set { _data = NbtClipboardData.SerializeNode(value); }
}
}
}