diff --git a/NBTExplorer/Controllers/NodeTreeController.cs b/NBTExplorer/Controllers/NodeTreeController.cs index 217b60e..2aca05f 100644 --- a/NBTExplorer/Controllers/NodeTreeController.cs +++ b/NBTExplorer/Controllers/NodeTreeController.cs @@ -229,14 +229,14 @@ namespace NBTExplorer.Controllers foreach (var item in FileTypeRegistry.RegisteredTypes) { if (item.Value.NamePatternTest(path)) node = item.Value.NodeCreate(path); - } - - if (node == null) - node = NbtFileDataNode.TryCreateFrom(path); - if (node != null) - _nodeTree.Nodes.Add(CreateUnexpandedNode(node)); - else - failCount++; + } + + if (node == null) + node = NbtFileDataNode.TryCreateFrom(path); + if (node != null) + _nodeTree.Nodes.Add(CreateUnexpandedNode(node)); + else + failCount++; } } diff --git a/NBTModel/Data/Nodes/RegionChunkDataNode.cs b/NBTModel/Data/Nodes/RegionChunkDataNode.cs index 2587934..b952679 100644 --- a/NBTModel/Data/Nodes/RegionChunkDataNode.cs +++ b/NBTModel/Data/Nodes/RegionChunkDataNode.cs @@ -31,13 +31,19 @@ namespace NBTExplorer.Model get { return _z; } } + protected RegionFileDataNode RegionParent + { + get { return Parent as RegionFileDataNode; } + } + protected override NodeCapabilities Capabilities { get { return NodeCapabilities.CreateTag | NodeCapabilities.PasteInto - | NodeCapabilities.Search; + | NodeCapabilities.Search + | NodeCapabilities.Delete; } } @@ -99,6 +105,17 @@ namespace NBTExplorer.Model get { return true; } } + public override bool DeleteNode () + { + if (CanDeleteNode && _regionFile.HasChunk(_x, _z)) { + RegionParent.QueueDeleteChunk(_x, _z); + IsParentModified = true; + return Parent.Nodes.Remove(this); + } + + return false; + } + public bool IsNamedContainer { get { return true; } diff --git a/NBTModel/Data/Nodes/RegionFileDataNode.cs b/NBTModel/Data/Nodes/RegionFileDataNode.cs index e736745..7f397fb 100644 --- a/NBTModel/Data/Nodes/RegionFileDataNode.cs +++ b/NBTModel/Data/Nodes/RegionFileDataNode.cs @@ -10,6 +10,7 @@ namespace NBTExplorer.Model { private string _path; private RegionFile _region; + private List _deleteQueue = new List(); private static Regex _namePattern = new Regex(@"^r\.(-?\d+)\.(-?\d+)\.(mcr|mca)$"); @@ -100,6 +101,16 @@ namespace NBTExplorer.Model Nodes.Clear(); } + protected override void SaveCore () + { + foreach (RegionKey key in _deleteQueue) { + if (_region.HasChunk(key.X, key.Z)) + _region.DeleteChunk(key.X, key.Z); + } + + _deleteQueue.Clear(); + } + public override bool RefreshNode () { Dictionary expandSet = BuildExpandSet(this); @@ -108,5 +119,12 @@ namespace NBTExplorer.Model return expandSet != null; } + + public void QueueDeleteChunk (int rx, int rz) + { + RegionKey key = new RegionKey(rx, rz); + if (!_deleteQueue.Contains(key)) + _deleteQueue.Add(key); + } } }