public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Int32 member) { LoadLabelControl(control, name); DataTypeAttribute dataAtt = ReflectionExt.FindAttribute <DataTypeAttribute>(attributes); ComboBox cbValue = new ComboBox(); cbValue.VirtualizationMode = ItemVirtualizationMode.Simple; int chosenIndex = member; EntryDataIndex nameIndex = DataManager.Instance.DataIndices[dataAtt.DataType]; List <string> items = new List <string>(); if (dataAtt.IncludeInvalid) { items.Add("---"); chosenIndex++; } for (int ii = 0; ii < nameIndex.Count; ii++) { items.Add(ii.ToString() + ": " + nameIndex.Entries[ii].GetLocalString(false)); } var subject = new Subject <List <string> >(); cbValue.Bind(ComboBox.ItemsProperty, subject); subject.OnNext(items); cbValue.SelectedIndex = Math.Min(Math.Max(0, chosenIndex), items.Count - 1); control.Children.Add(cbValue); }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Int32 member) { LoadLabelControl(control, name); FrameTypeAttribute frameAtt = ReflectionExt.FindAttribute <FrameTypeAttribute>(attributes); ComboBox cbValue = new ComboBox(); cbValue.VirtualizationMode = ItemVirtualizationMode.Simple; int chosenIndex = 0; List <string> items = new List <string>(); for (int ii = 0; ii < GraphicsManager.Actions.Count; ii++) { if (!frameAtt.DashOnly || GraphicsManager.Actions[ii].IsDash) { if (ii == (int)member) { chosenIndex = items.Count; } items.Add(GraphicsManager.Actions[ii].Name); } } var subject = new Subject <List <string> >(); cbValue.Bind(ComboBox.ItemsProperty, subject); subject.OnNext(items); cbValue.SelectedIndex = Math.Min(Math.Max(0, chosenIndex), items.Count - 1); control.Children.Add(cbValue); }
public override Int32 SaveWindowControls(StackPanel control, string name, Type type, object[] attributes) { int controlIndex = 0; controlIndex++; FrameTypeAttribute frameAtt = ReflectionExt.FindAttribute <FrameTypeAttribute>(attributes); ComboBox cbValue = (ComboBox)control.Children[controlIndex]; if (!frameAtt.DashOnly) { return(cbValue.SelectedIndex); } else { int currentDashValue = -1; for (int ii = 0; ii < GraphicsManager.Actions.Count; ii++) { if (GraphicsManager.Actions[ii].IsDash) { currentDashValue++; if (currentDashValue == cbValue.SelectedIndex) { return(ii); } } } } return(0); }
public override IntRange SaveWindowControls(StackPanel control, string name, Type type, object[] attributes) { RangeBorderAttribute rangeAtt = ReflectionExt.FindAttribute <RangeBorderAttribute>(attributes); int addMin = 0; int addMax = 0; if (rangeAtt != null) { rangeAtt.GetAddVals(out addMin, out addMax); } int controlIndex = 0; controlIndex++; Avalonia.Controls.Grid innerControl = (Avalonia.Controls.Grid)control.Children[controlIndex]; int innerControlIndex = 0; innerControlIndex++; NumericUpDown nudValueX = (NumericUpDown)innerControl.Children[innerControlIndex]; innerControlIndex++; innerControlIndex++; NumericUpDown nudValueY = (NumericUpDown)innerControl.Children[innerControlIndex]; return(new IntRange((int)nudValueX.Value - addMin, (int)nudValueY.Value - addMax)); }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IPriorityList member) { LoadLabelControl(control, name); Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IPriorityList <>), type, 0); PriorityListBox lbxValue = new PriorityListBox(); PriorityListBoxViewModel mv = new PriorityListBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(2, attributes))); lbxValue.DataContext = mv; //add lambda expression for editing a single element mv.OnEditItem = (Priority priority, int index, object element, PriorityListBoxViewModel.EditElementOp op) => { string elementName = name + "[" + priority.ToString() + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(2, attributes)); DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), element, true); frmData.SelectedOKEvent += () => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), true); op(priority, index, element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; control.GetOwningForm().RegisterChild(frmData); frmData.Show(); }; mv.OnEditPriority = (Priority priority, int index, PriorityListBoxViewModel.EditPriorityOp op) => { string elementName = name + "<Priority>"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(parent, elementName, priority, typeof(Priority), ReflectionExt.GetPassableAttributes(1, attributes)); DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, typeof(Priority), ReflectionExt.GetPassableAttributes(1, attributes), priority, true); frmData.SelectedOKEvent += () => { object priorityObj = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, typeof(Priority), ReflectionExt.GetPassableAttributes(1, attributes), true); op(priority, index, (Priority)priorityObj); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; control.GetOwningForm().RegisterChild(frmData); frmData.Show(); }; mv.LoadFromList(member); control.Children.Add(lbxValue); }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, String member) { LoadLabelControl(control, name); AnimAttribute animAtt = ReflectionExt.FindAttribute <AnimAttribute>(attributes); ComboBox cbValue = new ComboBox(); cbValue.VirtualizationMode = ItemVirtualizationMode.Simple; string choice = member; List <string> items = new List <string>(); items.Add("---"); int chosenIndex = 0; string[] dirs = PathMod.GetModFiles(GraphicsManager.CONTENT_PATH + animAtt.FolderPath); for (int ii = 0; ii < dirs.Length; ii++) { string filename = Path.GetFileNameWithoutExtension(dirs[ii]); if (filename == choice) { chosenIndex = items.Count; } items.Add(filename); } var subject = new Subject <List <string> >(); cbValue.Bind(ComboBox.ItemsProperty, subject); subject.OnNext(items); cbValue.SelectedIndex = chosenIndex; control.Children.Add(cbValue); }
private CollectionBoxViewModel createViewModel(StackPanel control, string parent, string name, Type type, object[] attributes, IList member, bool index1) { Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IList <>), type, 0); CollectionBoxViewModel mv = new CollectionBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes))); mv.Index1 = index1; //add lambda expression for editing a single element mv.OnEditItem += (int index, object element, CollectionBoxViewModel.EditElementOp op) => { string elementName = name + "[" + index + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(1, attributes)); DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), element, true); frmData.SelectedOKEvent += () => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), true); op(index, element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; control.GetOwningForm().RegisterChild(frmData); frmData.Show(); }; mv.LoadFromList(member); return(mv); }
public override MonsterID SaveWindowControls(StackPanel control, string name, Type type, object[] attributes) { MonsterID result = new MonsterID(); MonsterIDAttribute dataAtt = ReflectionExt.FindAttribute <MonsterIDAttribute>(attributes); int controlIndex = 0; controlIndex++; Avalonia.Controls.Grid innerControl1 = (Avalonia.Controls.Grid)control.Children[controlIndex]; int innerControlIndex = 0; innerControlIndex++; ComboBox cbSpecies = (ComboBox)innerControl1.Children[innerControlIndex]; result.Species = cbSpecies.SelectedIndex; if (dataAtt.InvalidSpecies) { result.Species--; } controlIndex++; Avalonia.Controls.Grid innerControl2 = (Avalonia.Controls.Grid)control.Children[controlIndex]; innerControlIndex = 0; innerControlIndex++; ComboBox cbForm = (ComboBox)innerControl2.Children[innerControlIndex]; result.Form = cbForm.SelectedIndex; if (dataAtt.InvalidForm) { result.Form--; } controlIndex++; Avalonia.Controls.Grid innerControl3 = (Avalonia.Controls.Grid)control.Children[controlIndex]; innerControlIndex = 0; innerControlIndex++; ComboBox cbSkin = (ComboBox)innerControl3.Children[innerControlIndex]; result.Skin = cbSkin.SelectedIndex; if (dataAtt.InvalidSkin) { result.Skin--; } innerControlIndex++; innerControlIndex++; ComboBox cbGender = (ComboBox)innerControl3.Children[innerControlIndex]; result.Gender = (Gender)cbGender.SelectedIndex; if (dataAtt.InvalidGender) { result.Gender--; } return(result); }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IntRange member) { LoadLabelControl(control, name); RangeBorderAttribute rangeAtt = ReflectionExt.FindAttribute <RangeBorderAttribute>(attributes); int addMin = 0; int addMax = 0; if (rangeAtt != null) { rangeAtt.GetAddVals(out addMin, out addMax); } Avalonia.Controls.Grid innerPanel = getSharedRowPanel(4); innerPanel.ColumnDefinitions[0].Width = new GridLength(30); innerPanel.ColumnDefinitions[2].Width = new GridLength(30); TextBlock lblX = new TextBlock(); lblX.Text = "Min:"; lblX.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center; lblX.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right; innerPanel.Children.Add(lblX); lblX.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0); NumericUpDown nudValueX = new NumericUpDown(); nudValueX.Margin = new Thickness(4, 0, 0, 0); nudValueX.Minimum = Int32.MinValue; nudValueX.Maximum = Int32.MaxValue; nudValueX.Value = member.Min + addMin; innerPanel.Children.Add(nudValueX); nudValueX.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1); TextBlock lblY = new TextBlock(); lblY.Margin = new Thickness(8, 0, 0, 0); lblY.Text = "Max:"; lblY.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center; lblY.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right; innerPanel.Children.Add(lblY); lblY.SetValue(Avalonia.Controls.Grid.ColumnProperty, 2); NumericUpDown nudValueY = new NumericUpDown(); nudValueY.Margin = new Thickness(4, 0, 0, 0); nudValueY.Minimum = Int32.MinValue; nudValueY.Maximum = Int32.MaxValue; nudValueY.Value = member.Max + addMax; innerPanel.Children.Add(nudValueY); nudValueY.SetValue(Avalonia.Controls.Grid.ColumnProperty, 3); control.Children.Add(innerPanel); }
public static void DemoData(string dataPath, string ext) { foreach (string dir in PathMod.GetModFiles(dataPath, "*" + ext)) { IEntryData data = (IEntryData)DataManager.LoadData(dir); if (!data.Released) { data = (IEntryData)ReflectionExt.CreateMinimalInstance(data.GetType()); } DataManager.SaveData(dir, data); } }
public override string GetString(Int32 obj, Type type, object[] attributes) { DataTypeAttribute dataAtt = ReflectionExt.FindAttribute <DataTypeAttribute>(attributes); EntryDataIndex nameIndex = DataManager.Instance.DataIndices[dataAtt.DataType]; if (obj >= 0 && obj < nameIndex.Count) { return(nameIndex.Entries[obj].Name.ToLocal()); } return("---"); }
public override Type SaveWindowControls(StackPanel control, string name, Type type, object[] attributes) { int controlIndex = 0; TypeConstraintAttribute dataAtt = ReflectionExt.FindAttribute <TypeConstraintAttribute>(attributes); Type baseType = dataAtt.BaseClass; Type[] children = baseType.GetAssignableTypes(); Avalonia.Controls.Grid subGrid = (Avalonia.Controls.Grid)control.Children[controlIndex]; ComboBox cbValue = (ComboBox)subGrid.Children[1]; return(children[cbValue.SelectedIndex]); }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, FlagType member) { StringTypeConstraintAttribute dataAtt = ReflectionExt.FindAttribute <StringTypeConstraintAttribute>(attributes); if (dataAtt != null) { Type baseType = dataAtt.BaseClass; Type[] children = baseType.GetAssignableTypes(); Avalonia.Controls.Grid sharedRowPanel = getSharedRowPanel(2); TextBlock lblType = new TextBlock(); lblType.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center; lblType.Text = name + ":"; sharedRowPanel.Children.Add(lblType); sharedRowPanel.ColumnDefinitions[0].Width = new GridLength(30); lblType.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0); ComboBox cbValue = new ComboBox(); cbValue.Margin = new Thickness(4, 0, 0, 0); sharedRowPanel.Children.Add(cbValue); cbValue.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1); List <string> items = new List <string>(); int selection = 0; for (int ii = 0; ii < children.Length; ii++) { Type childType = children[ii]; items.Add(childType.GetDisplayName()); if (childType == ((FlagType)member).FullType) { selection = ii; } } var subject = new Subject <List <string> >(); cbValue.Bind(ComboBox.ItemsProperty, subject); subject.OnNext(items); cbValue.SelectedIndex = selection; control.Children.Add(sharedRowPanel); } else { throw new InvalidOperationException("No constraints set for member!"); } }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, ISpawnRangeList member) { LoadLabelControl(control, name); Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ISpawnRangeList <>), type, 0); RangeBorderAttribute rangeAtt = ReflectionExt.FindAttribute <RangeBorderAttribute>(attributes); SpawnRangeListBox lbxValue = new SpawnRangeListBox(); lbxValue.MaxHeight = 260; SpawnRangeListBoxViewModel mv = new SpawnRangeListBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes))); if (rangeAtt != null) { mv.Index1 = rangeAtt.Index1; mv.Inclusive = rangeAtt.Inclusive; } lbxValue.DataContext = mv; //add lambda expression for editing a single element mv.OnEditItem += (int index, object element, SpawnRangeListBoxViewModel.EditElementOp op) => { string elementName = name + "[" + index + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(2, attributes)); DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), element, true); frmData.SelectedOKEvent += () => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), true); op(index, element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; control.GetOwningForm().RegisterChild(frmData); frmData.Show(); }; mv.LoadFromList(member); control.Children.Add(lbxValue); }
public override Int32 SaveWindowControls(StackPanel control, string name, Type type, object[] attributes) { int controlIndex = 0; controlIndex++; DataTypeAttribute dataAtt = ReflectionExt.FindAttribute <DataTypeAttribute>(attributes); ComboBox cbValue = (ComboBox)control.Children[controlIndex]; int returnValue = cbValue.SelectedIndex; if (dataAtt.IncludeInvalid) { returnValue--; } return(returnValue); }
public override void LoadClassControls(ISpawnList obj, TableLayoutPanel control) { SpawnListBox lbxValue = new SpawnListBox(); lbxValue.Dock = DockStyle.Fill; lbxValue.Size = new Size(0, 200); Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ISpawnList <>), obj.GetType(), 0); lbxValue.StringConv = DataEditor.GetStringRep(elementType, new object[0] { }); //add lambda expression for editing a single element lbxValue.OnEditItem = (int index, object element, SpawnListBox.EditElementOp op) => { ElementForm frmData = new ElementForm(); if (element == null) { frmData.Text = "New " + elementType.Name; } else { frmData.Text = element.ToString(); } DataEditor.StaticLoadMemberControl(frmData.ControlPanel, "(SpawnList) [" + index + "]", elementType, new object[0] { }, element, true); frmData.OnOK += (object okSender, EventArgs okE) => { DataEditor.StaticSaveMemberControl(frmData.ControlPanel, "SpawnList", elementType, new object[0] { }, ref element, true); op(index, element); frmData.Close(); }; frmData.OnCancel += (object okSender, EventArgs okE) => { frmData.Close(); }; frmData.Show(); }; lbxValue.LoadFromList(obj.GetType(), obj); control.Controls.Add(lbxValue); }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Single member) { LoadLabelControl(control, name); NumericUpDown nudValue = new NumericUpDown(); nudValue.Minimum = Int32.MinValue; nudValue.Maximum = Int32.MaxValue; NumberRangeAttribute attribute = ReflectionExt.FindAttribute <NumberRangeAttribute>(attributes); if (attribute != null) { nudValue.Minimum = attribute.Min; nudValue.Maximum = attribute.Max; } nudValue.Value = (double)member; control.Children.Add(nudValue); }
public override string GetString(IntRange obj, Type type, object[] attributes) { RangeBorderAttribute rangeAtt = ReflectionExt.FindAttribute <RangeBorderAttribute>(attributes); int addMin = 0; int addMax = 0; if (rangeAtt != null) { rangeAtt.GetAddVals(out addMin, out addMax); } if (obj.Min + addMin + 1 >= obj.Max + addMax) { return(obj.Min.ToString()); } else { return(string.Format("{0}-{1}", obj.Min + addMin, obj.Max + addMax)); } }
public override FlagType SaveWindowControls(StackPanel control, string name, Type type, object[] attributes) { int controlIndex = 0; StringTypeConstraintAttribute dataAtt = ReflectionExt.FindAttribute <StringTypeConstraintAttribute>(attributes); if (dataAtt != null) { Type baseType = dataAtt.BaseClass; Type[] children = baseType.GetAssignableTypes(); Avalonia.Controls.Grid subGrid = (Avalonia.Controls.Grid)control.Children[controlIndex]; ComboBox cbValue = (ComboBox)subGrid.Children[1]; return(new FlagType(children[cbValue.SelectedIndex])); } else { throw new InvalidOperationException("No constraints set for member!"); } }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, String member) { LoadLabelControl(control, name); //for strings, use an edit textbox TextBox txtValue = new TextBox(); //txtValue.Dock = DockStyle.Fill; MultilineAttribute attribute = ReflectionExt.FindAttribute <MultilineAttribute>(attributes); if (attribute != null) { //txtValue.Multiline = true; txtValue.Height = 80; //txtValue.Size = new Size(0, 80); } //else // txtValue.Size = new Size(0, 20); txtValue.Text = (member == null) ? "" : member; control.Children.Add(txtValue); }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Array member) { LoadLabelControl(control, name); RankedListAttribute rangeAtt = ReflectionExt.FindAttribute <RankedListAttribute>(attributes); if (rangeAtt != null) { RankedCollectionBox lbxValue = new RankedCollectionBox(); lbxValue.MaxHeight = 180; lbxValue.DataContext = createViewModel(control, parent, name, type, attributes, member, rangeAtt.Index1); control.Children.Add(lbxValue); } else { CollectionBox lbxValue = new CollectionBox(); lbxValue.MaxHeight = 180; lbxValue.DataContext = createViewModel(control, parent, name, type, attributes, member, false); control.Children.Add(lbxValue); } }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IDictionary member) { LoadLabelControl(control, name); Type keyType = ReflectionExt.GetBaseTypeArg(typeof(IDictionary <,>), type, 0); Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IDictionary <,>), type, 1); DictionaryBox lbxValue = new DictionaryBox(); lbxValue.MaxHeight = 180; DictionaryBoxViewModel mv = new DictionaryBoxViewModel(control.GetOwningForm(), new StringConv(elementType, ReflectionExt.GetPassableAttributes(2, attributes))); lbxValue.DataContext = mv; //add lambda expression for editing a single element mv.OnEditItem += (object key, object element, DictionaryBoxViewModel.EditElementOp op) => { string elementName = name + "[" + key.ToString() + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(2, attributes)); DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), element, true); frmData.SelectedOKEvent += () => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), true); op(key, element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; control.GetOwningForm().RegisterChild(frmData); frmData.Show(); }; mv.OnEditKey += (object key, object element, DictionaryBoxViewModel.EditElementOp op) => { string elementName = name + "<Key>"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(parent, elementName, key, keyType, ReflectionExt.GetPassableAttributes(1, attributes)); DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, keyType, ReflectionExt.GetPassableAttributes(1, attributes), key, true); frmData.SelectedOKEvent += () => { key = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, keyType, ReflectionExt.GetPassableAttributes(1, attributes), true); op(key, element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; control.GetOwningForm().RegisterChild(frmData); frmData.Show(); }; mv.LoadFromDict(member); control.Children.Add(lbxValue); }
void IEditor.LoadClassControls(StackPanel control, string parent, string name, Type type, object[] attributes, object member, bool isWindow) { //if you want a class that is by default isolated to a classbox but has a custom UI when opened on its own/overridden to render, //override LoadWindowControls, which is called by those methods. //in all cases where the class itself isn't being rendered to the window, simply represent as an editable object //isWindow will force subgroup automatically //otherwise, the presence of a Subgroup attribute will force it (or the presence of a Separation attribute will force it into its own classbox) //then defaultSubgroup will force it. bool subGroup = DefaultSubgroup; if (ReflectionExt.FindAttribute <SepGroupAttribute>(attributes) != null) { subGroup = false; } if (ReflectionExt.FindAttribute <SubGroupAttribute>(attributes) != null) { subGroup = true; } if (isWindow) { subGroup = true; } if (!subGroup) { LoadLabelControl(control, name); if (member == null) { Type[] children; if (DefaultType) { children = new Type[1] { type } } ; else { children = type.GetAssignableTypes(); } //create an empty instance member = ReflectionExt.CreateMinimalInstance(children[0]); } ClassBox cbxValue = new ClassBox(); MultilineAttribute attribute = ReflectionExt.FindAttribute <MultilineAttribute>(attributes); if (attribute != null) { //txtValue.Multiline = true; cbxValue.Height = 80; //txtValue.Size = new Size(0, 80); } //else // txtValue.Size = new Size(0, 20); ClassBoxViewModel mv = new ClassBoxViewModel(new StringConv(type, ReflectionExt.GetPassableAttributes(0, attributes))); mv.LoadFromSource(member); cbxValue.DataContext = mv; control.Children.Add(cbxValue); //add lambda expression for editing a single element mv.OnEditItem += (object element, ClassBoxViewModel.EditElementOp op) => { DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(parent, name, element, type, ReflectionExt.GetPassableAttributes(0, attributes)); DataEditor.LoadClassControls(frmData.ControlPanel, parent, name, type, ReflectionExt.GetPassableAttributes(0, attributes), element, true); frmData.SelectedOKEvent += () => { element = DataEditor.SaveClassControls(frmData.ControlPanel, name, type, ReflectionExt.GetPassableAttributes(0, attributes), true); op(element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; control.GetOwningForm().RegisterChild(frmData); frmData.Show(); }; { ContextMenu copyPasteStrip = new ContextMenu(); MenuItem copyToolStripMenuItem = new MenuItem(); MenuItem pasteToolStripMenuItem = new MenuItem(); Avalonia.Collections.AvaloniaList <object> list = (Avalonia.Collections.AvaloniaList <object>)copyPasteStrip.Items; list.AddRange(new MenuItem[] { copyToolStripMenuItem, pasteToolStripMenuItem }); copyToolStripMenuItem.Header = "Copy " + type.Name; pasteToolStripMenuItem.Header = "Paste " + type.Name; copyToolStripMenuItem.Click += (object copySender, RoutedEventArgs copyE) => { DataEditor.SetClipboardObj(mv.Object); }; pasteToolStripMenuItem.Click += async(object copySender, RoutedEventArgs copyE) => { Type type1 = DataEditor.clipboardObj.GetType(); Type type2 = type; if (type2.IsAssignableFrom(type1)) { mv.LoadFromSource(DataEditor.clipboardObj); } else { await MessageBox.Show(control.GetOwningForm(), String.Format("Incompatible types:\n{0}\n{1}", type1.AssemblyQualifiedName, type2.AssemblyQualifiedName), "Invalid Operation", MessageBox.MessageBoxButtons.Ok); } }; control.ContextMenu = copyPasteStrip; } } else { //when being drawn as a subgroup, we have 2 options: //(A) include a label and border, OR //(B) add controls directly to the current stackpanel? //additionally, there will be complications when the Type for a member has child classes //in this case, (A) choosing to have a label and border will result in label over the type dropdown, and border in the chosen class //(B) choosing not to have a label and border will remove the label, but still have a dropdown and contain it a child stackpanel, without border or margin //when isWindow is true, we never want option A. No label, no border, no margin //when isWindow is false, (which means either subgroup or defaultsubgroup is active) it's up to the editor itself to decide bool includeDecoration = DefaultDecoration; if (isWindow) { includeDecoration = false; } //if it's a class of its own, create a new panel //then pass it into the call //use the returned "ref" int to determine how big the panel should be //continue from there Type[] children; if (DefaultType) { children = new Type[1] { type } } ; else { children = type.GetAssignableTypes(); } //handle null members by getting an instance of the FIRST instantiatable subclass (including itself) it can find if (member == null) { member = ReflectionExt.CreateMinimalInstance(children[0]); } if (children.Length < 1) { throw new Exception("Completely abstract field found for: " + name); } else if (children.Length == 1) { Type memberType = member.GetType(); if (children[0] != memberType) { throw new TargetException("Types do not match."); } StackPanel controlParent = control; if (includeDecoration) { LoadLabelControl(control, name); Border border = new Border(); border.BorderThickness = new Thickness(1); border.BorderBrush = Avalonia.Media.Brushes.LightGray; border.Margin = new Thickness(2); control.Children.Add(border); StackPanel groupBoxPanel = new StackPanel(); groupBoxPanel.Margin = new Thickness(2); border.Child = groupBoxPanel; controlParent = groupBoxPanel; } { ContextMenu copyPasteStrip = new ContextMenu(); MenuItem copyToolStripMenuItem = new MenuItem(); MenuItem pasteToolStripMenuItem = new MenuItem(); Avalonia.Collections.AvaloniaList <object> list = (Avalonia.Collections.AvaloniaList <object>)copyPasteStrip.Items; list.AddRange(new MenuItem[] { copyToolStripMenuItem, pasteToolStripMenuItem }); copyToolStripMenuItem.Header = "Copy " + type.Name; pasteToolStripMenuItem.Header = "Paste " + type.Name; copyToolStripMenuItem.Click += (object copySender, RoutedEventArgs copyE) => { object obj = DataEditor.SaveWindowControls(controlParent, name, children[0], attributes); DataEditor.SetClipboardObj(obj); }; pasteToolStripMenuItem.Click += async(object copySender, RoutedEventArgs copyE) => { Type type1 = DataEditor.clipboardObj.GetType(); Type type2 = type; if (type2.IsAssignableFrom(type1)) { controlParent.Children.Clear(); DataEditor.LoadWindowControls(controlParent, parent, name, type1, attributes, DataEditor.clipboardObj); } else { await MessageBox.Show(control.GetOwningForm(), String.Format("Incompatible types:\n{0}\n{1}", type1.AssemblyQualifiedName, type2.AssemblyQualifiedName), "Invalid Operation", MessageBox.MessageBoxButtons.Ok); } }; control.ContextMenu = copyPasteStrip; } controlParent.Background = Avalonia.Media.Brushes.Transparent; DataEditor.LoadWindowControls(controlParent, parent, name, children[0], attributes, member); } else { //note: considerations must be made when dealing with inheritance/polymorphism //eg: find all children in this assembly that can be instantiated, //add them to different panels //show the one that is active right now //include a combobox for switching children StackPanel controlParent = null; if (includeDecoration) { LoadLabelControl(control, name); } Grid sharedRowPanel = getSharedRowPanel(2); TextBlock lblType = new TextBlock(); lblType.Text = "Type:"; lblType.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center; sharedRowPanel.Children.Add(lblType); sharedRowPanel.ColumnDefinitions[0].Width = new GridLength(30); lblType.SetValue(Grid.ColumnProperty, 0); ComboBox cbValue = new ComboBox(); cbValue.Margin = new Thickness(4, 0, 0, 0); cbValue.VirtualizationMode = ItemVirtualizationMode.Simple; sharedRowPanel.Children.Add(cbValue); cbValue.SetValue(Grid.ColumnProperty, 1); control.Children.Add(sharedRowPanel); if (includeDecoration) { Border border = new Border(); border.BorderThickness = new Thickness(1); border.BorderBrush = Avalonia.Media.Brushes.LightGray; border.Margin = new Thickness(2); control.Children.Add(border); StackPanel groupBoxPanel = new StackPanel(); groupBoxPanel.Margin = new Thickness(2); border.Child = groupBoxPanel; controlParent = groupBoxPanel; } else { StackPanel groupBoxPanel = new StackPanel(); control.Children.Add(groupBoxPanel); controlParent = groupBoxPanel; } List <CreateMethod> createMethods = new List <CreateMethod>(); bool refreshPanel = true; List <string> items = new List <string>(); int selection = -1; for (int ii = 0; ii < children.Length; ii++) { Type childType = children[ii]; items.Add(childType.GetDisplayName()); createMethods.Add(() => { if (refreshPanel) { controlParent.Children.Clear(); object emptyMember = ReflectionExt.CreateMinimalInstance(childType); DataEditor.LoadWindowControls(controlParent, parent, name, childType, attributes, emptyMember);//TODO: POTENTIAL INFINITE RECURSION? } }); if (childType == member.GetType()) { selection = ii; } } if (selection == -1) { throw new TargetException("Types do not match."); } var subject = new Subject <List <string> >(); cbValue.Bind(ComboBox.ItemsProperty, subject); subject.OnNext(items); cbValue.SelectedIndex = selection; cbValue.SelectionChanged += (object sender, SelectionChangedEventArgs e) => { createMethods[cbValue.SelectedIndex](); }; { ContextMenu copyPasteStrip = new ContextMenu(); MenuItem copyToolStripMenuItem = new MenuItem(); MenuItem pasteToolStripMenuItem = new MenuItem(); Avalonia.Collections.AvaloniaList <object> list = (Avalonia.Collections.AvaloniaList <object>)copyPasteStrip.Items; list.AddRange(new MenuItem[] { copyToolStripMenuItem, pasteToolStripMenuItem }); copyToolStripMenuItem.Header = "Copy " + type.Name; pasteToolStripMenuItem.Header = "Paste " + type.Name; copyToolStripMenuItem.Click += (object copySender, RoutedEventArgs copyE) => { object obj = DataEditor.SaveWindowControls(controlParent, name, children[cbValue.SelectedIndex], attributes); DataEditor.SetClipboardObj(obj); }; pasteToolStripMenuItem.Click += async(object copySender, RoutedEventArgs copyE) => { Type type1 = DataEditor.clipboardObj.GetType(); Type type2 = type; int type_idx = -1; for (int ii = 0; ii < children.Length; ii++) { if (children[ii] == type1) { type_idx = ii; break; } } if (type_idx > -1) { refreshPanel = false; cbValue.SelectedIndex = type_idx; refreshPanel = true; controlParent.Children.Clear(); DataEditor.LoadWindowControls(controlParent, parent, name, type1, attributes, DataEditor.clipboardObj); } else { await MessageBox.Show(control.GetOwningForm(), String.Format("Incompatible types:\n{0}\n{1}", type1.AssemblyQualifiedName, type2.AssemblyQualifiedName), "Invalid Operation", MessageBox.MessageBoxButtons.Ok); } }; control.ContextMenu = copyPasteStrip; } controlParent.Background = Avalonia.Media.Brushes.Transparent; DataEditor.LoadWindowControls(controlParent, parent, name, children[selection], attributes, member); } } }
object IEditor.SaveClassControls(StackPanel control, string name, Type type, object[] attributes, bool isWindow) { int controlIndex = 0; bool subGroup = DefaultSubgroup; if (ReflectionExt.FindAttribute <SepGroupAttribute>(attributes) != null) { subGroup = false; } if (ReflectionExt.FindAttribute <SubGroupAttribute>(attributes) != null) { subGroup = true; } if (isWindow) { subGroup = true; } if (!subGroup) { controlIndex++; ClassBox cbxValue = (ClassBox)control.Children[controlIndex]; ClassBoxViewModel mv = (ClassBoxViewModel)cbxValue.DataContext; return(mv.Object); } else { Type[] children; if (DefaultType) { children = new Type[1] { type } } ; else { children = type.GetAssignableTypes(); } //need to create a new instance //note: considerations must be made when dealing with inheritance/polymorphism //eg: check to see if there are children of the type, //and if so, do this instead: //get the combobox index determining the type //instantiate the type //get the panel for the index //save using THAT panel bool includeDecoration = DefaultDecoration; if (isWindow) { includeDecoration = false; } if (children.Length == 1) { StackPanel chosenParent = control; if (includeDecoration) { controlIndex++; Border border = (Border)control.Children[controlIndex]; chosenParent = (StackPanel)border.Child; } return(DataEditor.SaveWindowControls(chosenParent, name, children[0], attributes)); } else { StackPanel chosenParent = null; if (includeDecoration) { controlIndex++; } Grid subGrid = (Grid)control.Children[controlIndex]; ComboBox cbValue = (ComboBox)subGrid.Children[1]; controlIndex++; if (includeDecoration) { Border border = (Border)control.Children[controlIndex]; chosenParent = (StackPanel)border.Child; } else { chosenParent = (StackPanel)control.Children[controlIndex]; } return(DataEditor.SaveWindowControls(chosenParent, name, children[cbValue.SelectedIndex], attributes)); } } }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, MonsterID member) { LoadLabelControl(control, name); MonsterIDAttribute dataAtt = ReflectionExt.FindAttribute <MonsterIDAttribute>(attributes); { Avalonia.Controls.Grid innerPanel1 = getSharedRowPanel(2); TextBlock lblSpecies = new TextBlock(); lblSpecies.Text = "Species:"; lblSpecies.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center; lblSpecies.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right; innerPanel1.Children.Add(lblSpecies); innerPanel1.ColumnDefinitions[0].Width = new GridLength(46); lblSpecies.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0); ComboBox cbSpecies = new ComboBox(); ComboBox cbForms = new ComboBox(); cbSpecies.VirtualizationMode = ItemVirtualizationMode.Simple; int chosenSpecies = member.Species; EntryDataIndex nameIndex = DataManager.Instance.DataIndices[DataManager.DataType.Monster]; List <string> species = new List <string>(); List <string> forms = new List <string>(); if (dataAtt.InvalidSpecies) { species.Add("---"); chosenSpecies++; } for (int ii = 0; ii < nameIndex.Count; ii++) { species.Add(ii.ToString() + ": " + nameIndex.Entries[ii].GetLocalString(false)); } var speciesSubject = new Subject <List <string> >(); var formSubject = new Subject <List <string> >(); cbSpecies.Bind(ComboBox.ItemsProperty, speciesSubject); speciesSubject.OnNext(species); cbSpecies.SelectedIndex = Math.Min(Math.Max(0, chosenSpecies), species.Count - 1); cbSpecies.SelectionChanged += (object sender, SelectionChangedEventArgs e) => { loadForms(dataAtt, cbSpecies.SelectedIndex, forms); cbForms.SelectedIndex = -1; cbForms.SelectedIndex = Math.Min(Math.Max(0, cbForms.SelectedIndex), forms.Count - 1); formSubject.OnNext(forms); }; innerPanel1.Children.Add(cbSpecies); cbSpecies.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1); control.Children.Add(innerPanel1); Avalonia.Controls.Grid innerPanel2 = getSharedRowPanel(2); TextBlock lblForm = new TextBlock(); lblForm.Margin = new Thickness(8, 0, 0, 0); lblForm.Text = "Form:"; lblForm.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center; lblForm.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right; innerPanel2.Children.Add(lblForm); innerPanel2.ColumnDefinitions[0].Width = new GridLength(46); lblForm.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0); cbForms.VirtualizationMode = ItemVirtualizationMode.Simple; int chosenForm = member.Form; loadForms(dataAtt, member.Species, forms); if (dataAtt.InvalidForm) { chosenForm++; } cbForms.Bind(ComboBox.ItemsProperty, formSubject); formSubject.OnNext(forms); cbForms.SelectedIndex = Math.Min(Math.Max(0, chosenForm), forms.Count - 1); innerPanel2.Children.Add(cbForms); cbForms.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1); control.Children.Add(innerPanel2); } Avalonia.Controls.Grid innerPanel3 = getSharedRowPanel(4); { TextBlock lblSkin = new TextBlock(); lblSkin.Margin = new Thickness(8, 0, 0, 0); lblSkin.Text = "Skin:"; lblSkin.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center; lblSkin.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right; innerPanel3.Children.Add(lblSkin); innerPanel3.ColumnDefinitions[0].Width = new GridLength(46); lblSkin.SetValue(Avalonia.Controls.Grid.ColumnProperty, 0); ComboBox cbSkin = new ComboBox(); cbSkin.VirtualizationMode = ItemVirtualizationMode.Simple; int chosenIndex = member.Skin; EntryDataIndex nameIndex = DataManager.Instance.DataIndices[DataManager.DataType.Skin]; List <string> items = new List <string>(); if (dataAtt.InvalidSkin) { items.Add("---"); chosenIndex++; } for (int ii = 0; ii < nameIndex.Count; ii++) { items.Add(ii.ToString() + ": " + nameIndex.Entries[ii].GetLocalString(false)); } var subject = new Subject <List <string> >(); cbSkin.Bind(ComboBox.ItemsProperty, subject); subject.OnNext(items); cbSkin.SelectedIndex = Math.Min(Math.Max(0, chosenIndex), items.Count - 1); innerPanel3.Children.Add(cbSkin); cbSkin.SetValue(Avalonia.Controls.Grid.ColumnProperty, 1); } { TextBlock lblGender = new TextBlock(); lblGender.Margin = new Thickness(8, 0, 0, 0); lblGender.Text = "Gender:"; lblGender.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center; lblGender.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right; innerPanel3.Children.Add(lblGender); innerPanel3.ColumnDefinitions[2].Width = new GridLength(46); lblGender.SetValue(Avalonia.Controls.Grid.ColumnProperty, 2); ComboBox cbGender = new ComboBox(); cbGender.VirtualizationMode = ItemVirtualizationMode.Simple; int chosenIndex = (int)member.Gender; List <string> items = new List <string>(); if (dataAtt.InvalidGender) { items.Add("---"); chosenIndex++; } for (int ii = 0; ii <= (int)Gender.Female; ii++) { items.Add(((Gender)ii).ToLocal()); } var subject = new Subject <List <string> >(); cbGender.Bind(ComboBox.ItemsProperty, subject); subject.OnNext(items); cbGender.SelectedIndex = Math.Min(Math.Max(0, chosenIndex), items.Count - 1); innerPanel3.Children.Add(cbGender); cbGender.SetValue(Avalonia.Controls.Grid.ColumnProperty, 3); } control.Children.Add(innerPanel3); }
public override void LoadClassControls(ITypeDict obj, TableLayoutPanel control) { CollectionBox lbxValue = new CollectionBox(); lbxValue.Dock = DockStyle.Fill; lbxValue.Size = new Size(0, 150); Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ITypeDict <>), obj.GetType(), 0); lbxValue.StringConv = DataEditor.GetStringRep(elementType, new object[0] { }); //add lambda expression for editing a single element lbxValue.OnEditItem = (int index, object element, CollectionBox.EditElementOp op) => { ElementForm frmData = new ElementForm(); if (element == null) { frmData.Text = "New " + elementType.Name; } else { frmData.Text = element.ToString(); } DataEditor.StaticLoadMemberControl(frmData.ControlPanel, "(StateCollection) [" + index + "]", elementType, new object[0] { }, element, true); frmData.OnOK += (object okSender, EventArgs okE) => { DataEditor.StaticSaveMemberControl(frmData.ControlPanel, "StateCollection", elementType, new object[0] { }, ref element, true); bool itemExists = false; for (int ii = 0; ii < lbxValue.Collection.Count; ii++) { if (ii != index) { if (lbxValue.Collection[ii].GetType() == element.GetType()) { itemExists = true; } } } if (itemExists) { MessageBox.Show("Cannot add duplicate states.", "Entry already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { op(index, element); frmData.Close(); } }; frmData.OnCancel += (object okSender, EventArgs okE) => { frmData.Close(); }; frmData.Show(); }; List <object> states = new List <object>(); foreach (object state in obj) { states.Add(state); } lbxValue.LoadFromList(typeof(List <object>), states); control.Controls.Add(lbxValue); }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IRangeDict member) { LoadLabelControl(control, name); Type keyType = typeof(IntRange); Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IRangeDict <>), type, 0); RangeBorderAttribute rangeAtt = ReflectionExt.FindAttribute <RangeBorderAttribute>(attributes); RangeDictBox lbxValue = new RangeDictBox(); lbxValue.MaxHeight = 180; RangeDictBoxViewModel mv = new RangeDictBoxViewModel(control.GetOwningForm(), new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes))); if (rangeAtt != null) { mv.Index1 = rangeAtt.Index1; mv.Inclusive = rangeAtt.Inclusive; } lbxValue.DataContext = mv; //add lambda expression for editing a single element mv.OnEditItem += (IntRange key, object element, RangeDictBoxViewModel.EditElementOp op) => { string elementName = name + "[" + key.ToString() + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(1, attributes)); DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), element, true); frmData.SelectedOKEvent += () => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), true); op(key, element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; control.GetOwningForm().RegisterChild(frmData); frmData.Show(); }; mv.OnEditKey += (IntRange key, object element, RangeDictBoxViewModel.EditElementOp op) => { string elementName = name + "<Range>"; DataEditForm frmKey = new DataEditForm(); List <object> attrList = new List <object>(); if (rangeAtt != null) { attrList.Add(rangeAtt); } frmKey.Title = DataEditor.GetWindowTitle(parent, elementName, key, keyType, attrList.ToArray()); DataEditor.LoadClassControls(frmKey.ControlPanel, parent, elementName, keyType, attrList.ToArray(), key, true); frmKey.SelectedOKEvent += () => { key = (IntRange)DataEditor.SaveClassControls(frmKey.ControlPanel, elementName, keyType, attrList.ToArray(), true); op(key, element); frmKey.Close(); }; frmKey.SelectedCancelEvent += () => { frmKey.Close(); }; control.GetOwningForm().RegisterChild(frmKey); frmKey.Show(); }; mv.LoadFromDict(member); control.Children.Add(lbxValue); }
public virtual T SaveWindowControls(StackPanel control, string name, Type type, object[] attributes) { try { //create instance of type here; object always starts null? T obj = (T)ReflectionExt.CreateMinimalInstance(type); List <MemberInfo> myFields = type.GetEditableMembers(); List <List <MemberInfo> > tieredFields = new List <List <MemberInfo> >(); for (int ii = 0; ii < myFields.Count; ii++) { if (myFields[ii].GetCustomAttributes(typeof(NonEditedAttribute), false).Length > 0) { continue; } if (myFields[ii].GetCustomAttributes(typeof(NonSerializedAttribute), false).Length > 0) { continue; } object member = myFields[ii].GetValue(obj); if (member == null && myFields[ii].GetCustomAttributes(typeof(NonNullAttribute), false).Length > 0) { throw new Exception("Null class member found in " + type.ToString() + ": " + myFields[ii].Name); } if (myFields[ii].GetCustomAttributes(typeof(SharedRowAttribute), false).Length == 0) { tieredFields.Add(new List <MemberInfo>()); } tieredFields[tieredFields.Count - 1].Add(myFields[ii]); } int controlIndex = 0; for (int ii = 0; ii < tieredFields.Count; ii++) { if (tieredFields[ii].Count == 1) { MemberInfo myInfo = tieredFields[ii][0]; object member = DataEditor.SaveMemberControl(obj, (StackPanel)control.Children[controlIndex], myInfo.Name, myInfo.GetMemberInfoType(), myInfo.GetCustomAttributes(false), false); myInfo.SetValue(obj, member); controlIndex++; } else { Grid sharedRowControl = (Grid)control.Children[controlIndex]; int sharedRowControlIndex = 0; for (int jj = 0; jj < tieredFields[ii].Count; jj++) { MemberInfo myInfo = tieredFields[ii][jj]; object member = DataEditor.SaveMemberControl(obj, (StackPanel)sharedRowControl.Children[jj], myInfo.Name, myInfo.GetMemberInfoType(), myInfo.GetCustomAttributes(false), false); myInfo.SetValue(obj, member); sharedRowControlIndex++; } controlIndex++; } } return(obj); } catch (Exception e) { DiagManager.Instance.LogError(e); return(default(T)); } }
public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IList member) { LoadLabelControl(control, name); Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IList <>), member.GetType(), 0); CollectionBox lbxValue = new CollectionBox(); lbxValue.MaxHeight = 180; CollectionBoxViewModel mv = new CollectionBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes))); lbxValue.DataContext = mv; //add lambda expression for editing a single element mv.OnEditItem += (int index, object element, CollectionBoxViewModel.EditElementOp op) => { string elementName = name + "[" + index + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(1, attributes)); //TODO: make this a member and reference it that way DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), element, true); frmData.SelectedOKEvent += async() => { object newElement = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), true); bool itemExists = false; List <object> states = (List <object>)mv.GetList(typeof(List <object>)); for (int ii = 0; ii < states.Count; ii++) { //ignore the current index being edited //if the element is null, then we are editing a new object, so skip if (ii != index || element == null) { if (states[ii].Equals(newElement)) { itemExists = true; } } } if (itemExists) { await MessageBox.Show(control.GetOwningForm(), "Cannot add duplicate states.", "Entry already exists.", MessageBox.MessageBoxButtons.Ok); } else { op(index, newElement); frmData.Close(); } }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; control.GetOwningForm().RegisterChild(frmData); frmData.Show(); }; List <object> states = new List <object>(); foreach (object state in member) { states.Add(state); } mv.LoadFromList(states); control.Children.Add(lbxValue); }