I’m trying to write a command in Java that structurally changes a DTBook file -
promoting a subsection up a level to become a sibling of its current parent.
In DTBook sections are <level1>, <level2>, <level3>, etc, and contain header
tags <h1>, <h2>, <h3>, etc. So my method has to (a) change the element names,
etc from <level3> to <level2> and <h3> to <h2>, and then (b) move the structure.
That much is working, but I find that when I hit ‘undo’ only some of the
changes get undone - the structural change is reverted but tag names are not
set back to what they were, resulting in an invalid document.
My execute method looks like this. I had thought that the beginEdit() and
endEdit() would tell the undo manager the scope of everything that needs to be
reverted. PromotionHandler is defined to do the appropriate element name
changes.
public Object execute(DocumentView doc, String param, int x, int y) {
MarkManager markManager = doc.getMarkManager();
markManager.beginMark();
Document document = doc.getDocument();
document.beginEdit();
// Rewrite element names inside this element to one level higher
Element e = getSelectedElement(doc);
Traversal.traverse(e, new PromotionHandler());
// Move the element to be a sibling of, and just before, its
current parent.
Element parent = e.getParentElement();
parent.removeChild(e);
parent.getParentElement().insertChild(parent, e);
document.endEdit();
doc.describeUndo("Promote level");
markManager.endMark();
return null;
}
Any idea what I’m missing?
Thanks!
Boris
--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support