Ok, one more code change before 2.7.0 is released: This deals with opening old projects that have loaded the Legacy library - though if the old project uses any components from the old Legacy library, they are deleted from the project with an error message warning about that happening.

git-svn-id: https://circuit.svn.sourceforge.net/svnroot/circuit/trunk@229 70edf91d-0b9e-4248-82e7-2488d7716404
This commit is contained in:
Carl Burch 2011-03-07 14:37:55 +00:00
parent b5e50bb0a8
commit ad8ad20c00
1 changed files with 45 additions and 0 deletions

View File

@ -374,6 +374,7 @@ class XmlReader {
}
repairForWiringLibrary(doc, root);
repairForLegacyLibrary(doc, root);
}
}
@ -493,4 +494,48 @@ class XmlReader {
}
}
}
private void repairForLegacyLibrary(Document doc, Element root) {
Element legacyElt = null;
String legacyLabel = null;
for (Element libElt : XmlIterator.forChildElements(root, "lib")) {
String desc = libElt.getAttribute("desc");
String label = libElt.getAttribute("name");
if (desc != null && desc.equals("#Legacy")) {
legacyElt = libElt;
legacyLabel = label;
}
}
if (legacyElt != null) {
root.removeChild(legacyElt);
ArrayList<Element> toRemove = new ArrayList<Element>();
findLibraryUses(toRemove, legacyLabel,
XmlIterator.forDescendantElements(root, "comp"));
boolean componentsRemoved = !toRemove.isEmpty();
findLibraryUses(toRemove, legacyLabel,
XmlIterator.forDescendantElements(root, "tool"));
for (Element elt : toRemove) {
elt.getParentNode().removeChild(elt);
}
if (componentsRemoved) {
String error = "Some components have been deleted;"
+ " the Legacy library is no longer supported.";
Element elt = doc.createElement("message");
elt.setAttribute("value", error);
root.appendChild(elt);
}
}
}
private static void findLibraryUses(ArrayList<Element> dest, String label,
Iterable<Element> candidates) {
for (Element elt : candidates) {
String lib = elt.getAttribute("lib");
if (lib.equals(label)) {
dest.add(elt);
}
}
}
}