Browse Source

Fixed sorting of AddInTreeNodes when multiple <Path> elements in a single addin file contribute to the same path. (Patch by Boris Kozorovitzky)

pull/1/head
Daniel Grunwald 16 years ago
parent
commit
6e8012ed22
  1. 41
      src/Main/Core/Project/Src/AddInTree/AddIn/ExtensionPath.cs
  2. 3
      src/Main/Core/Project/Src/AddInTree/AddInTree.cs
  3. 6
      src/Main/Core/Project/Src/AddInTree/AddInTreeNode.cs

41
src/Main/Core/Project/Src/AddInTree/AddIn/ExtensionPath.cs

@ -7,19 +7,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Xml; using System.Xml;
namespace ICSharpCode.Core namespace ICSharpCode.Core
{ {
/// <summary> /// <summary>
/// Description of Path. /// Represents all contributions to a Path in a single .addin file.
/// </summary> /// </summary>
public class ExtensionPath public class ExtensionPath
{ {
string name; string name;
AddIn addIn; AddIn addIn;
List<Codon> codons = new List<Codon>(); List<List<Codon>> codons = new List<List<Codon>>();
public AddIn AddIn { public AddIn AddIn {
get { get {
return addIn; return addIn;
@ -31,27 +32,45 @@ namespace ICSharpCode.Core
return name; return name;
} }
} }
public List<Codon> Codons {
public IEnumerable<Codon> Codons {
get { get {
return codons; return
from list in codons
from c in list
select c;
} }
} }
/// <summary>
/// Gets the codons separated by the groups they were created in.
/// i.e. if two addins add the codons to the same path they will be in diffrent group.
/// if the same addin adds the codon in diffrent path elements they will be in diffrent groups.
/// </summary>
public IEnumerable<IEnumerable<Codon>> GroupedCodons {
get {
return codons.AsReadOnly();
}
}
public ExtensionPath(string name, AddIn addIn) public ExtensionPath(string name, AddIn addIn)
{ {
this.addIn = addIn; this.addIn = addIn;
this.name = name; this.name = name;
} }
public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement) public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement)
{ {
Stack<ICondition> conditionStack = new Stack<ICondition>(); Stack<ICondition> conditionStack = new Stack<ICondition>();
List<Codon> innerCodons = new List<Codon>();
while (reader.Read()) { while (reader.Read()) {
switch (reader.NodeType) { switch (reader.NodeType) {
case XmlNodeType.EndElement: case XmlNodeType.EndElement:
if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition") { if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition") {
conditionStack.Pop(); conditionStack.Pop();
} else if (reader.LocalName == endElement) { } else if (reader.LocalName == endElement) {
if (innerCodons.Count > 0)
extensionPath.codons.Add(innerCodons);
return; return;
} }
break; break;
@ -63,7 +82,7 @@ namespace ICSharpCode.Core
conditionStack.Push(Condition.ReadComplexCondition(reader)); conditionStack.Push(Condition.ReadComplexCondition(reader));
} else { } else {
Codon newCodon = new Codon(extensionPath.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray()); Codon newCodon = new Codon(extensionPath.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray());
extensionPath.codons.Add(newCodon); innerCodons.Add(newCodon);
if (!reader.IsEmptyElement) { if (!reader.IsEmptyElement) {
ExtensionPath subPath = extensionPath.AddIn.GetExtensionPath(extensionPath.Name + "/" + newCodon.Id); ExtensionPath subPath = extensionPath.AddIn.GetExtensionPath(extensionPath.Name + "/" + newCodon.Id);
//foreach (ICondition condition in extensionPath.conditionStack) { //foreach (ICondition condition in extensionPath.conditionStack) {
@ -78,6 +97,8 @@ namespace ICSharpCode.Core
break; break;
} }
} }
if (innerCodons.Count > 0)
extensionPath.codons.Add(innerCodons);
} }
} }
} }

3
src/Main/Core/Project/Src/AddInTree/AddInTree.cs

@ -223,7 +223,8 @@ namespace ICSharpCode.Core
static void AddExtensionPath(ExtensionPath path) static void AddExtensionPath(ExtensionPath path)
{ {
AddInTreeNode treePath = CreatePath(rootNode, path.Name); AddInTreeNode treePath = CreatePath(rootNode, path.Name);
treePath.AddCodons(path.Codons); foreach (IEnumerable<Codon> innerCodons in path.GroupedCodons)
treePath.AddCodons(innerCodons);
} }
/// <summary> /// <summary>

6
src/Main/Core/Project/Src/AddInTree/AddInTreeNode.cs

@ -20,7 +20,7 @@ namespace ICSharpCode.Core
readonly object lockObj = new object(); readonly object lockObj = new object();
Dictionary<string, AddInTreeNode> childNodes = new Dictionary<string, AddInTreeNode>(); Dictionary<string, AddInTreeNode> childNodes = new Dictionary<string, AddInTreeNode>();
ReadOnlyCollection<Codon> codons; ReadOnlyCollection<Codon> codons;
List<ICollection<Codon>> codonInput; List<IEnumerable<Codon>> codonInput;
/// <summary> /// <summary>
/// A dictionary containing the child paths. /// A dictionary containing the child paths.
@ -31,13 +31,13 @@ namespace ICSharpCode.Core
} }
} }
public void AddCodons(ICollection<Codon> newCodons) public void AddCodons(IEnumerable<Codon> newCodons)
{ {
if (newCodons == null) if (newCodons == null)
throw new ArgumentNullException("newCodons"); throw new ArgumentNullException("newCodons");
lock (lockObj) { lock (lockObj) {
if (codonInput == null) { if (codonInput == null) {
codonInput = new List<ICollection<Codon>>(); codonInput = new List<IEnumerable<Codon>>();
if (codons != null) if (codons != null)
codonInput.Add(codons); codonInput.Add(codons);
} }

Loading…
Cancel
Save