Commit cf8f77dc authored by Tebjan Halm's avatar Tebjan Halm
Browse files

added correct insert method for IdManager and SvgElementCollection

parent 29a3026e
...@@ -280,7 +280,7 @@ namespace Svg ...@@ -280,7 +280,7 @@ namespace Svg
if (this.OwnerDocument != null) if (this.OwnerDocument != null)
{ {
this.OwnerDocument.IdManager.AddAndFixID(this, autoFixID, logElementOldIDNewID); this.OwnerDocument.IdManager.AddAndFixID(this, null, autoFixID, logElementOldIDNewID);
} }
} }
......
...@@ -58,7 +58,7 @@ namespace Svg ...@@ -58,7 +58,7 @@ namespace Svg
public void InsertAddAndFixID(int index, SvgElement item, bool autoFixID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null) public void InsertAddAndFixID(int index, SvgElement item, bool autoFixID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
{ {
AddToIdManager(item, autoFixID, autoFixChildrenID, logElementOldIDNewID); AddToIdManager(item, this._elements[index], autoFixID, autoFixChildrenID, logElementOldIDNewID);
this._elements.Insert(index, item); this._elements.Insert(index, item);
item._parent.OnElementAdded(item, index); item._parent.OnElementAdded(item, index);
} }
...@@ -86,24 +86,24 @@ namespace Svg ...@@ -86,24 +86,24 @@ namespace Svg
public void AddAndFixID(SvgElement item, bool autoFixID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null) public void AddAndFixID(SvgElement item, bool autoFixID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
{ {
AddToIdManager(item, autoFixID, autoFixChildrenID, logElementOldIDNewID); AddToIdManager(item, null, autoFixID, autoFixChildrenID, logElementOldIDNewID);
this._elements.Add(item); this._elements.Add(item);
item._parent.OnElementAdded(item, this.Count - 1); item._parent.OnElementAdded(item, this.Count - 1);
} }
private void AddToIdManager(SvgElement item, bool autoFixID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null) private void AddToIdManager(SvgElement item, SvgElement sibling, bool autoFixID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
{ {
if (!this._mock) if (!this._mock)
{ {
if (this._owner.OwnerDocument != null) if (this._owner.OwnerDocument != null)
{ {
this._owner.OwnerDocument.IdManager.AddAndFixID(item, autoFixID, logElementOldIDNewID); this._owner.OwnerDocument.IdManager.AddAndFixID(item, sibling, autoFixID, logElementOldIDNewID);
if (!(item is SvgDocument)) //don't add subtree of a document to parent document if (!(item is SvgDocument)) //don't add subtree of a document to parent document
{ {
foreach (var child in item.Children) foreach (var child in item.Children)
{ {
child.ApplyRecursive(e => this._owner.OwnerDocument.IdManager.AddAndFixID(e, autoFixChildrenID, logElementOldIDNewID)); child.ApplyRecursive(e => this._owner.OwnerDocument.IdManager.AddAndFixID(e, null, autoFixChildrenID, logElementOldIDNewID));
} }
} }
} }
......
...@@ -48,7 +48,7 @@ namespace Svg ...@@ -48,7 +48,7 @@ namespace Svg
/// <param name="element">The <see cref="SvgElement"/> to be managed.</param> /// <param name="element">The <see cref="SvgElement"/> to be managed.</param>
public virtual void Add(SvgElement element) public virtual void Add(SvgElement element)
{ {
AddAndFixID(element, false); AddAndFixID(element, null, false);
} }
/// <summary> /// <summary>
...@@ -59,7 +59,7 @@ namespace Svg ...@@ -59,7 +59,7 @@ namespace Svg
/// <param name="autoFixID">Pass true here, if you want the ID to be fixed</param> /// <param name="autoFixID">Pass true here, if you want the ID to be fixed</param>
/// <param name="logElementOldIDNewID">If not null, the action is called before the id is fixed</param> /// <param name="logElementOldIDNewID">If not null, the action is called before the id is fixed</param>
/// <returns>true, if ID was altered</returns> /// <returns>true, if ID was altered</returns>
public virtual bool AddAndFixID(SvgElement element, bool autoFixID = true, Action<SvgElement, string, string> logElementOldIDNewID = null) public virtual bool AddAndFixID(SvgElement element, SvgElement sibling, bool autoFixID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
{ {
var result = false; var result = false;
if (!string.IsNullOrEmpty(element.ID)) if (!string.IsNullOrEmpty(element.ID))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment