Add global undo for graph

This commit is contained in:
Oleg Sh
2021-07-17 21:53:21 +02:00
parent 50f1d0b936
commit 112e2b37ae
6 changed files with 97 additions and 40 deletions

View File

@@ -734,6 +734,11 @@ Application.prototype.SetHandlerMode = function(mode)
var setupBackgroundStyle = new SetupBackgroundStyle(this);
setupBackgroundStyle.show();
}
else if (mode == "graphUndo")
{
if (!this.IsUndoStackEmpty())
this.Undo();
}
else if (g_AlgorithmIds.indexOf(mode) >= 0)
{
this.handler = new AlgorithmGraphHandler(this, g_Algorithms[g_AlgorithmIds.indexOf(mode)](this.graph, this));
@@ -819,6 +824,9 @@ Application.prototype.onPostLoadEvent = function()
}
}
if (this.IsUndoStackEmpty())
document.getElementById('GraphUndo').style.display = 'none';
this.updateMessage();
this.redrawGraph();
}
@@ -1341,14 +1349,18 @@ Application.prototype.PushToStack = function(actionName)
{
var object = {};
object.actionName = actionName;
object.graphSave = this.graph.SaveToXML("");
object.graphSave = this.graph.SaveToXML(this.SaveUserSettings());
this.undoStack.push(object);
while (this.undoStack.length > this.maxUndoStackSize)
{
this.undoStack.shift();
}
//console.log("push undo:" + object.actionName + " size =" + this.undoStack.length);
document.getElementById('GraphUndo').style.display = 'inline-block';
}
Application.prototype.Undo = function()
@@ -1358,9 +1370,18 @@ Application.prototype.Undo = function()
var state = this.undoStack.pop();
this.graph = new Graph();
var empty;
this.graph.LoadFromXML(state.graphSave, empty);
var userSettings = {};
this.graph.LoadFromXML(state.graphSave, userSettings);
if (userSettings.hasOwnProperty("data") && userSettings["data"].length > 0)
this.LoadUserSettings(userSettings["data"]);
this.redrawGraph();
//console.log("undo:" + state.actionName + " size =" + this.undoStack.length);
if (this.IsUndoStackEmpty())
document.getElementById('GraphUndo').style.display = 'none';
}
Application.prototype.ClearUndoStack = function()