TBF.UI : Item.EditXyz added.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace TBF.UI.Item
|
||||
{
|
||||
public class EditEnum<T> : IEditItem where T : IComparable
|
||||
{
|
||||
string name;
|
||||
T variable;
|
||||
IEnumerable<T> values;
|
||||
string[] strValues;
|
||||
ComboBox comboBox;
|
||||
|
||||
public EditEnum(string name, ref T variable, IList<T>values, string[] strValues)
|
||||
{
|
||||
if (values.Count != strValues.Length) throw new Exception("values and strValues lengths are different");
|
||||
|
||||
this.name = name;
|
||||
this.variable = variable;
|
||||
this.values = values;
|
||||
this.strValues = strValues;
|
||||
|
||||
this.comboBox = new ComboBox();
|
||||
foreach (var v in strValues) comboBox.Items.Add(v);
|
||||
}
|
||||
|
||||
public string Name() { return name; }
|
||||
public Control EmbeddedControl() { return comboBox; }
|
||||
|
||||
public string Print()
|
||||
{
|
||||
int ix = 0;
|
||||
foreach (var v in values)
|
||||
{
|
||||
if (v.CompareTo(variable) == 0) return strValues[ix];
|
||||
ix++;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void Update(string strValue)
|
||||
{
|
||||
int ix = 0;
|
||||
foreach (var v in values)
|
||||
{
|
||||
if (strValues[ix++].Equals(strValue))
|
||||
{
|
||||
variable = v;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Validate(string strValue, out string message)
|
||||
{
|
||||
foreach (var sv in strValues)
|
||||
{
|
||||
if (sv == strValue)
|
||||
{
|
||||
message = string.Empty;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
message = string.Format("{0} is invalid", name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user