void UpdateView(View view) { if (view.Layout == null) { if (view.LayoutInfo == null) { StructField[] field = new StructField[this.fields.Values.Count]; this.fields.Values.CopyTo(field, 0); view.Layout = new RawLayout(field, CreateControl); } else { view.Layout = NekoKun.Core.ReflectionHelper.CreateInstanceFromTypeName( view.LayoutInfo.Attributes["Type"].Value, view.LayoutInfo, new CreateControlDelegate(CreateControl) ) as IStructEditorLayout; } tab.TabPages[this.views.IndexOf(view)].Controls.Add(view.Layout as System.Windows.Forms.Control); view.IsFresh = false; } if (view.IsFresh == false) { foreach (var item in view.Editors) { item.Value.SelectedItem = this.selectedItem[view.EditorsR[item.Value]]; } view.IsFresh = true; } }
System.Windows.Forms.Control CreateControl(System.Xml.XmlNode node) { if (node.Name == "Control") { AbstractObjectEditor editor = NekoKun.Core.ReflectionHelper.CreateInstanceFromTypeName( node.Attributes["Editor"].Value, NekoKun.Core.XMLHelper.BuildParameterDictionary(node) ) as AbstractObjectEditor; editor.DirtyChanged += new EventHandler(editor_DirtyChanged); StructField item = this.fields[node.Attributes["ID"].Value]; this.views[tab.SelectedIndex].Editors.Add(item, editor); this.views[tab.SelectedIndex].EditorsR.Add(editor, item); return(editor.Control); } else if (node.Name == "Layout") { IStructEditorLayout layout = NekoKun.Core.ReflectionHelper.CreateInstanceFromTypeName( node.Attributes["Type"].Value, node, new CreateControlDelegate(CreateControl) ) as IStructEditorLayout; return(layout as System.Windows.Forms.Control); } return(null); }
public RawLayout(StructField[] fields, CreateControlDelegate createControlDelegate) { this.AutoScroll = true; this.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; this.Dock = System.Windows.Forms.DockStyle.Fill; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); foreach (StructField item in fields) { System.Windows.Forms.Label lbl = new UI.LynnLabel(); lbl.Text = string.Format("{0} {1}", item.ID, item.Name); lbl.Width = 200; this.Controls.Add(lbl); System.Xml.XmlElement node = doc.CreateElement("Control"); node.SetAttribute("ID", item.ID); node.SetAttribute("Editor", EditorFactory.CreateFromDefaultValue(item.DefaultValue)); System.Windows.Forms.Control con = createControlDelegate(node); con.Width = 200; this.Controls.Add(con); } }