From 20b36407839d8f16bfbd2d433b2f5482cc8aed83 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Thu, 8 Nov 2012 20:20:55 -0500 Subject: [PATCH 1/2] Adding icon --- Resources/Dead_Bush_256.png | Bin 0 -> 4010 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Resources/Dead_Bush_256.png diff --git a/Resources/Dead_Bush_256.png b/Resources/Dead_Bush_256.png new file mode 100644 index 0000000000000000000000000000000000000000..f10673a2d404bab85e823b2bfb337836ba1157a7 GIT binary patch literal 4010 zcmZ`+d011|w%-{r2ufnL4pkw&di7RCq99rcoZw8K0-r+>2NJPZs6}wNKp^Ao~b2&3IC5^e1wPY!C>5`SKB`cS#VEVI`u~_>(R%JpO?MTF?wX`m8PckFG()ssq zp=f;ShSN!nbC03|+XHzpG)=+MQEA zt7Gy+qw^o5FCN}p<;-<9k*O;VmbHGqX9YtZm8y}KmGOIGhpXGSUCx?$cXyk1!!G~A z1+~M2SF7-SqrVE4@b=eQtZgqHv(@Nb!Ra1aVs&Hy7_l1z&`%1VChQVAEVwjJDV^1D zkYMF2W%nFeM882N#t?yd81rj>O3RHI@Zk7XSTM&FuUsJNvA;w43{X()ToElAWC9MJ zGJy=le^H1%TWKUvW0@oxVFKoIgy8y7!AZ?}(pAXnva@N?aQ{vtaX!rj^5|j=qh6zv zK_=efd=(Bj2ZSY*D{vp=tmo0jEvlKB3jhv+zuyUXzVdn|kh4Xn!hwhnTndG3i6>w` zV2eWEiy(F!31~>)!eE|Jo=>NOBH9gznxG-Q@%~RylYM5L?fx`vv6TBL#9*Tr-ui3M z9Q2$?$rg>fD|8@E1HG>$st{L+>9XsnfNynPcRF7U$i!S3n{d3uoOaWeOq;>J?facB zg0R9;)#dSqO(&5OMLKOvv9oy%DXk<=1cKy7yj-C!b5@S+{NpMtAwlw!_HE-xiAVd~ z(2KM;?yZ|CdwLjzC|7g9N}koyrb&r*ZW)Q0K`kX+$GFK3pMYG&V{QUN4={y$7Gk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Vp(L8O^2WsltMUHKQG0C-u35{b&w|WAV2N9|(yiRe-Fq)2_ zuoWzfH%LcjiH0Q0O|lwH#&YFt2-qyI^;35`$HEaOK9W6Iy}iOROlXJHvam7^sBb!f zo+d}Wk9hB67v%Z-pi?iU;>b^t-_+V>iz-o@l|c!4OUb`v>h4@l_e0jH(2CZ}qe!2% zU~d-bE%CfvBkQ$VT5!OmRf37BgdNWE)7%3v#s@YyaKe!~kj~>W+>^I^wr`@QmymEU zN_CIlU;D~ynP4`f*z^Voj7t_;5jvboYxv^N4e_`%{&EK#rz!Ecud?=7h~XLKiZ|5W zbIoBpaC`yB*ENIUJ$^^C4BxGk)P$x!I^UPpVV3AHIty6xqHAWllp-pK0b z_VmDyV2M{Ug9C8*EKL-3RX1GA_{qZmmOX(Q$wdj}Xz}`0a z*1})ZE%w2IJcsY9rrA}^1Ef!0SPkcCHv*vhT}T)#9US0Ax`wgR{R;+*?mkcgSmg1r zNGdUWA7#6JsM}Fj19zVz_%`w5ra1OKF@8#es7`S}FoJ_Ym;`LNPZj91dtvw;`wUKMCui_p3UvF#`HUIzs literal 0 HcmV?d00001 From e0bc93eb59673def9477f386ad625652c1073c6f Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Fri, 9 Nov 2012 00:14:23 -0500 Subject: [PATCH 2/2] Refactored Clipboard model to separate UX layer. --- Model/TagCompoundDataNode.cs | 6 +-- Model/TagDataNode.cs | 6 +-- Model/TagListDataNode.cs | 13 ++++--- NBTExplorer.csproj | 2 + NbtClipboardController.cs | 51 ++++++++++++++++++++++++ NbtClipboardData.cs | 57 +++++++++++++-------------- Windows/MainForm.cs | 13 ++++--- Windows/NbtClipboardControllerWin.cs | 58 ++++++++++++++++++++++++++++ 8 files changed, 158 insertions(+), 48 deletions(-) create mode 100644 NbtClipboardController.cs create mode 100644 Windows/NbtClipboardControllerWin.cs diff --git a/Model/TagCompoundDataNode.cs b/Model/TagCompoundDataNode.cs index ad09b87..8063c21 100644 --- a/Model/TagCompoundDataNode.cs +++ b/Model/TagCompoundDataNode.cs @@ -40,7 +40,7 @@ namespace NBTExplorer.Model public override bool CanPasteIntoNode { - get { return NbtClipboardData.ContainsData; } + get { return NbtClipboardController.ContainsData; } } public override bool CreateNode (TagType type) @@ -68,8 +68,8 @@ namespace NBTExplorer.Model if (!CanPasteIntoNode) return false; - NbtClipboardData clipboard = NbtClipboardData.CopyFromClipboard(); - if (clipboard.Node == null) + NbtClipboardData clipboard = NbtClipboardController.CopyFromClipboard(); + if (clipboard == null || clipboard.Node == null) return false; string name = clipboard.Name; diff --git a/Model/TagDataNode.cs b/Model/TagDataNode.cs index 48235f9..0d44ceb 100644 --- a/Model/TagDataNode.cs +++ b/Model/TagDataNode.cs @@ -238,8 +238,7 @@ namespace NBTExplorer.Model public override bool CopyNode () { if (CanCopyNode) { - NbtClipboardData clip = new NbtClipboardData(NodeName, Tag); - clip.CopyToClipboard(); + NbtClipboardController.CopyToClipboard(new NbtClipboardData(NodeName, Tag)); return true; } @@ -249,8 +248,7 @@ namespace NBTExplorer.Model public override bool CutNode () { if (CanCutNode) { - NbtClipboardData clip = new NbtClipboardData(NodeName, Tag); - clip.CopyToClipboard(); + NbtClipboardController.CopyToClipboard(new NbtClipboardData(NodeName, Tag)); TagParent.DeleteTag(Tag); Parent.Nodes.Remove(this); diff --git a/Model/TagListDataNode.cs b/Model/TagListDataNode.cs index ecc630b..3a9c26b 100644 --- a/Model/TagListDataNode.cs +++ b/Model/TagListDataNode.cs @@ -40,9 +40,12 @@ namespace NBTExplorer.Model { get { - if (NbtClipboardData.ContainsData) { - TagNode node = NbtClipboardData.CopyFromClipboard().Node; - if (node != null && node.GetTagType() == Tag.ValueType) + if (NbtClipboardController.ContainsData) { + NbtClipboardData data = NbtClipboardController.CopyFromClipboard(); + if (data == null) + return false; + + if (data.Node != null && data.Node.GetTagType() == Tag.ValueType) return true; } @@ -68,8 +71,8 @@ namespace NBTExplorer.Model if (!CanPasteIntoNode) return false; - NbtClipboardData clipboard = NbtClipboardData.CopyFromClipboard(); - if (clipboard.Node == null) + NbtClipboardData clipboard = NbtClipboardController.CopyFromClipboard(); + if (clipboard == null || clipboard.Node == null) return false; AppendTag(clipboard.Node); diff --git a/NBTExplorer.csproj b/NBTExplorer.csproj index a68738f..5c1d29d 100644 --- a/NBTExplorer.csproj +++ b/NBTExplorer.csproj @@ -81,6 +81,7 @@ + Form @@ -192,6 +193,7 @@ + CancelSearchForm.cs diff --git a/NbtClipboardController.cs b/NbtClipboardController.cs new file mode 100644 index 0000000..6a4c5ce --- /dev/null +++ b/NbtClipboardController.cs @@ -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 (); + } +} diff --git a/NbtClipboardData.cs b/NbtClipboardData.cs index 02ea8bf..271cfac 100644 --- a/NbtClipboardData.cs +++ b/NbtClipboardData.cs @@ -1,53 +1,51 @@ using System; using System.IO; -using System.Windows.Forms; using Substrate.Nbt; namespace NBTExplorer { - [Serializable] public class NbtClipboardData { - public string Name; + private string _name; + private TagNode _node; - private byte[] _data; - - [NonSerialized] - public TagNode Node; - - public NbtClipboardData (String name, TagNode node) + public string Name { - 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(); root.Add("root", node); NbtTree tree = new NbtTree(root); using (MemoryStream ms = new MemoryStream()) { tree.WriteTo(ms); - _data = new byte[ms.Length]; - Array.Copy(ms.GetBuffer(), _data, ms.Length); + byte[] data = new byte[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(); - using (MemoryStream ms = new MemoryStream(clip._data)) { + using (MemoryStream ms = new MemoryStream(data)) { tree.ReadFrom(ms); } @@ -55,8 +53,7 @@ namespace NBTExplorer if (root == null || !root.ContainsKey("root")) return null; - clip.Node = root["root"]; - return clip; + return root["root"]; } } } diff --git a/Windows/MainForm.cs b/Windows/MainForm.cs index bf6bbdf..5580722 100644 --- a/Windows/MainForm.cs +++ b/Windows/MainForm.cs @@ -45,6 +45,7 @@ namespace NBTExplorer.Windows InitializeComponent(); InitializeIconRegistry(); FormHandlers.Register(); + NbtClipboardController.Initialize(new NbtClipboardControllerWin()); FormClosing += MainForm_Closing; @@ -662,21 +663,21 @@ namespace NBTExplorer.Windows _buttonAddTagString.Enabled = node.CanCreateTag(TagType.TAG_STRING); _buttonSave.Enabled = CheckModifications(); - _buttonCopy.Enabled = node.CanCopyNode; - _buttonCut.Enabled = node.CanCutNode; + _buttonCopy.Enabled = node.CanCopyNode && NbtClipboardController.IsInitialized; + _buttonCut.Enabled = node.CanCutNode && NbtClipboardController.IsInitialized; _buttonDelete.Enabled = node.CanDeleteNode; _buttonEdit.Enabled = node.CanEditNode; _buttonFindNext.Enabled = node.CanSearchNode || _searchState != null; - _buttonPaste.Enabled = node.CanPasteIntoNode; + _buttonPaste.Enabled = node.CanPasteIntoNode && NbtClipboardController.IsInitialized; _buttonRename.Enabled = node.CanRenameNode; _menuItemSave.Enabled = _buttonSave.Enabled; - _menuItemCopy.Enabled = node.CanCopyNode; - _menuItemCut.Enabled = node.CanCutNode; + _menuItemCopy.Enabled = node.CanCopyNode && NbtClipboardController.IsInitialized; + _menuItemCut.Enabled = node.CanCutNode && NbtClipboardController.IsInitialized; _menuItemDelete.Enabled = node.CanDeleteNode; _menuItemEditValue.Enabled = node.CanEditNode; _menuItemFind.Enabled = node.CanSearchNode; - _menuItemPaste.Enabled = node.CanPasteIntoNode; + _menuItemPaste.Enabled = node.CanPasteIntoNode && NbtClipboardController.IsInitialized; _menuItemRename.Enabled = node.CanRenameNode; _menuItemFind.Enabled = node.CanSearchNode; _menuItemFindNext.Enabled = _searchState != null; diff --git a/Windows/NbtClipboardControllerWin.cs b/Windows/NbtClipboardControllerWin.cs new file mode 100644 index 0000000..36425d6 --- /dev/null +++ b/Windows/NbtClipboardControllerWin.cs @@ -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); } + } + } +}