Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copying the data off of NBT files (i.e playerdata .dat files) into the clipboard. #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions NBTModel/Data/Nodes/NbtFileDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected override NodeCapabilities Capabilities
get
{
return NodeCapabilities.CreateTag
| NodeCapabilities.Copy
| NodeCapabilities.PasteInto
| NodeCapabilities.Search
| NodeCapabilities.Refresh
Expand All @@ -71,11 +72,17 @@ public override string NodeName
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
Expand All @@ -101,6 +108,27 @@ public override bool IsContainerType
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) {
Expand Down Expand Up @@ -203,6 +231,20 @@ public override bool CreateNode (TagType type)
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)
Expand Down