2012-08-24 03:58:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Substrate.Nbt;
|
|
|
|
|
|
|
|
|
|
namespace NBTExplorer
|
|
|
|
|
{
|
|
|
|
|
public partial class EditName : Form
|
|
|
|
|
{
|
2012-08-31 05:29:32 +00:00
|
|
|
|
private string _originalName;
|
2012-08-24 03:58:11 +00:00
|
|
|
|
private string _name;
|
|
|
|
|
|
|
|
|
|
private List<string> _invalidNames = new List<string>();
|
|
|
|
|
|
|
|
|
|
public EditName (String name)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2012-08-31 05:29:32 +00:00
|
|
|
|
_originalName = name;
|
2012-08-24 03:58:11 +00:00
|
|
|
|
_name = name;
|
|
|
|
|
|
|
|
|
|
_nameField.Text = _name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String TagName
|
|
|
|
|
{
|
|
|
|
|
get { return _name; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<string> InvalidNames
|
|
|
|
|
{
|
|
|
|
|
get { return _invalidNames; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 05:29:32 +00:00
|
|
|
|
public bool IsModified
|
|
|
|
|
{
|
|
|
|
|
get { return _name != _originalName; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-24 03:58:11 +00:00
|
|
|
|
private void Apply ()
|
|
|
|
|
{
|
|
|
|
|
if (ValidateInput()) {
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ValidateInput ()
|
|
|
|
|
{
|
|
|
|
|
return ValidateNameInput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ValidateNameInput ()
|
|
|
|
|
{
|
|
|
|
|
string text = _nameField.Text.Trim();
|
|
|
|
|
if (String.IsNullOrEmpty(text)) {
|
|
|
|
|
MessageBox.Show("You must provide a nonempty name.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 05:29:32 +00:00
|
|
|
|
if (text != _originalName && _invalidNames.Contains(text)) {
|
2012-08-24 03:58:11 +00:00
|
|
|
|
MessageBox.Show("Duplicate name provided.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_name = _nameField.Text.Trim();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _buttonOK_Click (object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Apply();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|