private void FillStructureTree(InstanceTree instanceTree) { foreach (InstanceTreeNode instance in instanceTree.Children) { AddInstanceNode(null, instance); } }
public void UpdateTree(ref Twinsanity.Instances INSTs, int Index) { InstanceTree.BeginUpdate(); for (int i = 0; i <= INSTs._Item.Length - 1; i++) InstanceTree.Nodes.Add("ID: " + INSTs._Item[i].ID.ToString()); InstanceTree.EndUpdate(); IISIndex = Index; }
[Test] public void LoadSibling() { InstanceTree tree = PrepareInstanceTree( "struct A { u8 a; sibling B; } struct B { u8 value; }", new byte[] { 17, 37 }); Assert.AreEqual(1, tree.Children[0].Cells.Count); Assert.AreEqual(2, tree.Children.Count); }
private void _structTreeView_AfterSelect(object sender, TreeViewEventArgs e) { _activeInstance = (InstanceTreeNode)e.Node.Tag; if (_nodeControl != null) { _nodeControl.Parent.Controls.Remove(_nodeControl); _nodeControl.Dispose(); _nodeControl = null; } _structTreeView.BeginUpdate(); try { if (_activeInstance == null) { _structGridView.DataSource = new List <StructCell>(); } else { NodeUI ui = FindNodeUI(_activeInstance); if (ui != null) { _nodeControl = ui.CreateControl(); _nodeControl.Dock = DockStyle.Fill; splitContainer1.Panel2.Controls.Add(_nodeControl); _structGridView.Visible = false; } else { _structGridView.Visible = true; _structGridView.DataSource = _activeInstance.Cells; } // while we're in BeginUpdate, pre-evaluate all cell values _activeInstance.Cells.ToList().ForEach(cell => cell.Value.ToString()); } } finally { _structTreeView.EndUpdate(); } var instance = _activeInstance as StructInstance; if (instance == null) { InstanceTree tree = ActiveInstanceTree; if (tree != null) { _hexDump.Stream = FindDataFile(tree).Stream; } _currentStructureHighlighter.SetRange(-1, -1); } else { _hexDump.Stream = instance.Stream; _currentStructureHighlighter.SetRange(instance.Offset, instance.EndOffset); } }
[Test] public void LoadSiblingDefault() { InstanceTree tree = PrepareInstanceTree( "struct A { u8 a; if (a > 0) { sibling; } }", new byte[] { 17, 0 }); Assert.AreEqual(1, tree.Children[0].Cells.Count); Assert.AreEqual(2, tree.Children.Count); Assert.AreEqual(1, tree.Children[1].Cells.Count); }
[Test] public void NodeName() { InstanceTree tree = PrepareInstanceTree( "struct A { enum8 e [enum=X]; nodename e; } enum X { q=12 }", new byte[] { 0x0C }); InstanceTreeNode lastChangedNode = null; tree.NodeNameChanged += delegate(object sender, NodeNameChangedEventArgs e) { lastChangedNode = e.Node; }; Assert.AreEqual(1, tree.Children [0].Cells.Count); Assert.AreEqual("q", tree.Children [0].NodeName); Assert.AreSame(tree.Children [0], lastChangedNode); }
[Test] public void NotifyChild() { InstanceTree tree = PrepareInstanceTree( "struct A { u8 a; child B [offset=a]; } struct B { u8 value; } ", new byte[] { 2, 0, 17, 37 }); InstanceTreeNode lastAddParent = null; InstanceTreeNode lastAddChild = null; tree.InstanceAdded += delegate(object sender, InstanceAddedEventArgs e) { lastAddParent = e.Parent; lastAddChild = e.Child; }; tree.Children [0].NeedChildren(); Assert.AreSame(tree.Children [0], lastAddParent); Assert.AreSame(tree.Children [0].Children[0], lastAddChild); }
[Test] public void NotifyFromGroupContainer() { InstanceTree tree = PrepareInstanceTree( "struct A { u8 a; child B [group=X]; } struct B { u8 value; } ", new byte[] { 2, 17, 37 }); InstanceTreeNode groupInstance = tree.Children[0].Children [0]; InstanceTreeNode lastAddParent = null; InstanceTreeNode lastAddChild = null; tree.InstanceAdded += delegate(object sender, InstanceAddedEventArgs e) { lastAddParent = e.Parent; lastAddChild = e.Child; }; groupInstance.NeedChildren(); Assert.AreSame(groupInstance, lastAddParent); Assert.AreSame(groupInstance.Children[0], lastAddChild); }
[Test] public void Preload() { InstanceTree tree = PrepareInstanceTree( "[preload] struct A { u8 a; child B [offset=a]; } [preload] struct B { nodename (\"Q\"); u8 value; child C [offset=Parent.a]; } struct C { u8 value; nodename(\"W\"); }", new byte[] { 2, 0, 17, 37 }); InstanceTreeNode lastAddParent = null; InstanceTreeNode lastAddChild = null; tree.InstanceAdded += delegate(object sender, InstanceAddedEventArgs e) { lastAddParent = e.Parent; lastAddChild = e.Child; }; tree.Children[0].NeedData(); Assert.AreSame(tree.Children[0], lastAddParent); Assert.AreSame(tree.Children[0].Children[0], lastAddChild); Assert.AreEqual("Q", lastAddChild.NodeName); tree.Children[0].Children[0].NeedChildren(); Assert.AreEqual("W", tree.Children[0].Children[0].Children[0].NodeName); }
[Test] public void NotifySiblingInGroup() { InstanceTree tree = PrepareInstanceTree( "struct A { u8 a; child B [group=q]; } struct B { u8 c; if (c != 0) { sibling; } }", new byte[] { 17, 37, 2 }); InstanceTreeNode lastAddChild = null; tree.InstanceAdded += delegate(object sender, InstanceAddedEventArgs e) { lastAddChild = e.Child; }; InstanceTreeNode a = tree.Children[0]; a.NeedChildren(); InstanceTreeNode q = a.Children[0]; q.NeedChildren(); Assert.AreEqual(1, q.Children.Count); InstanceTreeNode b = q.Children[0]; b.NeedChildren(); Assert.AreEqual(2, q.Children.Count); Assert.AreSame(q.Children[1], lastAddChild); }
public static StructInstance PrepareInstance(string structDefs, byte[] data) { InstanceTree tree = PrepareInstanceTree(structDefs, data); return((StructInstance)tree.Children [0]); }
private void _structTreeView_AfterSelect(object sender, TreeViewEventArgs e) { _activeInstance = (InstanceTreeNode)e.Node.Tag; if (_nodeControl != null) { _nodeControl.Parent.Controls.Remove(_nodeControl); _nodeControl.Dispose(); _nodeControl = null; } _structTreeView.BeginUpdate(); try { if (_activeInstance == null) { _structGridView.DataSource = new List <StructCell>(); } else { NodeUI ui = FindNodeUI(_activeInstance); if (ui != null) { _nodeControl = ui.CreateControl(); _nodeControl.Dock = DockStyle.Fill; splitContainer1.Panel2.Controls.Add(_nodeControl); _structGridView.Visible = false; } else { _structGridView.Visible = true; // _structGridView.DataSource = _activeInstance.Cells; if (_structGridView.DataSource == null) { _structGridView.DataSource = LoadDS(currentInstanceTree); } } // while we're in BeginUpdate, pre-evaluate all cell values _activeInstance.Cells.ToList().ForEach(cell => cell.Value.ToString()); } if (!string.IsNullOrEmpty(this.parent.getFilterField())) { (_structGridView.DataSource as DataTable).DefaultView.RowFilter = string.Format("{0} like '%{1}%'", this.parent.getFilterField(), this.parent.getFilterValue()); } } finally { _structTreeView.EndUpdate(); } var instance = _activeInstance as StructInstance; if (instance == null) { InstanceTree tree = ActiveInstanceTree; if (tree != null) { _hexDump.Stream = FindDataFile(tree).Stream; } _currentStructureHighlighter.SetRange(-1, -1); } else { _hexDump.Stream = instance.Stream; _currentStructureHighlighter.SetRange(instance.Offset, instance.EndOffset); } // Re-select grid if (_structGridView.Rows.Count >= e.Node.Index && _structGridView.CurrentCell != null) { _structGridView.CurrentCell = _structGridView.Rows[e.Node.Index].Cells[_structGridView.CurrentCell.ColumnIndex]; } }
private DataFile FindDataFile(InstanceTreeNode instance) { InstanceTree tree = instance.GetInstanceTree(); return(_dataFiles.Find(f => f.InstanceTree == tree)); }