diff --git a/FormRegistry.cs b/FormRegistry.cs index 770959b..eab7a84 100644 --- a/FormRegistry.cs +++ b/FormRegistry.cs @@ -10,11 +10,15 @@ namespace NBTExplorer public delegate bool EditRestrictedStringAction (RestrictedStringFormData data); public delegate bool EditTagScalarAction (TagScalarFormData data); public delegate bool EditByteArrayAction (ByteArrayFormData data); + public delegate bool CreateNodeAction (CreateTagFormData data); public static EditStringAction EditString { get; set; } public static EditRestrictedStringAction RenameTag { get; set; } public static EditTagScalarAction EditTagScalar { get; set; } public static EditByteArrayAction EditByteArray { get; set; } + public static CreateNodeAction CreateNode { get; set; } + + public static Action MessageBox { get; set; } } public class TagScalarFormData @@ -52,6 +56,21 @@ namespace NBTExplorer } } + public class CreateTagFormData + { + public CreateTagFormData () + { + RestrictedNames = new List(); + } + + public TagType TagType { get; set; } + public bool HasName { get; set; } + public List RestrictedNames { get; private set; } + + public TagNode TagNode { get; set; } + public string TagName { get; set; } + } + public class ByteArrayFormData { public string NodeName { get; set; } diff --git a/Model/CubicRegionDataNode.cs b/Model/CubicRegionDataNode.cs index 51de6f5..271a575 100644 --- a/Model/CubicRegionDataNode.cs +++ b/Model/CubicRegionDataNode.cs @@ -1,6 +1,5 @@ using System.IO; using System.Text.RegularExpressions; -using System.Windows.Forms; namespace NBTExplorer.Model { @@ -60,7 +59,8 @@ namespace NBTExplorer.Model } } catch { - MessageBox.Show("Not a valid cubic region file.", "Read Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); + if (FormRegistry.MessageBox != null) + FormRegistry.MessageBox("Not a valid cubic region file."); } } diff --git a/Model/NbtFileDataNode.cs b/Model/NbtFileDataNode.cs index 6d4681f..e344296 100644 --- a/Model/NbtFileDataNode.cs +++ b/Model/NbtFileDataNode.cs @@ -1,7 +1,7 @@ using System.IO; +using System.Text.RegularExpressions; using Substrate.Core; using Substrate.Nbt; -using System.Text.RegularExpressions; namespace NBTExplorer.Model { diff --git a/Model/RegionChunkDataNode.cs b/Model/RegionChunkDataNode.cs index 02be164..599ef66 100644 --- a/Model/RegionChunkDataNode.cs +++ b/Model/RegionChunkDataNode.cs @@ -1,6 +1,6 @@ -using Substrate.Core; +using System.IO; +using Substrate.Core; using Substrate.Nbt; -using System.IO; namespace NBTExplorer.Model { diff --git a/Model/RegionFileDataNode.cs b/Model/RegionFileDataNode.cs index 4fb1a2d..dbd2993 100644 --- a/Model/RegionFileDataNode.cs +++ b/Model/RegionFileDataNode.cs @@ -1,7 +1,6 @@ using System.IO; -using System.Windows.Forms; -using Substrate.Core; using System.Text.RegularExpressions; +using Substrate.Core; namespace NBTExplorer.Model { @@ -61,7 +60,8 @@ namespace NBTExplorer.Model } } catch { - MessageBox.Show("Not a valid region file.", "Read Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); + if (FormRegistry.MessageBox != null) + FormRegistry.MessageBox("Not a valid region file."); } } diff --git a/Model/TagCompoundDataNode.cs b/Model/TagCompoundDataNode.cs index e6a36d5..ad09b87 100644 --- a/Model/TagCompoundDataNode.cs +++ b/Model/TagCompoundDataNode.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Windows.Forms; -using NBTExplorer.Windows; using Substrate.Nbt; namespace NBTExplorer.Model @@ -50,12 +48,16 @@ namespace NBTExplorer.Model if (!CanCreateTag(type)) return false; - CreateNodeForm form = new CreateNodeForm(type, true); - form.InvalidNames.AddRange(_container.TagNamesInUse); + if (FormRegistry.CreateNode != null) { + CreateTagFormData data = new CreateTagFormData() { + TagType = type, HasName = true, + }; + data.RestrictedNames.AddRange(_container.TagNamesInUse); - if (form.ShowDialog() == DialogResult.OK) { - AddTag(form.TagNode, form.TagName); - return true; + if (FormRegistry.CreateNode(data)) { + AddTag(data.TagNode, data.TagName); + return true; + } } return false; diff --git a/Model/TagDataNode.cs b/Model/TagDataNode.cs index 0631752..48235f9 100644 --- a/Model/TagDataNode.cs +++ b/Model/TagDataNode.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -//susing System.Windows.Forms; using Substrate.Nbt; namespace NBTExplorer.Model diff --git a/Windows/FormHandlers.cs b/Windows/FormHandlers.cs index 9653d80..7f22c63 100644 --- a/Windows/FormHandlers.cs +++ b/Windows/FormHandlers.cs @@ -11,6 +11,14 @@ namespace NBTExplorer.Windows FormRegistry.EditString = EditStringHandler; FormRegistry.EditTagScalar = EditTagScalarValueHandler; FormRegistry.RenameTag = RenameTagHandler; + FormRegistry.CreateNode = CreateNodeHandler; + + FormRegistry.MessageBox = MessageBoxHandler; + } + + public static void MessageBoxHandler (string message) + { + MessageBox.Show(message); } public static bool EditStringHandler (StringFormData data) @@ -56,5 +64,19 @@ namespace NBTExplorer.Windows else return false; } + + public static bool CreateNodeHandler (CreateTagFormData data) + { + CreateNodeForm form = new CreateNodeForm(data.TagType, data.HasName); + form.InvalidNames.AddRange(data.RestrictedNames); + + if (form.ShowDialog() == DialogResult.OK) { + data.TagNode = form.TagNode; + data.TagName = form.TagName; + return true; + } + else + return false; + } } }