Index: src/Common/DelftTools.Controls.Swf/CustomInputDialog.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/DelftTools.Controls.Swf/CustomInputDialog.cs (.../CustomInputDialog.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/DelftTools.Controls.Swf/CustomInputDialog.cs (.../CustomInputDialog.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -3,48 +3,30 @@ using System.Drawing; using System.Linq; using System.Windows.Forms; +using DelftTools.Controls.Swf.DataEditorGenerator; using DelftTools.Controls.Swf.DataEditorGenerator.Metadata; using DelftTools.Utils.Reflection; namespace DelftTools.Controls.Swf { public partial class CustomInputDialog : Form { + private readonly Dictionary data = new Dictionary(); + private readonly Dictionary datafields = new Dictionary(); + public CustomInputDialog() { InitializeComponent(); } - - protected override void OnLoad(System.EventArgs e) - { - base.OnLoad(e); - // generate custom input fields: - var objectDescription = new ObjectUIDescription {FieldDescriptions = datafields.Values}; - var dataEditor = DataEditorGenerator.DataEditorGeneratorSwf.GenerateView(objectDescription); - dataEditor.Data = new object(); - - var itemsHeight = 0; - - foreach (var control in dataEditor.Controls.OfType()) + public object this[string dataName] + { + get { - control.WrapContents = false; - control.AutoScroll = false; - itemsHeight = Math.Max(itemsHeight, control.PreferredSize.Height); + return GetValueCore(dataName); } - - dataEditor.Location = new Point(0, 0); - dataEditor.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; - dataEditor.Height = itemsHeight; - dataEditor.Width = Width; - Controls.Add(dataEditor); - - ClientSize = new Size(ClientSize.Width, itemsHeight + btnPanel.Height); } - private readonly Dictionary data = new Dictionary(); - private readonly Dictionary datafields = new Dictionary(); - public FieldUIDescription AddInput(string dataName) { var initialValue = default(T); @@ -53,10 +35,14 @@ public FieldUIDescription AddInput(string dataName, T initialValue) { - if (typeof (T) == typeof (string) && initialValue == null) + if (typeof(T) == typeof(string) && initialValue == null) + { data.Add(dataName, ""); + } else + { data.Add(dataName, initialValue); + } var fieldDescription = new FieldUIDescription(o => GetValueCore(dataName), (o, v) => SetValue(dataName, v)) { @@ -79,13 +65,13 @@ choicesAsStrings, choicesAsStrings); var fieldDescription = new FieldUIDescription( - o => Enum.GetValues(dynamicEnum).GetValue(choices.IndexOf((T) GetValueCore(dataName))), // get - (o, v) => SetValue(dataName, choices[(int) v])) // set - { - Name = dataName, - ValueType = dynamicEnum, - Label = dataName, - }; + o => Enum.GetValues(dynamicEnum).GetValue(choices.IndexOf((T) GetValueCore(dataName))), // get + (o, v) => SetValue(dataName, choices[(int) v])) // set + { + Name = dataName, + ValueType = dynamicEnum, + Label = dataName, + }; datafields.Add(dataName, fieldDescription); return fieldDescription; @@ -96,9 +82,34 @@ return (T) GetValueCore(dataName); } - public object this[string dataName] + protected override void OnLoad(EventArgs e) { - get { return GetValueCore(dataName); } + base.OnLoad(e); + + // generate custom input fields: + var objectDescription = new ObjectUIDescription + { + FieldDescriptions = datafields.Values + }; + var dataEditor = DataEditorGeneratorSwf.GenerateView(objectDescription); + dataEditor.Data = new object(); + + var itemsHeight = 0; + + foreach (var control in dataEditor.Controls.OfType()) + { + control.WrapContents = false; + control.AutoScroll = false; + itemsHeight = Math.Max(itemsHeight, control.PreferredSize.Height); + } + + dataEditor.Location = new Point(0, 0); + dataEditor.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; + dataEditor.Height = itemsHeight; + dataEditor.Width = Width; + Controls.Add(dataEditor); + + ClientSize = new Size(ClientSize.Width, itemsHeight + btnPanel.Height); } private void SetValue(string dataName, object value) @@ -111,14 +122,14 @@ return data[dataName]; } - private void ButtonOk_Click(object sender, System.EventArgs e) + private void ButtonOk_Click(object sender, EventArgs e) { DialogResult = DialogResult.OK; } - private void ButtonCancel_Click(object sender, System.EventArgs e) + private void ButtonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; } } -} +} \ No newline at end of file