Skip to content

Commit 3562133

Browse files
committed
Updated the container methods.
1 parent 0afacae commit 3562133

File tree

3 files changed

+45
-46
lines changed

3 files changed

+45
-46
lines changed

Nodes/BaseContainerNode.cs

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,64 +34,47 @@ public int FindNodeIndex(BaseNode node)
3434
return Nodes.FindIndex(n => n == node);
3535
}
3636

37-
public virtual BaseNode ReplaceChildNode(BaseNode child, Type nodeType)
37+
public bool ReplaceChildNode(BaseNode child, Type nodeType)
3838
{
3939
Contract.Requires(nodeType != null);
4040

41-
return ReplaceChildNode(FindNodeIndex(child), nodeType);
41+
List<BaseNode> dummy = null;
42+
return ReplaceChildNode(child, nodeType, ref dummy);
4243
}
4344

44-
/// <summary>Replaces the child at the specific position with the provided node.</summary>
45-
/// <param name="index">Zero-based position.</param>
46-
/// <param name="node">The node to add.</param>
47-
/// <returns>True if it succeeds, false if it fails.</returns>
48-
public virtual BaseNode ReplaceChildNode(int index, Type nodeType)
45+
public bool ReplaceChildNode(BaseNode child, Type nodeType, ref List<BaseNode> createdNodes)
4946
{
47+
Contract.Requires(child != null);
5048
Contract.Requires(nodeType != null);
51-
Contract.Requires(nodeType.IsSubclassOf(typeof(BaseNode)));
5249

53-
var node = Activator.CreateInstance(nodeType) as BaseNode;
54-
55-
node.Intialize();
56-
57-
if (ReplaceChildNode(index, node))
58-
{
59-
return node;
60-
}
61-
62-
return null;
50+
return ReplaceChildNode(FindNodeIndex(child), nodeType, ref createdNodes);
6351
}
6452

6553
/// <summary>Replaces the child at the specific position with the provided node.</summary>
6654
/// <param name="index">Zero-based position.</param>
67-
/// <param name="node">The node to add.</param>
55+
/// <param name="nodeType">The type of the node.</param>
56+
/// <param name="createdNodes">[in,out] A list with the created nodes.</param>
6857
/// <returns>True if it succeeds, false if it fails.</returns>
69-
public bool ReplaceChildNode(BaseNode child, BaseNode node)
58+
public virtual bool ReplaceChildNode(int index, Type nodeType, ref List<BaseNode> createdNodes)
7059
{
71-
return ReplaceChildNode(FindNodeIndex(child), node);
72-
}
60+
Contract.Requires(nodeType != null);
61+
Contract.Requires(nodeType.IsSubclassOf(typeof(BaseNode)));
7362

74-
/// <summary>Replaces the child at the specific position with the provided node.</summary>
75-
/// <param name="index">Zero-based position.</param>
76-
/// <param name="node">The node to add.</param>
77-
/// <returns>True if it succeeds, false if it fails.</returns>
78-
public virtual bool ReplaceChildNode(int index, BaseNode node)
79-
{
80-
if (node == null)
81-
{
82-
return false;
83-
}
8463
if (index < 0 || index >= nodes.Count)
8564
{
8665
return false;
8766
}
8867

8968
var oldNode = nodes[index];
9069

70+
var node = Activator.CreateInstance(nodeType) as BaseNode;
71+
72+
node.Intialize();
9173
node.CopyFromNode(oldNode);
9274

75+
createdNodes?.Add(node);
76+
9377
node.ParentNode = this;
94-
node.ClearSelection();
9578

9679
nodes[index] = node;
9780

@@ -100,12 +83,12 @@ public virtual bool ReplaceChildNode(int index, BaseNode node)
10083

10184
if (newSize < oldSize)
10285
{
103-
InsertBytes(index + 1, oldSize - newSize);
86+
InsertBytes(index + 1, oldSize - newSize, ref createdNodes);
10487
}
105-
else if (newSize > oldSize)
88+
/*else if (newSize > oldSize)
10689
{
107-
//RemoveNodes(index + 1, newSize - oldSize);
108-
}
90+
RemoveNodes(index + 1, newSize - oldSize);
91+
}*/
10992

11093
return true;
11194
}
@@ -117,15 +100,25 @@ public void AddBytes(int size)
117100
InsertBytes(nodes.Count, size);
118101
}
119102

