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 15 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 @@ @@ -7,19 +7,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
namespace ICSharpCode.Core
{
/// <summary>
/// Description of Path.
/// Represents all contributions to a Path in a single .addin file.
/// </summary>
public class ExtensionPath
{
string name;
AddIn addIn;
List<Codon> codons = new List<Codon>();
string name;
AddIn addIn;
List<List<Codon>> codons = new List<List<Codon>>();
public AddIn AddIn {
get {
return addIn;
@ -31,27 +32,45 @@ namespace ICSharpCode.Core @@ -31,27 +32,45 @@ namespace ICSharpCode.Core
return name;
}
}
public List<Codon> Codons {
public IEnumerable<Codon> Codons {
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)
{
this.addIn = addIn;
this.name = name;
}
public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement)
{
Stack<ICondition> conditionStack = new Stack<ICondition>();
List<Codon> innerCodons = new List<Codon>();
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.EndElement:
if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition") {
conditionStack.Pop();
} else if (reader.LocalName == endElement) {
if (innerCodons.Count > 0)
extensionPath.codons.Add(innerCodons);
return;
}
break;
@ -63,7 +82,7 @@ namespace ICSharpCode.Core @@ -63,7 +82,7 @@ namespace ICSharpCode.Core
conditionStack.Push(Condition.ReadComplexCondition(reader));
} else {
Codon newCodon = new Codon(extensionPath.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray());
extensionPath.codons.Add(newCodon);
innerCodons.Add(newCodon);
if (!reader.IsEmptyElement) {
ExtensionPath subPath = extensionPath.AddIn.GetExtensionPath(extensionPath.Name + "/" + newCodon.Id);
//foreach (ICondition condition in extensionPath.conditionStack) {
@ -78,6 +97,8 @@ namespace ICSharpCode.Core @@ -78,6 +97,8 @@ namespace ICSharpCode.Core
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 @@ -223,7 +223,8 @@ namespace ICSharpCode.Core
static void AddExtensionPath(ExtensionPath path)
{
AddInTreeNode treePath = CreatePath(rootNode, path.Name);
treePath.AddCodons(path.Codons);
foreach (IEnumerable<Codon> innerCodons in path.GroupedCodons)
treePath.AddCodons(innerCodons);
}
/// <summary>

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

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

Loading…
Cancel
Save