From ebe6a42bdf76d53a985dec528ad9702df3738f56 Mon Sep 17 00:00:00 2001 From: Jon Reid Date: Fri, 9 Mar 2012 15:34:46 -0800 Subject: Timeline: Fixes for deleting layers, layer selection, persisting layer name edits and selection between document switching. --- js/panels/Timeline/Layer.reel/Layer.js | 6 +- .../Timeline/TimelinePanel.reel/TimelinePanel.js | 109 ++++++++++++--------- 2 files changed, 66 insertions(+), 49 deletions(-) (limited to 'js') diff --git a/js/panels/Timeline/Layer.reel/Layer.js b/js/panels/Timeline/Layer.reel/Layer.js index e561e45d..b41680be 100644 --- a/js/panels/Timeline/Layer.reel/Layer.js +++ b/js/panels/Timeline/Layer.reel/Layer.js @@ -82,8 +82,8 @@ var Layer = exports.Layer = Montage.create(Component, { if (newVal !== this._layerName) { this._layerEditable.value = newVal; this._layerName = newVal; - //this._layerEditable.needsDraw = true; - //this.needsDraw = true; + this.layerData.layerName = newVal; + this.log('layerName setter: ' + newVal) } } @@ -259,6 +259,7 @@ var Layer = exports.Layer = Montage.create(Component, { this.selectStyle(false); } this._isSelected = value; + this.layerData.isSelected = value; //this.needsDraw = true; } @@ -405,6 +406,7 @@ var Layer = exports.Layer = Montage.create(Component, { setData:{ value:function(){ + this.log('layer: setData called') this.layerName = this.layerData.layerName; this.layerID = this.layerData.layerID; this.arrLayerStyles = this.layerData.arrLayerStyles; diff --git a/js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js b/js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js index a1730b37..8ae801fc 100644 --- a/js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js +++ b/js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js @@ -126,9 +126,18 @@ var TimelinePanel = exports.TimelinePanel = Montage.create(Component, { } }, - currentLayerSelected:{ + _currentLayerSelected:{ value: null }, + currentLayerSelected : { + get: function() { + return this._currentLayerSelected; + }, + set: function(newVal) { + this._currentLayerSelected = newVal; + this.application.ninja.currentDocument.tlCurrentLayerSelected = newVal; + } + }, millisecondsOffset:{ value:1000 @@ -391,10 +400,29 @@ var TimelinePanel = exports.TimelinePanel = Montage.create(Component, { this._boolCacheArrays = false; this.arrLayers = this.application.ninja.currentDocument.tlArrLayers; this.currentLayerNumber = this.application.ninja.currentDocument.tllayerNumber; + this.currentLayerSelected = this.application.ninja.currentDocument.tlCurrentLayerSelected; this.hashInstance = this.application.ninja.currentDocument.tlLayerHashTable; this.hashElementMapToLayer = this.application.ninja.currentDocument.tlElementHashTable; this.hashKey = this.application.ninja.currentDocument.hashKey; this._boolCacheArrays = true; + + // Search through the arrLayers and select the layer that's already selected + var i = 0, + selectMe = 0, + arrLayersLength = this.arrLayers.length; + for (i = 0; i < arrLayersLength; i++) { + if (this.arrLayers[i].isSelected === true) { + selectMe = i; + } + } + + + this._captureSelection = true; + // TODO: Better solution than a timer. + var that = this; + setTimeout(function() { + that.selectLayer(selectMe, true); + }, 300) } } }, @@ -651,7 +679,6 @@ var TimelinePanel = exports.TimelinePanel = Montage.create(Component, { // layer on top of it. myIndex = this.layerRepetition.selectedIndexes[0]; thingToPush.layerData.layerPosition = myIndex; - thingToPush.layerData.isSelected = true; thingToPush.layerData.trackPosition = myIndex; this.arrLayers.splice(myIndex, 0, thingToPush); this._LayerUndoPosition = myIndex; @@ -665,13 +692,21 @@ var TimelinePanel = exports.TimelinePanel = Montage.create(Component, { this._LayerUndoPosition = this.arrLayers.length - 1; //this.hashLayerNumber.setItem(this.hashKey, thingToPush.layerData); this.hashInstance.setItem(this.hashKey, thingToPush.layerData, thingToPush.layerData.layerPosition); + indexToSelect = this.arrLayers.length -1; } this._LayerUndoObject = thingToPush; this._LayerUndoIndex = thingToPush.layerData.layerID; this._LayerUndoStatus = true; - - this.selectLayer(indexToSelect, true); + + this._captureSelection = true; + + // TODO: Find a better solution than a timout here. + var that = this; + setTimeout(function() { + that.selectLayer(indexToSelect, true); + }, 500); + } } @@ -768,36 +803,23 @@ var TimelinePanel = exports.TimelinePanel = Montage.create(Component, { hashVariable++; } } - } - else { - if (!!this.layerRepetition.selectedIndexes) { - + } else { + // Only delete a selected layer. If no layer is selected, do nothing. + if (this.layerRepetition.selectedIndexes.length > 0) { + // Delete the selected item. var myIndex = this.layerRepetition.selectedIndexes[0]; this._LayerUndoObject = this.arrLayers[myIndex]; - dLayer = this.hashInstance.getItem(this.hashKey); - dLayer[myIndex].layerData.deleted = true; + // Deleting a layer should delete associated elements, + // But the hash tables are messed up. + // TODO: Kruti can you fix this? + //dLayer = this.hashInstance.getItem(this.hashKey); + //dLayer[myIndex].layerData.deleted = true; + // ElementMediator.deleteElements(dLayer[myIndex].layerData.elementsList); this.arrLayers.splice(myIndex, 1); this._LayerUndoIndex = this._LayerUndoObject.layerData.layerID; this._LayerUndoPosition = myIndex; - - if(myIndex===0){ - this.selectLayer(0); - } - else{ - this.selectLayer(myIndex-1); - } - ElementMediator.deleteElements(dLayer[myIndex].layerData.elementsList); - - } else { - dLayer = this.hashInstance.getItem(this.hashKey); - dLayer[this.arrLayers.length - 1].layerData.deleted = true; - ElementMediator.deleteElements(dLayer[this.arrLayers.length - 1].layerData.elementsList); - this._LayerUndoPosition = this.arrLayers.length - 1; - this._LayerUndoObject = this.arrLayers.pop(); - this._LayerUndoIndex = this._LayerUndoObject.layerData.layerID; - } } } @@ -981,38 +1003,31 @@ var TimelinePanel = exports.TimelinePanel = Montage.create(Component, { value:function (layerIndex, userSelection) { var i = 0; var arrLayersLength = this.arrLayers.length; - + if(this.selectedKeyframes){ this.deselectTweens(); } for (i = 0; i < arrLayersLength; i++) { if (i === layerIndex) { - this.arrLayers[i].layerData.isSelected = true; + this.arrLayers[i].isSelected = true; } else { - this.arrLayers[i].layerData.isSelected = false; + this.arrLayers[i].isSelected = false; } } - //if (layerIndex !== false) { - this.layerRepetition.selectedIndexes = [layerIndex]; - this.currentLayerSelected = this.arrLayers[layerIndex]; - if(userSelection){ - if(this._captureSelection){ - if(this.currentLayerSelected.layerData.elementsList.length >= 1) { - this.application.ninja.selectionController.selectElements(this.currentLayerSelected.layerData.elementsList); - } else { - this.application.ninja.selectionController.executeSelectElement(); - } + + this.layerRepetition.selectedIndexes = [layerIndex]; + this.currentLayerSelected = this.arrLayers[layerIndex]; + if(userSelection){ + if(this._captureSelection){ + if(this.currentLayerSelected.layerData.elementsList.length >= 1) { + this.application.ninja.selectionController.selectElements(this.currentLayerSelected.layerData.elementsList); + } else { + this.application.ninja.selectionController.executeSelectElement(); } - this._captureSelection = true; } - /* - } else { - this.layerRepetition.selectedIndexes = null; - this.trackRepetition.selectedIndexes = null; - this.currentLayerSelected = null; + this._captureSelection = true; } - */ } }, -- cgit v1.2.3