120-
public virtual void InsertBytes(BaseNode position, int size)
103+
public void InsertBytes(BaseNode position, int size)
121104
{
122105
InsertBytes(FindNodeIndex(position), size);
123106
}
124107

125108
/// <summary>Inserts <paramref name="size"/> bytes at the specified position.</summary>
126109
/// <param name="index">Zero-based position.</param>
127110
/// <param name="size">The number of bytes to insert.</param>
128-
public virtual void InsertBytes(int index, int size)
111+
public void InsertBytes(int index, int size)
112+
{
113+
List<BaseNode> dummy = null;
114+
InsertBytes(index, size, ref dummy);
115+
}
116+
117+
/// <summary>Inserts <paramref name="size"/> bytes at the specified position.</summary>
118+
/// <param name="index">Zero-based position.</param>
119+
/// <param name="size">The number of bytes to insert.</param>
120+
/// <param name="createdNodes">[in,out] A list with the created nodes.</param>
121+
public virtual void InsertBytes(int index, int size, ref List<BaseNode> createdNodes)
129122
{
130123
if (index < 0 || index > nodes.Count || size == 0)
131124
{
@@ -167,6 +160,8 @@ public virtual void InsertBytes(int index, int size)
167160

168161
nodes.Insert(index, node);
169162

163+
createdNodes?.Add(node);
164+
170165
offset += node.MemorySize;
171166
size -= node.MemorySize;
172167

Nodes/ClassNode.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics.Contracts;
34
using System.Drawing;
45
using System.Linq;
@@ -180,9 +181,9 @@ public void UpdateAddress(MemoryBuffer memory)
180181
}
181182
}
182183

183-
public override void InsertBytes(int index, int size)
184+
public override void InsertBytes(int index, int size, ref List<BaseNode> createdNodes)
184185
{
185-
base.InsertBytes(index, size);
186+
base.InsertBytes(index, size, ref createdNodes);
186187

187188
ChildHasChanged(null);
188189
}
@@ -211,12 +212,12 @@ public override bool RemoveNode(BaseNode node)
211212
return removed;
212213
}
213214

214-
public override bool ReplaceChildNode(int index, BaseNode node)
215+
public override bool ReplaceChildNode(int index, Type nodeType, ref List<BaseNode> createdNodes)
215216
{
216-
var replaced = base.ReplaceChildNode(index, node);
217+
var replaced = base.ReplaceChildNode(index, nodeType, ref createdNodes);
217218
if (replaced)
218219
{
219-
ChildHasChanged(node);
220+
ChildHasChanged(null); //TODO
220221
}
221222
return replaced;
222223
}

Nodes/VTableNode.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using ReClassNET.Memory;
45
using ReClassNET.UI;
@@ -92,9 +93,9 @@ public override int CalculateHeight(ViewInfo view)
9293
return h;
9394
}
9495

95-
public override bool ReplaceChildNode(int index, BaseNode node) => false;
96+
public override bool ReplaceChildNode(int index, Type nodeType, ref List<BaseNode> createdNodes) => false;
9697

97-
public override void InsertBytes(int index, int size)
98+
public override void InsertBytes(int index, int size, ref List<BaseNode> createdNodes)
9899
{
99100
if (index < 0 || index > nodes.Count || size == 0)
100101
{
@@ -118,6 +119,8 @@ public override void InsertBytes(int index, int size)
118119

119120
nodes.Insert(index, node);
120121

122+
createdNodes?.Add(node);
123+
121124
offset += node.MemorySize;
122125
size -= node.MemorySize;
123126

0 commit comments

Comments
 (0)