From 2edcdd88ffc2f6ff0ea836e4da3e1fd2cb3e856f Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 27 Feb 2012 17:39:26 -0800 Subject: persist undo/redo stack per html document Signed-off-by: Ananya Sen --- js/controllers/undo-controller.js | 17 ++++++++++++++-- js/document/html-document.js | 29 ++++++++++++++++++++++++++++ js/models/color-model.js | 6 +++--- js/ninja.reel/ninja.js | 3 +++ js/panels/properties/content.reel/content.js | 4 ++-- 5 files changed, 52 insertions(+), 7 deletions(-) (limited to 'js') diff --git a/js/controllers/undo-controller.js b/js/controllers/undo-controller.js index 926803d3..01853593 100755 --- a/js/controllers/undo-controller.js +++ b/js/controllers/undo-controller.js @@ -71,22 +71,28 @@ exports.UndoController = Montage.create( Component, { /** * Undo Queue */ - _undoQueue: { value: [] }, + _undoQueue: { value: [], writable:true }, undoQueue: { get: function() { return this._undoQueue; + }, + set: function(value){ + this._undoQueue = value; } }, /** * Redo Queue */ - _redoQueue: { value: [], enumerable: false }, + _redoQueue: { value: [], enumerable: false, writable:true }, redoQueue: { get: function() { return this._redoQueue; + }, + set: function(value){ + this._redoQueue = value; } }, @@ -202,5 +208,12 @@ exports.UndoController = Montage.create( Component, { this.redoQueue.splice(0, this.redoQueue.length); //this.redoQueue = []; } + }, + + clearHistory:{ + value: function(){ + this.undoQueue.splice(0, this.undoQueue.length); + this.redoQueue.splice(0, this.redoQueue.length); + } } }); \ No newline at end of file diff --git a/js/document/html-document.js b/js/document/html-document.js index 75628731..111c491d 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -59,6 +59,27 @@ exports.HTMLDocument = Montage.create(TextDocument, { _gridVerticalSpacing: {value:0}, //end - drawUtils state + _undoStack: { value: [] }, + undoStack: { + get: function() { + return this._undoStack; + }, + set:function(value){ + this._undoStack = value; + } + }, + + _redoStack: { value: [], enumerable: false }, + + redoStack: { + get: function() { + return this._redoStack; + }, + set:function(value){ + this._redoStack = value; + } + }, + // GETTERS / SETTERS @@ -681,6 +702,11 @@ exports.HTMLDocument = Montage.create(TextDocument, { } this.draw3DGrid = this.application.ninja.appModel.show3dGrid; + + //persist a clone of history per document + this.undoStack = this.application.ninja.undocontroller.undoQueue.slice(0); + this.redoStack = this.application.ninja.undocontroller.redoQueue.slice(0); + this.application.ninja.undocontroller.clearHistory();//clear history to give the next document a fresh start } }, @@ -704,6 +730,9 @@ exports.HTMLDocument = Montage.create(TextDocument, { this.application.ninja.stage.handleScroll(); this.application.ninja.appModel.show3dGrid = this.draw3DGrid; + + this.application.ninja.undocontroller.undoQueue = this.undoStack.slice(0); + this.application.ninja.undocontroller.redoQueue = this.redoStack.slice(0); } } //////////////////////////////////////////////////////////////////// diff --git a/js/models/color-model.js b/js/models/color-model.js index 2c86422f..d3618c3e 100755 --- a/js/models/color-model.js +++ b/js/models/color-model.js @@ -265,7 +265,7 @@ exports.ColorModel = Montage.create(Component, { //////////////////////////////////////////////////////// case 'rgb': //Checking for match of previous (RGB) - if (color.r !== this.rgb.r && color.g !== this.rgb.g && color.b !== this.rgb.b) { + if (color && color.r !== this.rgb.r && color.g !== this.rgb.g && color.b !== this.rgb.b) { //Setting value and breaking out of function this.rgb = color; return; @@ -279,7 +279,7 @@ exports.ColorModel = Montage.create(Component, { //////////////////////////////////////////////////////// case 'hsv': //Checking for match of previous (HSV) - if (color.h !== this.hsv.h && color.s !== this.hsv.s && color.v !== this.hsv.v) { + if (color && color.h !== this.hsv.h && color.s !== this.hsv.s && color.v !== this.hsv.v) { //Setting value and breaking out of function this.hsv = color; return; @@ -293,7 +293,7 @@ exports.ColorModel = Montage.create(Component, { //////////////////////////////////////////////////////// case 'hsl': //Checking for match of previous (HSV) - if (color.h !== this.hsl.h && color.s !== this.hsl.s && color.l !== this.hsl.l) { + if (color && color.h !== this.hsl.h && color.s !== this.hsl.s && color.l !== this.hsl.l) { //Setting value and breaking out of function this.hsl = color; return; diff --git a/js/ninja.reel/ninja.js b/js/ninja.reel/ninja.js index 6efeef8a..ab9503ec 100755 --- a/js/ninja.reel/ninja.js +++ b/js/ninja.reel/ninja.js @@ -98,6 +98,9 @@ exports.Ninja = Montage.create(Component, { if(this._appLoaded && this._preload) { // App is now deserialized and files are preloaded this.appModel.materials = MaterialsLibrary.materials; + + this.currentDocument = null; + } } }, diff --git a/js/panels/properties/content.reel/content.js b/js/panels/properties/content.reel/content.js index 8fa33a75..fa4c56f2 100755 --- a/js/panels/properties/content.reel/content.js +++ b/js/panels/properties/content.reel/content.js @@ -268,12 +268,12 @@ exports.Content = Montage.create(Component, { } else { - if (currentValue.color.a !== undefined) + if (currentValue.color && (currentValue.color.a !== undefined)) { this.application.ninja.colorController.colorModel.alpha = {value: currentValue.color.a, wasSetByCode: true, type: 'change'}; } - if(currentValue.color.mode) + if(currentValue.color && currentValue.color.mode) { this.application.ninja.colorController.colorModel[currentValue.color.mode] = currentValue.color; } -- cgit v1.2.3