public void Events_EditItem(int index, object element, CollectionBoxViewModel.EditElementOp op) { string elementName = "Events[" + index + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(ZoneManager.Instance.CurrentMap.AssetName, elementName, element, typeof(SingleCharEvent), new object[0]); DataEditor.LoadClassControls(frmData.ControlPanel, ZoneManager.Instance.CurrentMap.AssetName, elementName, typeof(SingleCharEvent), new object[0], element, true); frmData.SelectedOKEvent += () => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, typeof(SingleCharEvent), new object[0], true); op(index, element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; DevForm form = (DevForm)DiagManager.Instance.DevEditor; form.MapEditForm.RegisterChild(frmData); frmData.Show(); }
public void MapBG_Edit(object element, ClassBoxViewModel.EditElementOp op) { string elementName = "MapBG"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(ZoneManager.Instance.CurrentGround.AssetName, elementName, element, typeof(MapBG), new object[0]); DataEditor.LoadClassControls(frmData.ControlPanel, ZoneManager.Instance.CurrentGround.AssetName, elementName, typeof(MapBG), new object[0], element, true); frmData.SelectedOKEvent += () => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, typeof(MapBG), new object[0], true); op(element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; DevForm form = (DevForm)DiagManager.Instance.DevEditor; form.GroundEditForm.RegisterChild(frmData); frmData.Show(); }
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); }
//对比数据库 void CompareDB() { if (this.compare1 == null || this.compare2 == null) { return; } string cdb1 = this.compare1.GetOpenFile(); string cdb2 = this.compare2.GetOpenFile(); if (string.IsNullOrEmpty(cdb1) || string.IsNullOrEmpty(cdb2) || cdb1 == cdb2) { return; } bool checktext = MyMsg.Question(LMSG.CheckText); //分别对比数据库 this.compare1.CompareCards(cdb2, checktext); this.compare2.CompareCards(cdb1, checktext); MyMsg.Show(LMSG.CompareOK); this.menuitem_comp2.Enabled = false; this.compare1 = null; this.compare2 = null; }
private void mapFormToolStripMenuItem_Click(object sender, EventArgs e) { DataEditForm edit = new DataEditForm(); edit.PackName = (sender as ToolStripMenuItem).Tag.ToString(); edit.Show(); }
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 void TextureMap_EditItem(object key, object element, DictionaryBoxViewModel.EditElementOp op) { string elementName = "TextureMap[" + key.ToString() + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(ZoneManager.Instance.CurrentMap.AssetName, elementName, element, typeof(AutoTile), new object[0]); DataEditor.LoadClassControls(frmData.ControlPanel, ZoneManager.Instance.CurrentMap.AssetName, elementName, typeof(AutoTile), new object[0], element, true); frmData.SelectedOKEvent += () => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, typeof(AutoTile), new object[0], true); op(key, element); frmData.Close(); }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; DevForm form = (DevForm)DiagManager.Instance.DevEditor; form.MapEditForm.RegisterChild(frmData); frmData.Show(); }
//设置数据库1 void Menuitem_comp1Click(object sender, EventArgs e) { this.compare1 = this.GetActive(); if (this.compare1 != null && !string.IsNullOrEmpty(this.compare1.GetOpenFile())) { this.menuitem_comp2.Enabled = true; this.CompareDB(); } }
//复制选中 void Menuitem_copyselecttoClick(object sender, EventArgs e) { DataEditForm df = GetActive();//获取当前的数据库编辑 if (df != null) { tCards = df.GetCardList(true); //获取选中的卡片 if (tCards != null) { SetCopyNumber(tCards.Length);//显示复制卡片的数量 MyMsg.Show(LMSG.CopyCards); } } }
//复制当前结果 void Menuitem_copyallClick(object sender, EventArgs e) { DataEditForm df = this.GetActive();//获取当前的数据库编辑 if (df != null) { this.tCards = df.GetCardList(false);//获取结果的所有卡片 if (this.tCards != null) { this.SetCopyNumber(this.tCards.Length);//显示复制卡片的数量 MyMsg.Show(LMSG.CopyCards); } } }
//粘贴卡片 void Menuitem_pastecardsClick(object sender, EventArgs e) { if (tCards == null) { return; } DataEditForm df = GetActive(); if (df == null) { return; } df.SaveCards(tCards);//保存卡片 MyMsg.Show(LMSG.PasteCards); }
public void TileStates_EditItem(int index, object element, CollectionBoxViewModel.EditElementOp op) { string elementName = "TileStates[" + index + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle("Tile", elementName, element, typeof(TileState), new object[0]); //TODO: make this a member and reference it that way DataEditor.LoadClassControls(frmData.ControlPanel, "Tile", elementName, typeof(TileState), new object[0], element, true); DevForm form = (DevForm)DiagManager.Instance.DevEditor; frmData.SelectedOKEvent += async() => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, typeof(TileState), new object[0], true); bool itemExists = false; List <object> states = (List <object>)TileStates.GetList(typeof(List <object>)); for (int ii = 0; ii < states.Count; ii++) { if (ii != index) { if (states[ii].GetType() == element.GetType()) { itemExists = true; } } } if (itemExists) { await MessageBox.Show(form.MapEditForm, "Cannot add duplicate states.", "Entry already exists.", MessageBox.MessageBoxButtons.Ok); } else { op(index, element); frmData.Close(); } }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; form.MapEditForm.RegisterChild(frmData); frmData.Show(); }
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); }
//TODO: move these events into ListEditor; they were generic enough to warrant copy+pasting public void Statuses_EditItem(int index, object element, CollectionBoxViewModel.EditElementOp op) { string elementName = "Statuses[" + index + "]"; DataEditForm frmData = new DataEditForm(); frmData.Title = DataEditor.GetWindowTitle(ZoneManager.Instance.CurrentMap.AssetName, elementName, element, typeof(MapStatus), new object[0]); DataEditor.LoadClassControls(frmData.ControlPanel, ZoneManager.Instance.CurrentMap.AssetName, elementName, typeof(MapStatus), new object[0], element, true); DevForm form = (DevForm)DiagManager.Instance.DevEditor; frmData.SelectedOKEvent += async() => { element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, typeof(MapStatus), new object[0], true); bool itemExists = false; List <MapStatus> states = (List <MapStatus>)Statuses.GetList(typeof(List <MapStatus>)); for (int ii = 0; ii < states.Count; ii++) { if (ii != index) { if (states[ii].ID == ((MapStatus)element).ID) { itemExists = true; } } } if (itemExists) { await MessageBox.Show(form.MapEditForm, "Cannot add duplicate IDs.", "Entry already exists.", MessageBox.MessageBoxButtons.Ok); } else { op(index, element); frmData.Close(); } }; frmData.SelectedCancelEvent += () => { frmData.Close(); }; form.MapEditForm.RegisterChild(frmData); frmData.Show(); }
//打开数据库 void OpenDataBase(string file) { DataEditForm def; if (string.IsNullOrEmpty(file) || !File.Exists(file)) { def = new DataEditForm(this.datapath); } else { def = new DataEditForm(this.datapath, file); } //设置语言 LanguageHelper.SetFormLabel(def); //初始化界面数据 def.InitControl(this.datacfg); def.Show(this.dockPanel, DockState.Document); }
static void SaveLanguage() { string datapath = MyPath.Combine(Application.StartupPath, MyConfig.TAG_DATA); string conflang = MyConfig.GetLanguageFile(datapath); LanguageHelper.LoadFormLabels(conflang); LanguageHelper langhelper = new LanguageHelper(); MainForm form1 = new MainForm(); LanguageHelper.SetFormLabel(form1); langhelper.GetFormLabel(form1); DataEditForm form2 = new DataEditForm(); LanguageHelper.SetFormLabel(form2); langhelper.GetFormLabel(form2); CodeEditForm form3 = new CodeEditForm(); LanguageHelper.SetFormLabel(form3); langhelper.GetFormLabel(form3); // LANG.GetFormLabel(this); //获取窗体文字 langhelper.SaveLanguage(conflang + ".bak"); }
//得到当前的数据编辑 DataEditForm GetActive() { DataEditForm df = this.dockPanel.ActiveContent as DataEditForm; return(df); }
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 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); }
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); }
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); } } }