Commit 0b3df0a9 authored by tebjan's avatar tebjan
Browse files

renamed FixID to ForceUniqueID

parent 03f7a46b
......@@ -259,11 +259,11 @@ namespace Svg
get { return this.Attributes.GetAttribute<string>("id"); }
set
{
SetAndFixID(value, false);
SetAndForceUniqueID(value, false);
}
}
public void SetAndFixID(string value, bool autoFixID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
public void SetAndForceUniqueID(string value, bool autoForceUniqueID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
{
// Don't do anything if it hasn't changed
if (string.Compare(this.ID, value) == 0)
......@@ -280,7 +280,7 @@ namespace Svg
if (this.OwnerDocument != null)
{
this.OwnerDocument.IdManager.AddAndFixID(this, null, autoFixID, logElementOldIDNewID);
this.OwnerDocument.IdManager.AddAndForceUniqueID(this, null, autoForceUniqueID, logElementOldIDNewID);
}
}
......@@ -288,7 +288,7 @@ namespace Svg
/// Only used by the ID Manager
/// </summary>
/// <param name="newID"></param>
internal void FixID(string newID)
internal void ForceUniqueID(string newID)
{
this.Attributes["id"] = newID;
}
......
......@@ -53,12 +53,12 @@ namespace Svg
/// <param name="item">The <see cref="SvgElement"/> to be added.</param>
public void Insert(int index, SvgElement item)
{
InsertAndFixID(index, item, false, false);
InsertAndForceUniqueID(index, item, false, false);
}
public void InsertAndFixID(int index, SvgElement item, bool autoFixID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
public void InsertAndForceUniqueID(int index, SvgElement item, bool autoForceUniqueID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
{
AddToIdManager(item, this._elements[index], autoFixID, autoFixChildrenID, logElementOldIDNewID);
AddToIdManager(item, this._elements[index], autoForceUniqueID, autoFixChildrenID, logElementOldIDNewID);
this._elements.Insert(index, item);
item._parent.OnElementAdded(item, index);
}
......@@ -81,29 +81,29 @@ namespace Svg
public void Add(SvgElement item)
{
this.AddAndFixID(item, false, false);
this.AddAndForceUniqueID(item, false, false);
}
public void AddAndFixID(SvgElement item, bool autoFixID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
public void AddAndForceUniqueID(SvgElement item, bool autoForceUniqueID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
{
AddToIdManager(item, null, autoFixID, autoFixChildrenID, logElementOldIDNewID);
AddToIdManager(item, null, autoForceUniqueID, autoFixChildrenID, logElementOldIDNewID);
this._elements.Add(item);
item._parent.OnElementAdded(item, this.Count - 1);
}
private void AddToIdManager(SvgElement item, SvgElement sibling, bool autoFixID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
private void AddToIdManager(SvgElement item, SvgElement sibling, bool autoForceUniqueID = true, bool autoFixChildrenID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
{
if (!this._mock)
{
if (this._owner.OwnerDocument != null)
{
this._owner.OwnerDocument.IdManager.AddAndFixID(item, sibling, autoFixID, logElementOldIDNewID);
this._owner.OwnerDocument.IdManager.AddAndForceUniqueID(item, sibling, autoForceUniqueID, logElementOldIDNewID);
if (!(item is SvgDocument)) //don't add subtree of a document to parent document
{
foreach (var child in item.Children)
{
child.ApplyRecursive(e => this._owner.OwnerDocument.IdManager.AddAndFixID(e, null, autoFixChildrenID, logElementOldIDNewID));
child.ApplyRecursive(e => this._owner.OwnerDocument.IdManager.AddAndForceUniqueID(e, null, autoFixChildrenID, logElementOldIDNewID));
}
}
}
......
......@@ -48,7 +48,7 @@ namespace Svg
/// <param name="element">The <see cref="SvgElement"/> to be managed.</param>
public virtual void Add(SvgElement element)
{
AddAndFixID(element, null, false);
AddAndForceUniqueID(element, null, false);
}
/// <summary>
......@@ -56,20 +56,20 @@ namespace Svg
/// And can auto fix the ID if it already exists or it starts with a number.
/// </summary>
/// <param name="element">The <see cref="SvgElement"/> to be managed.</param>
/// <param name="autoFixID">Pass true here, if you want the ID to be fixed</param>
/// <param name="autoForceUniqueID">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>
/// <returns>true, if ID was altered</returns>
public virtual bool AddAndFixID(SvgElement element, SvgElement sibling, bool autoFixID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
public virtual bool AddAndForceUniqueID(SvgElement element, SvgElement sibling, bool autoForceUniqueID = true, Action<SvgElement, string, string> logElementOldIDNewID = null)
{
var result = false;
if (!string.IsNullOrEmpty(element.ID))
{
var newID = this.EnsureValidId(element.ID, autoFixID);
if (autoFixID && newID != element.ID)
var newID = this.EnsureValidId(element.ID, autoForceUniqueID);
if (autoForceUniqueID && newID != element.ID)
{
if(logElementOldIDNewID != null)
logElementOldIDNewID(element, element.ID, newID);
element.FixID(newID);
element.ForceUniqueID(newID);
result = true;
}
this._idValueMap.Add(element.ID, element);
......@@ -101,7 +101,7 @@ namespace Svg
/// <para>The ID cannot start with a digit.</para>
/// <para>An element with the same ID already exists within the containing <see cref="SvgDocument"/>.</para>
/// </exception>
public string EnsureValidId(string id, bool autoFixID = false)
public string EnsureValidId(string id, bool autoForceUniqueID = false)
{
if (string.IsNullOrEmpty(id))
......@@ -111,7 +111,7 @@ namespace Svg
if (char.IsDigit(id[0]))
{
if (autoFixID)
if (autoForceUniqueID)
{
return EnsureValidId("id" + id, true);
}
......@@ -120,7 +120,7 @@ namespace Svg
if (this._idValueMap.ContainsKey(id))
{
if(autoFixID)
if(autoForceUniqueID)
{
var match = regex.Match(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