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) {
|
2011-07-27 19:33:02 +02:00
|
|
|
$assert(command, "Command can not be null");
|
2009-06-07 20:59:43 +02:00
|
|
|
var length = this._undoQueue.length;
|
2012-02-02 04:13:29 +01:00
|
|
|
if (command.discardDuplicated && length > 0) {
|
2009-06-07 20:59:43 +02:00
|
|
|
// Skip duplicated events ...
|
|
|
|
var lastItem = this._undoQueue[length - 1];
|
2012-02-02 04:13:29 +01:00
|
|
|
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() {
|
2012-07-16 03:20:21 +02:00
|
|
|
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;
|
2012-07-16 03:20:21 +02:00
|
|
|
var undoLength= this._undoQueue.length;
|
|
|
|
if (undoLength == 0 && this._baseId == 0) {
|
2009-06-07 20:59:43 +02:00
|
|
|
result = false;
|
2012-07-16 03:20:21 +02:00
|
|
|
} 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
|
|
|
}
|
|
|
|
});
|