/// <summary> /// Add a struct data element. /// </summary> /// <param name="parentNode">parent node that contains this struct element node</param> /// <param name="at">position where the new struct is inserted before</param> public void addStructTypeNode(DataNode parentNode, int at, bool defineType) { FormStruct formStruct = new FormStruct(); if (defineType) { formStruct.TypeName = "MyStructType-" + Convert.ToString(++typeStructCounter_); } else { formStruct.Text = "Build a struct element"; formStruct.ChangeLabel("Var Name:"); formStruct.TypeName = "myStruct-" + Convert.ToString(parentNode.Nodes.Count); //TODO: check for duplicate name } formStruct.setDataTypeSource(document_.getTypeNames()); DialogResult r = formStruct.ShowDialog(view_); if (r == DialogResult.OK) { string varName = formStruct.TypeName; string blockSize = formStruct.BlockSize; int nBlockSize = 0; try { nBlockSize = Convert.ToInt32(blockSize); } catch (Exception ex) { Console.WriteLine(ex.Message); } StructNode sn = new StructNode((defineType)?"":varName, nBlockSize); AbstractNode aNode = sn; if (defineType) { aNode = new DefineTypeNode(formStruct.TypeName, sn); } DataNode dn = new DataNode(aNode); //collect struct members foreach (ListViewItem itm in formStruct.getMemberItems()) { string stype = itm.Text; string svname = itm.SubItems[1].Text; if (!stype.Equals("")) { addChildNode(dn, stype, svname); } } addChildNode(parentNode, dn, at); document_.setModified(); parentNode.ExpandAll(); } }
/// <summary> /// Add a struct data element. /// </summary> /// <param name="parentNode">parent node that contains this struct element node</param> /// <param name="at">position where the new struct is inserted before</param> public void addStructTypeNode(DataNode parentNode, int at, bool defineType) { FormStruct formStruct = new FormStruct(); if (defineType) { formStruct.TypeName = "MyStructType-" + Convert.ToString(++typeStructCounter_); } else { formStruct.Text = "Build a struct element"; formStruct.ChangeLabel("Var Name:"); formStruct.TypeName = "myStruct-" + Convert.ToString(parentNode.Nodes.Count); //TODO: check for duplicate name } formStruct.setDataTypeSource(document_.getTypeNames()); DialogResult r = formStruct.ShowDialog(view_); if (r==DialogResult.OK) { string varName = formStruct.TypeName; string blockSize = formStruct.BlockSize; int nBlockSize = 0; try { nBlockSize = Convert.ToInt32(blockSize); } catch (Exception ex) { Console.WriteLine(ex.Message); } StructNode sn = new StructNode((defineType)?"":varName, nBlockSize); AbstractNode aNode = sn; if (defineType) { aNode = new DefineTypeNode(formStruct.TypeName, sn); } DataNode dn = new DataNode(aNode); //collect struct members foreach (ListViewItem itm in formStruct.getMemberItems()) { string stype = itm.Text; string svname = itm.SubItems[1].Text; if (!stype.Equals("")) { addChildNode(dn, stype, svname); } } addChildNode(parentNode, dn, at); document_.setModified(); parentNode.ExpandAll(); } }