Factored more Windows.Forms out of the model.

This commit is contained in:
Justin Aquadro 2012-11-05 00:33:30 -05:00
parent 491b13aec3
commit f942697af5
8 changed files with 58 additions and 16 deletions

View file

@ -10,11 +10,15 @@ namespace NBTExplorer
public delegate bool EditRestrictedStringAction (RestrictedStringFormData data); public delegate bool EditRestrictedStringAction (RestrictedStringFormData data);
public delegate bool EditTagScalarAction (TagScalarFormData data); public delegate bool EditTagScalarAction (TagScalarFormData data);
public delegate bool EditByteArrayAction (ByteArrayFormData data); public delegate bool EditByteArrayAction (ByteArrayFormData data);
public delegate bool CreateNodeAction (CreateTagFormData data);
public static EditStringAction EditString { get; set; } public static EditStringAction EditString { get; set; }
public static EditRestrictedStringAction RenameTag { get; set; } public static EditRestrictedStringAction RenameTag { get; set; }
public static EditTagScalarAction EditTagScalar { get; set; } public static EditTagScalarAction EditTagScalar { get; set; }
public static EditByteArrayAction EditByteArray { get; set; } public static EditByteArrayAction EditByteArray { get; set; }
public static CreateNodeAction CreateNode { get; set; }
public static Action<string> MessageBox { get; set; }
} }
public class TagScalarFormData public class TagScalarFormData
@ -52,6 +56,21 @@ namespace NBTExplorer
} }
} }
public class CreateTagFormData
{
public CreateTagFormData ()
{
RestrictedNames = new List<string>();
}
public TagType TagType { get; set; }
public bool HasName { get; set; }
public List<String> RestrictedNames { get; private set; }
public TagNode TagNode { get; set; }
public string TagName { get; set; }
}
public class ByteArrayFormData public class ByteArrayFormData
{ {
public string NodeName { get; set; } public string NodeName { get; set; }

View file

@ -1,6 +1,5 @@
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace NBTExplorer.Model namespace NBTExplorer.Model
{ {
@ -60,7 +59,8 @@ namespace NBTExplorer.Model
} }
} }
catch { 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.");
} }
} }

View file

@ -1,7 +1,7 @@
using System.IO; using System.IO;
using System.Text.RegularExpressions;
using Substrate.Core; using Substrate.Core;
using Substrate.Nbt; using Substrate.Nbt;
using System.Text.RegularExpressions;
namespace NBTExplorer.Model namespace NBTExplorer.Model
{ {

View file

@ -1,6 +1,6 @@
using Substrate.Core; using System.IO;
using Substrate.Core;
using Substrate.Nbt; using Substrate.Nbt;
using System.IO;
namespace NBTExplorer.Model namespace NBTExplorer.Model
{ {

View file

@ -1,7 +1,6 @@
using System.IO; using System.IO;
using System.Windows.Forms;
using Substrate.Core;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Substrate.Core;
namespace NBTExplorer.Model namespace NBTExplorer.Model
{ {
@ -61,7 +60,8 @@ namespace NBTExplorer.Model
} }
} }
catch { 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.");
} }
} }

View file

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms;
using NBTExplorer.Windows;
using Substrate.Nbt; using Substrate.Nbt;
namespace NBTExplorer.Model namespace NBTExplorer.Model
@ -50,12 +48,16 @@ namespace NBTExplorer.Model
if (!CanCreateTag(type)) if (!CanCreateTag(type))
return false; return false;
CreateNodeForm form = new CreateNodeForm(type, true); if (FormRegistry.CreateNode != null) {
form.InvalidNames.AddRange(_container.TagNamesInUse); CreateTagFormData data = new CreateTagFormData() {
TagType = type, HasName = true,
};
data.RestrictedNames.AddRange(_container.TagNamesInUse);
if (form.ShowDialog() == DialogResult.OK) { if (FormRegistry.CreateNode(data)) {
AddTag(form.TagNode, form.TagName); AddTag(data.TagNode, data.TagName);
return true; return true;
}
} }
return false; return false;

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
//susing System.Windows.Forms;
using Substrate.Nbt; using Substrate.Nbt;
namespace NBTExplorer.Model namespace NBTExplorer.Model

View file

@ -11,6 +11,14 @@ namespace NBTExplorer.Windows
FormRegistry.EditString = EditStringHandler; FormRegistry.EditString = EditStringHandler;
FormRegistry.EditTagScalar = EditTagScalarValueHandler; FormRegistry.EditTagScalar = EditTagScalarValueHandler;
FormRegistry.RenameTag = RenameTagHandler; FormRegistry.RenameTag = RenameTagHandler;
FormRegistry.CreateNode = CreateNodeHandler;
FormRegistry.MessageBox = MessageBoxHandler;
}
public static void MessageBoxHandler (string message)
{
MessageBox.Show(message);
} }
public static bool EditStringHandler (StringFormData data) public static bool EditStringHandler (StringFormData data)
@ -56,5 +64,19 @@ namespace NBTExplorer.Windows
else else
return false; 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;
}
} }
} }