| | |
| | | if (handler) { |
| | | handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this); |
| | | } |
| | | |
| | | |
| | | this.elem = this.oldParent.insertBefore(this.elem, this.oldNextSibling); |
| | | |
| | | if (handler) { |
| | |
| | | |
| | | // Function: svgedit.history.InsertElementCommand.apply |
| | | // Re-Inserts the new element |
| | | svgedit.history.InsertElementCommand.prototype.apply = function(handler) { |
| | | svgedit.history.InsertElementCommand.prototype.apply = function(handler) { |
| | | if (handler) { |
| | | handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, this); |
| | | } |
| | | |
| | | this.elem = this.parent.insertBefore(this.elem, this.nextSibling); |
| | | this.elem = this.parent.insertBefore(this.elem, this.nextSibling); |
| | | |
| | | if (handler) { |
| | | handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.AFTER_APPLY, this); |
| | |
| | | |
| | | // Function: RemoveElementCommand.apply |
| | | // Re-removes the new element |
| | | svgedit.history.RemoveElementCommand.prototype.apply = function(handler) { |
| | | svgedit.history.RemoveElementCommand.prototype.apply = function(handler) { |
| | | if (handler) { |
| | | handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, this); |
| | | } |
| | |
| | | |
| | | // Function: RemoveElementCommand.unapply |
| | | // Re-adds the new element |
| | | svgedit.history.RemoveElementCommand.prototype.unapply = function(handler) { |
| | | svgedit.history.RemoveElementCommand.prototype.unapply = function(handler) { |
| | | if (handler) { |
| | | handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this); |
| | | } |
| | |
| | | |
| | | // Class: svgedit.history.ChangeElementCommand |
| | | // implements svgedit.history.HistoryCommand |
| | | // History command to make a change to an element. |
| | | // History command to make a change to an element. |
| | | // Usually an attribute change, but can also be textcontent. |
| | | // |
| | | // Parameters: |
| | |
| | | this.undoChangeStackPointer = -1; |
| | | this.undoableChangeStack = []; |
| | | }; |
| | | |
| | | |
| | | // Function: svgedit.history.UndoManager.resetUndoStack |
| | | // Resets the undo stack, effectively clearing the undo/redo history |
| | | svgedit.history.UndoManager.prototype.resetUndoStack = function() { |
| | |
| | | }; |
| | | |
| | | // Function: svgedit.history.UndoManager.getUndoStackSize |
| | | // Returns: |
| | | // Returns: |
| | | // Integer with the current size of the undo history stack |
| | | svgedit.history.UndoManager.prototype.getUndoStackSize = function() { |
| | | return this.undoStackPointer; |
| | | }; |
| | | |
| | | // Function: svgedit.history.UndoManager.getRedoStackSize |
| | | // Returns: |
| | | // Returns: |
| | | // Integer with the current size of the redo history stack |
| | | svgedit.history.UndoManager.prototype.getRedoStackSize = function() { |
| | | return this.undoStack.length - this.undoStackPointer; |
| | | }; |
| | | |
| | | // Function: svgedit.history.UndoManager.getNextUndoCommandText |
| | | // Returns: |
| | | // Returns: |
| | | // String associated with the next undo command |
| | | svgedit.history.UndoManager.prototype.getNextUndoCommandText = function() { |
| | | svgedit.history.UndoManager.prototype.getNextUndoCommandText = function() { |
| | | return this.undoStackPointer > 0 ? this.undoStack[this.undoStackPointer-1].getText() : ""; |
| | | }; |
| | | |
| | | // Function: svgedit.history.UndoManager.getNextRedoCommandText |
| | | // Returns: |
| | | // Returns: |
| | | // String associated with the next redo command |
| | | svgedit.history.UndoManager.prototype.getNextRedoCommandText = function() { |
| | | svgedit.history.UndoManager.prototype.getNextRedoCommandText = function() { |
| | | return this.undoStackPointer < this.undoStack.length ? this.undoStack[this.undoStackPointer].getText() : ""; |
| | | }; |
| | | |
| | |
| | | } |
| | | }; |
| | | |
| | | // Function: svgedit.history.UndoManager.redo |
| | | // Function: svgedit.history.UndoManager.redo |
| | | // Performs a redo step |
| | | svgedit.history.UndoManager.prototype.redo = function() { |
| | | if (this.undoStackPointer < this.undoStack.length && this.undoStack.length > 0) { |
| | |
| | | cmd.apply(this.handler_); |
| | | } |
| | | }; |
| | | |
| | | |
| | | // Function: svgedit.history.UndoManager.addCommandToHistory |
| | | // Adds a command object to the undo history stack |
| | | // |
| | | // Parameters: |
| | | // Parameters: |
| | | // cmd - The command object to add |
| | | svgedit.history.UndoManager.prototype.addCommandToHistory = function(cmd) { |
| | | // FIXME: we MUST compress consecutive text changes to the same element |
| | | // (right now each keystroke is saved as a separate command that includes the |
| | | // entire text contents of the text element) |
| | | // TODO: consider limiting the history that we store here (need to do some slicing) |
| | | |
| | | |
| | | // if our stack pointer is not at the end, then we have to remove |
| | | // all commands after the pointer and insert the new command |
| | | if (this.undoStackPointer < this.undoStack.length && this.undoStack.length > 0) { |
| | |
| | | |
| | | |
| | | // Function: svgedit.history.UndoManager.beginUndoableChange |
| | | // This function tells the canvas to remember the old values of the |
| | | // attrName attribute for each element sent in. The elements and values |
| | | // are stored on a stack, so the next call to finishUndoableChange() will |
| | | // This function tells the canvas to remember the old values of the |
| | | // attrName attribute for each element sent in. The elements and values |
| | | // are stored on a stack, so the next call to finishUndoableChange() will |
| | | // pop the elements and old values off the stack, gets the current values |
| | | // from the DOM and uses all of these to construct the undo-able command. |
| | | // |
| | | // Parameters: |
| | | // Parameters: |
| | | // attrName - The name of the attribute being changed |
| | | // elems - Array of DOM elements being changed |
| | | svgedit.history.UndoManager.prototype.beginUndoableChange = function(attrName, elems) { |
| | |
| | | // change since beginUndoableChange was called. The command can then |
| | | // be added to the command history |
| | | // |
| | | // Returns: |
| | | // Returns: |
| | | // Batch command object with resulting changes |
| | | svgedit.history.UndoManager.prototype.finishUndoableChange = function() { |
| | | var p = this.undoChangeStackPointer--; |
| | |
| | | }; |
| | | |
| | | |
| | | })(); |
| | | })(); |