From 609ad21e56623827c5ca203cf6062f70d3067764 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 11 Jun 2012 17:13:31 -0700 Subject: - removed extra selection change event, - displace element after adding it to the document Signed-off-by: Ananya Sen --- js/controllers/clipboard-controller.js | 55 +++++++++++++--------- .../styles-view-container.js | 2 +- js/stage/stage.reel/stage.js | 2 +- 3 files changed, 34 insertions(+), 25 deletions(-) (limited to 'js') diff --git a/js/controllers/clipboard-controller.js b/js/controllers/clipboard-controller.js index e7b772d4..57ee5c64 100644 --- a/js/controllers/clipboard-controller.js +++ b/js/controllers/clipboard-controller.js @@ -76,7 +76,11 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component handleCopy:{ value:function(clipboardEvent){ - if(this.application.ninja.currentDocument.currentView === "code") return; + if(!this.application.ninja.currentDocument + || (this.application.ninja.currentDocument && this.application.ninja.currentDocument.currentView === "code")){ + + return; + }//for design view only this.copy(clipboardEvent); @@ -96,7 +100,11 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component handlePaste:{ value:function(clipboardEvent){ - if(this.application.ninja.currentDocument.currentView === "code") return;//for design view only + if(!this.application.ninja.currentDocument + || (this.application.ninja.currentDocument && this.application.ninja.currentDocument.currentView === "code")){ + + return; + }//for design view only //TODO: return if stage is not focussed @@ -173,11 +181,6 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component //TODO: cleanse HTML - //clear previous selections - this.application.ninja.selectedElements.length = 0; - NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": true} ); - - for(j=0; j< this.copiedObjects.copy.length; j++){ copiedElement = this.copiedObjects.copy[j]; styles = null; @@ -280,16 +283,9 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component //can't paste external canvas for lack of all metadata clipboardHelper.removeChild(clipboardHelper.lastChild); } - else if((clipboardHelper.lastChild.nodeType === 3) || (clipboardHelper.lastChild.tagName === "A")){//TextNode + else if((clipboardHelper.lastChild.nodeType === 3) || (clipboardHelper.lastChild.tagName === "A")){ node = clipboardHelper.removeChild(clipboardHelper.lastChild); - //todo : not working - USE styles controller to create the styles of the div and span -// var doc = this.application.ninja.currentDocument ? this.application.ninja.currentDocument._document : document; -// var aspan = doc.createElement("span"); -// aspan.appendChild(node); -// var adiv = doc.createElement("div"); -// adiv.appendChild(aspan); - divWrapper = document.application.njUtils.make("div", null, this.application.ninja.currentDocument); spanWrapper = document.application.njUtils.make("span", null, this.application.ninja.currentDocument); spanWrapper.appendChild(node); @@ -297,6 +293,15 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component styles = null; //end - todo : not working + this.pastePositioned(divWrapper, styles); + }else if(clipboardHelper.lastChild.tagName === "SPAN"){ + node = clipboardHelper.removeChild(clipboardHelper.lastChild); + + divWrapper = document.application.njUtils.make("div", null, this.application.ninja.currentDocument); + divWrapper.appendChild(node); + styles = null; + //end - todo : not working + this.pastePositioned(divWrapper, styles); } else { @@ -536,16 +541,20 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component newX = styles ? ("" + (styles.left + (25 * this.pasteCounter)) + "px") : "100px"; newY = styles ? ("" + (styles.top + (25 * this.pasteCounter)) + "px") : "100px"; - translation = {"left": newX, "top": newY}; - //add the pasted object on top of the copied object - this.application.ninja.elementMediator.addElements(element, translation); -// //move the pasted object to make it visible to user -// modObject.push({element:element, properties:{left: newX, top:newY}, previousProperties: {left: x, top:y}}); -// this.application.ninja.elementMediator.setProperties(modObject, "Change", "clipboard-controller" ); + +// //add pasted object with new position +// translation = {"left": newX, "top": newY}; +// this.application.ninja.elementMediator.addElements(element, translation); // -// element.elementModel.setProperty("x", this.application.ninja.elementMediator.getProperty(element, "left")); -// element.elementModel.setProperty("y", this.application.ninja.elementMediator.getProperty(element, "top")); + + + //first paste on top and then move the pasted object to make it visible to user + this.application.ninja.elementMediator.addElements(element, null, false); + modObject.push({element:element, properties:{left: newX, top:newY}, previousProperties: {left: x, top:y}}); + this.application.ninja.elementMediator.setProperties(modObject, "Change", "clipboard-controller" ); + NJevent("elementAdded", element); + } }, diff --git a/js/panels/css-panel/styles-view-container.reel/styles-view-container.js b/js/panels/css-panel/styles-view-container.reel/styles-view-container.js index 157d99de..4a09d5f3 100644 --- a/js/panels/css-panel/styles-view-container.reel/styles-view-container.js +++ b/js/panels/css-panel/styles-view-container.reel/styles-view-container.js @@ -110,7 +110,7 @@ exports.StylesViewContainer = Montage.create(Component, { } }, handleSelectionChange: { - value: function() { + value: function(e) { var elements = this.application.ninja.selectedElements, elementsCopy = this._copy(elements); diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 30ee1e40..2177616d 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -634,7 +634,7 @@ exports.Stage = Montage.create(Component, { point = webkitConvertPointFromPageToNode(this.canvas, new WebKitPoint(position.pageX - docView.iframe.contentWindow.pageXOffset + this.documentOffsetLeft, position.pageY - docView.iframe.contentWindow.pageYOffset + this.documentOffsetTop)); element = this.currentDocument.model.views.design.getElementFromPoint(point.x - this.userContentLeft,point.y - this.userContentTop); - if(!element) debugger; +// if(!element) debugger; // workaround Chrome 3d bug if(this.application.ninja.toolsData.selectedToolInstance._canSnap && this.currentDocument.inExclusion(element) !== -1) { point = webkitConvertPointFromPageToNode(this.canvas, new WebKitPoint(position.pageX, position.pageY)); -- cgit v1.2.3