wisemapping-open-source/mindplot/src/main/javascript/DesignerUndoManager.js

83 lines
2.7 KiB
JavaScript
Raw Normal View History

2009-06-07 20:59:43 +02:00
/*
2011-07-27 13:25:10 +02:00
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2009-06-07 20:59:43 +02:00
mindplot.DesignerUndoManager = new Class({
2011-08-05 03:12:53 +02:00
initialize: function(fireChange) {
2009-06-07 20:59:43 +02:00
this._undoQueue = [];
this._redoQueue = [];
this._baseId = 0;
},
2011-07-27 13:25:10 +02:00
enqueue:function(command) {
$assert(command, "Command can not be null");
2009-06-07 20:59:43 +02:00
var length = this._undoQueue.length;
if (command.discardDuplicated && length > 0) {
2009-06-07 20:59:43 +02:00
// Skip duplicated events ...
var lastItem = this._undoQueue[length - 1];
if (lastItem.discardDuplicated != command.discardDuplicated) {
2009-06-07 20:59:43 +02:00
this._undoQueue.push(command);
}
2011-07-27 13:25:10 +02:00
} else {
2009-06-07 20:59:43 +02:00
this._undoQueue.push(command);
}
this._redoQueue = [];
},
2011-07-27 13:25:10 +02:00
execUndo: function(commandContext) {
if (this._undoQueue.length > 0) {
2009-06-07 20:59:43 +02:00
var command = this._undoQueue.pop();
this._redoQueue.push(command);
command.undoExecute(commandContext);
}
},
2011-07-27 13:25:10 +02:00
execRedo: function(commandContext) {
if (this._redoQueue.length > 0) {
2009-06-07 20:59:43 +02:00
var command = this._redoQueue.pop();
this._undoQueue.push(command);
command.execute(commandContext);
}
},
2011-07-27 13:25:10 +02:00
2011-08-05 03:12:53 +02:00
buildEvent: function() {
2009-06-07 20:59:43 +02:00
return {undoSteps: this._undoQueue.length, redoSteps:this._redoQueue.length};
},
2011-07-27 13:25:10 +02:00
markAsChangeBase: function() {
var undoLength = this._undoQueue.length;
if (undoLength > 0) {
var command = this._undoQueue[undoLength - 1];
2009-06-07 20:59:43 +02:00
this._baseId = command.getId();
2011-07-27 13:25:10 +02:00
} else {
2009-06-07 20:59:43 +02:00
this._baseId = 0;
}
},
2011-07-27 13:25:10 +02:00
hasBeenChanged: function() {
2009-06-07 20:59:43 +02:00
var result = true;
var undoLength= this._undoQueue.length;
if (undoLength == 0 && this._baseId == 0) {
2009-06-07 20:59:43 +02:00
result = false;
} else if (undoLength > 0) {
var command = this._undoQueue[undoLength - 1];
2009-06-07 20:59:43 +02:00
result = (this._baseId != command.getId());
}
return result;
2011-07-27 13:25:10 +02:00
}
});