mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-04-07 08:16:18 +00:00
Refactor Undo and SaveLoad from disk.
This commit is contained in:
41
script/pages/editor/model/UndoStack.js
Normal file
41
script/pages/editor/model/UndoStack.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// Undo Stack
|
||||
|
||||
|
||||
|
||||
function UndoStack(maxUndoStackSize) {
|
||||
this.undoStack = [];
|
||||
this.maxUndoStackSize = maxUndoStackSize;
|
||||
}
|
||||
|
||||
UndoStack.prototype.PushToStack = function(actionName, dataToSave)
|
||||
{
|
||||
var object = {};
|
||||
object.actionName = actionName;
|
||||
object.data = dataToSave;
|
||||
|
||||
this.undoStack.push(object);
|
||||
|
||||
while (this.undoStack.length > this.maxUndoStackSize)
|
||||
{
|
||||
this.undoStack.shift();
|
||||
}
|
||||
}
|
||||
|
||||
UndoStack.prototype.Undo = function()
|
||||
{
|
||||
if (this.IsUndoStackEmpty())
|
||||
return null;
|
||||
|
||||
var state = this.undoStack.pop();
|
||||
return state.data;
|
||||
}
|
||||
|
||||
UndoStack.prototype.ClearUndoStack = function()
|
||||
{
|
||||
this.undoStack = [];
|
||||
}
|
||||
|
||||
UndoStack.prototype.IsUndoStackEmpty = function()
|
||||
{
|
||||
return (this.undoStack.length <= 0);
|
||||
}
|
||||
Reference in New Issue
Block a user