From 09f7112164ad31176a75c88ade20b1e4182ef93c Mon Sep 17 00:00:00 2001 From: Desktop Date: Fri, 28 Jul 2023 18:06:13 +0300 Subject: [PATCH] NBT files (i.e .dat or .schematic files) can now have their data copied into the clipboard. --- NBTModel/Data/Nodes/NbtFileDataNode.cs | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/NBTModel/Data/Nodes/NbtFileDataNode.cs b/NBTModel/Data/Nodes/NbtFileDataNode.cs index 866d812..4c7559d 100644 --- a/NBTModel/Data/Nodes/NbtFileDataNode.cs +++ b/NBTModel/Data/Nodes/NbtFileDataNode.cs @@ -59,6 +59,7 @@ namespace NBTExplorer.Model get { return NodeCapabilities.CreateTag + | NodeCapabilities.Copy | NodeCapabilities.PasteInto | NodeCapabilities.Search | NodeCapabilities.Refresh @@ -71,11 +72,17 @@ namespace NBTExplorer.Model get { return Path.GetFileName(_path); } } + public override string NodePathName { get { return Path.GetFileName(_path); } } + private string NodeNameWithoutExtension + { + get { return Path.GetFileNameWithoutExtension(_path); } + } + public override string NodeDisplay { get @@ -101,6 +108,27 @@ namespace NBTExplorer.Model get { return true; } } + private TagNodeCompound GetTagNode () + { + TagNode tag; + + if (_tree == null) { + try { + Expand(); + tag = _tree.Root.Copy(); + Release(); + } + catch { + Release(); + return null; + } + } + else { + tag = _tree.Root.Copy(); + } + return (TagNodeCompound) tag; + } + protected override void ExpandCore () { if (_tree == null) { @@ -203,6 +231,20 @@ namespace NBTExplorer.Model return false; } + public override bool CopyNode() + { + if (CanCopyNode) + { + // Need to create new compound tag, add all children of the nbt node into it, + // copy it and delete it. + + NbtClipboardController.CopyToClipboard(new NbtClipboardData(this.NodeNameWithoutExtension, this.GetTagNode())); + return true; + } + + return false; + } + public override bool PasteNode () { if (!CanPasteIntoNode)