[Jsxe-cvs] SF.net SVN: jsxe: [1119] trunk/jsxe
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-08-08 04:59:42
|
Revision: 1119 Author: ian_lewis Date: 2006-08-07 21:59:34 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1119&view=rev Log Message: ----------- Fixed bugs in undo Modified Paths: -------------- trunk/jsxe/Changelog trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java trunk/jsxe/src/net/sourceforge/jsxe/dom/XMLDocument.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java Modified: trunk/jsxe/Changelog =================================================================== --- trunk/jsxe/Changelog 2006-08-08 04:20:55 UTC (rev 1118) +++ trunk/jsxe/Changelog 2006-08-08 04:59:34 UTC (rev 1119) @@ -1,6 +1,8 @@ 08/07/2006 Ian Lewis <Ian...@me...> * Added temporary support for undo to jsXe. + * Added support for undo of text insert and delete. + * Added support for undo of changes to a node's name, value, and prefix. 08/05/2006 Ian Lewis <Ian...@me...> Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-08 04:20:55 UTC (rev 1118) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-08 04:59:34 UTC (rev 1119) @@ -277,9 +277,24 @@ * NAMESPACE_ERR: Raised if the specified prefix is malformed per the Namespaces in XML specification, if the namespaceURI of this node is null, if the specified prefix is "xml" and the namespaceURI of this node is different from "http://www.w3.org/XML/1998/namespace", if this node is an attribute and the specified prefix is "xmlns" and the namespaceURI of this node is different from " http://www.w3.org/2000/xmlns/", or if this node is an attribute and the qualifiedName of this node is "xmlns" . */ public void setNSPrefix(String prefix) throws DOMException { - String oldPrefix = getNSPrefix(); - m_domNode.setPrefix(prefix); - fireNamespaceChanged(this, oldPrefix, prefix); + XMLDocument doc = getOwnerDocument(); + try { + doc.beginCompoundEdit(); + String oldPrefix = getNSPrefix(); + /* + for whatever reason if I set a prefix on an node with no prefix + you get DOMException.NAMESPACE_ERRs. If we are adding a NS then + just rename the node. + */ + if (oldPrefix != null && !oldPrefix.equals("")) { + m_domNode.setPrefix(prefix); + } else { + renameElementNode(prefix, getLocalName()); + } + fireNamespaceChanged(this, oldPrefix, prefix); + } finally { + doc.endCompoundEdit(); + } }//}}} //{{{ getNodeName() @@ -312,14 +327,15 @@ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "An attempt was made to rename a node that is not supported."); } } - + XMLDocument doc = getOwnerDocument(); + doc.beginCompoundEdit(); if (!MiscUtilities.equals(oldPrefix, prefix)) { fireNamespaceChanged(this, oldPrefix, prefix); } if (!MiscUtilities.equals(oldLocalName, localName)) { fireLocalNameChanged(this, oldLocalName, localName); } - + doc.endCompoundEdit(); }//}}} //{{{ getLocalName() Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/XMLDocument.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-08-08 04:20:55 UTC (rev 1118) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-08-08 04:59:34 UTC (rev 1119) @@ -203,9 +203,10 @@ */ protected boolean addUndoableEdit(UndoableEdit edit) { if (!getFlag(UNDO_IN_PROGRESS)) { + Log.log(Log.DEBUG, this, edit); if (insideCompoundEdit()) { m_addedToCompoundEdits = true; - return ((CompoundEdit)m_compoundEdits.peek()).addEdit(edit); + return m_compoundEdit.addEdit(edit); } else { return m_undoManager.addEdit(edit); } @@ -219,9 +220,11 @@ * undone/redone all at once. */ public void beginCompoundEdit() { - Log.log(Log.DEBUG, this, "begin compound edit"); - m_addedToCompoundEdits = false; - m_compoundEdits.push(new CompoundEdit()); + if (m_compoundEditCount == 0) { + m_compoundEdit = new CompoundEdit(); + m_addedToCompoundEdits = false; + } + ++m_compoundEditCount; }//}}} //{{{ endCompoundEdit() @@ -234,13 +237,13 @@ Log.log(Log.WARNING, this, new Exception("Unbalanced begin/endCompoundEdit()")); return; } - Log.log(Log.DEBUG, this, "end compound edit"); - CompoundEdit edit = (CompoundEdit)m_compoundEdits.pop(); - edit.end(); - if (m_addedToCompoundEdits) { - m_undoManager.addEdit(edit); - m_addedToCompoundEdits = false; + m_compoundEdit.end(); + if (m_compoundEditCount == 1) { + if (m_addedToCompoundEdits) { + m_undoManager.addEdit(m_compoundEdit); + } } + --m_compoundEditCount; }//}}} //{{{ insideCompoundEdit() @@ -249,7 +252,7 @@ * edit that will be undone/redone all at once. */ public boolean insideCompoundEdit() { - return m_compoundEdits.size() != 0; + return (m_compoundEditCount != 0); }//}}} //{{{ undo() @@ -263,7 +266,7 @@ m_undoManager.undo(); EditBus.send(new UndoEvent(this)); } catch (CannotUndoException e) { - Log.log(Log.WARNING, this, e); + Log.log(Log.WARNING, this, "Could not undo"); } finally { setFlag(UNDO_IN_PROGRESS, false); } @@ -280,7 +283,7 @@ m_undoManager.redo(); EditBus.send(new RedoEvent(this)); } catch (CannotRedoException e) { - Log.log(Log.WARNING, this, e); + Log.log(Log.WARNING, this, "Could not redo"); } finally { setFlag(UNDO_IN_PROGRESS, false); } @@ -2267,8 +2270,9 @@ private HashMap m_mappings; private UndoManager m_undoManager = new UndoManager(); - private Stack m_compoundEdits = new Stack(); + private CompoundEdit m_compoundEdit = null; private boolean m_addedToCompoundEdits = false; + private int m_compoundEditCount = 0; // private XMLDocAdapterListener docAdapterListener = new XMLDocAdapterListener(); Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java 2006-08-08 04:20:55 UTC (rev 1118) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java 2006-08-08 04:59:34 UTC (rev 1119) @@ -66,8 +66,9 @@ public void undo() throws CannotUndoException { super.undo(); try { - m_node.setNodeName(m_oldValue); - } catch (DOMException ioe) { + m_node.setLocalName(m_oldValue); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); throw new CannotUndoException(); } }//}}} @@ -77,8 +78,9 @@ public void redo() throws CannotRedoException { super.redo(); try { - m_node.setNodeName(m_newValue); - } catch (DOMException ioe) { + m_node.setLocalName(m_newValue); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); throw new CannotRedoException(); } }//}}} Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java 2006-08-08 04:20:55 UTC (rev 1118) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java 2006-08-08 04:59:34 UTC (rev 1119) @@ -67,7 +67,8 @@ super.undo(); try { m_node.setNSPrefix(m_oldValue); - } catch (DOMException ioe) { + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); throw new CannotUndoException(); } }//}}} @@ -78,7 +79,8 @@ super.redo(); try { m_node.setNSPrefix(m_newValue); - } catch (DOMException ioe) { + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); throw new CannotRedoException(); } }//}}} Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java 2006-08-08 04:20:55 UTC (rev 1118) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java 2006-08-08 04:59:34 UTC (rev 1119) @@ -67,7 +67,8 @@ super.undo(); try { m_node.setNodeValue(m_oldValue); - } catch (DOMException ioe) { + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); throw new CannotUndoException(); } }//}}} @@ -78,7 +79,8 @@ super.redo(); try { m_node.setNodeValue(m_newValue); - } catch (DOMException ioe) { + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); throw new CannotRedoException(); } }//}}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |