From 0dafb4b31b4d659a4d7db20cd0987a5b44009540 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 24 Sep 2012 14:54:19 -0300 Subject: [PATCH] - Fix undo of multiple nodes. --- .../main/javascript/commands/DeleteCommand.js | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/mindplot/src/main/javascript/commands/DeleteCommand.js b/mindplot/src/main/javascript/commands/DeleteCommand.js index 77a859f8..9e06229e 100644 --- a/mindplot/src/main/javascript/commands/DeleteCommand.js +++ b/mindplot/src/main/javascript/commands/DeleteCommand.js @@ -76,20 +76,30 @@ mindplot.commands.DeleteCommand = new Class({ undoExecute:function (commandContext) { - var parent = commandContext.findTopics(this._parentTopicIds); + // Add all the topics ... + this._deletedTopicModels.each(function (model) { + commandContext.createTopic(model); + }, this); + + // Do they need to be connected ? this._deletedTopicModels.each(function (model, index) { - var topic = commandContext.createTopic(model); + var topicModel = this._deletedTopicModels[index]; + var topics = commandContext.findTopics(topicModel.getId()); - // Was the topic connected? - var parentTopic = parent[index]; - if (parentTopic != null) { - commandContext.connect(topic, parentTopic); - topic.setOnFocus(true); + var parentId = this._parentTopicIds[index]; + if (parentId) { + var parentTopics = commandContext.findTopics(parentId); + commandContext.connect(topics[0], parentTopics[0]); } - }, this); + // Focus on last recovered topic .. + var firstTopic = this._deletedTopicModels[0]; + var topic = commandContext.findTopics(firstTopic.getId())[0]; + topic.setOnFocus(true); + + // Add rebuild relationships ... this._deletedRelModel.each(function (model) { commandContext.addRelationship(model); }.bind(this));