diff options
author | Ananya Sen | 2012-06-18 19:17:36 -0700 |
---|---|---|
committer | Ananya Sen | 2012-06-18 19:17:36 -0700 |
commit | 9ea2610cec6569e7b7d5268b6c65bbf94c4753e5 (patch) | |
tree | a89db52a299de040bde538144cc461555f6bb4ad /js/controllers | |
parent | 6aca635e82d7f5c1e3f6a4964d041c1d8eb3f306 (diff) | |
download | ninja-9ea2610cec6569e7b7d5268b6c65bbf94c4753e5.tar.gz |
start pasting in-place for cut/paste
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/controllers')
-rw-r--r-- | js/controllers/clipboard-controller.js | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/js/controllers/clipboard-controller.js b/js/controllers/clipboard-controller.js index db581d37..bc78922c 100644 --- a/js/controllers/clipboard-controller.js +++ b/js/controllers/clipboard-controller.js | |||
@@ -235,7 +235,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
235 | }else{ | 235 | }else{ |
236 | styles = null; | 236 | styles = null; |
237 | } | 237 | } |
238 | this.pastePositioned(node, styles); | 238 | this.pastePositioned(node, styles, true/*notify*/); |
239 | pastedElements.push(node); | 239 | pastedElements.push(node); |
240 | } | 240 | } |
241 | 241 | ||
@@ -263,6 +263,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
263 | canvas = this.generateNewCanvas(this.copiedObjects.cut[j].outerhtml, this.copiedObjects.cut[j].styles, this.copiedObjects.cut[j].className, this.copiedObjects.cut[j].worldJson); | 263 | canvas = this.generateNewCanvas(this.copiedObjects.cut[j].outerhtml, this.copiedObjects.cut[j].styles, this.copiedObjects.cut[j].className, this.copiedObjects.cut[j].worldJson); |
264 | NJevent("elementAdded", canvas); | 264 | NJevent("elementAdded", canvas); |
265 | pastedElements.push(canvas); | 265 | pastedElements.push(canvas); |
266 | clipboardHelper.removeChild(clipboardHelper.lastChild); | ||
266 | } | 267 | } |
267 | else if((clipboardHelper.lastChild.nodeType === 3) || (clipboardHelper.lastChild.tagName === "A")){//TextNode | 268 | else if((clipboardHelper.lastChild.nodeType === 3) || (clipboardHelper.lastChild.tagName === "A")){//TextNode |
268 | 269 | ||
@@ -270,7 +271,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
270 | } | 271 | } |
271 | else { | 272 | else { |
272 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); | 273 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); |
273 | this.pastePositioned(node, this.copiedObjects.cut[j].styles); | 274 | this.pastePositioned(node, this.copiedObjects.cut[j].styles, true/*notify*/, false/*fromCopy*/); |
274 | pastedElements.push(node); | 275 | pastedElements.push(node); |
275 | } | 276 | } |
276 | } | 277 | } |
@@ -328,7 +329,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
328 | styles = null; | 329 | styles = null; |
329 | //end - todo : not working | 330 | //end - todo : not working |
330 | 331 | ||
331 | this.pastePositioned(divWrapper, styles); | 332 | this.pastePositioned(divWrapper, styles, true/*notify*/); |
332 | }else if(clipboardHelper.lastChild.tagName === "SPAN"){ | 333 | }else if(clipboardHelper.lastChild.tagName === "SPAN"){ |
333 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); | 334 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); |
334 | 335 | ||
@@ -337,7 +338,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
337 | styles = null; | 338 | styles = null; |
338 | //end - todo : not working | 339 | //end - todo : not working |
339 | 340 | ||
340 | this.pastePositioned(divWrapper, styles); | 341 | this.pastePositioned(divWrapper, styles, true/*notify*/); |
341 | } | 342 | } |
342 | else { | 343 | else { |
343 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); | 344 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); |
@@ -345,7 +346,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
345 | //get class string while copying .... generate styles from class | 346 | //get class string while copying .... generate styles from class |
346 | styles = null; | 347 | styles = null; |
347 | 348 | ||
348 | this.pastePositioned(node, styles); | 349 | this.pastePositioned(node, styles, true/*notify*/); |
349 | } | 350 | } |
350 | 351 | ||
351 | } | 352 | } |
@@ -357,7 +358,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
357 | clipboardHelper.innerHTML = "<div><span>"+ textData +"</span></div>";//add the copied html to generate the nodes | 358 | clipboardHelper.innerHTML = "<div><span>"+ textData +"</span></div>";//add the copied html to generate the nodes |
358 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); | 359 | node = clipboardHelper.removeChild(clipboardHelper.lastChild); |
359 | styles = null;//get real stage center coordinates | 360 | styles = null;//get real stage center coordinates |
360 | this.pastePositioned(node, styles); | 361 | this.pastePositioned(node, styles, true/*notify*/); |
361 | } | 362 | } |
362 | 363 | ||
363 | } | 364 | } |
@@ -379,7 +380,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
379 | if(!ninjaClipboardObj.canvas){ | 380 | if(!ninjaClipboardObj.canvas){ |
380 | ninjaClipboardObj.canvas = true; | 381 | ninjaClipboardObj.canvas = true; |
381 | } | 382 | } |
382 | elObj["worldJson"] = this.application.ninja.selectedElements[j].elementModel.shapeModel.GLWorld.exportJSON(); | 383 | elObj["worldJson"] = this.application.ninja.selectedElements[j].elementModel.shapeModel ? this.application.ninja.selectedElements[j].elementModel.shapeModel.GLWorld.exportJSON(): null; |
383 | elObj["className"] = this.application.ninja.selectedElements[j].className; | 384 | elObj["className"] = this.application.ninja.selectedElements[j].className; |
384 | }else{ | 385 | }else{ |
385 | elObj["styles"] = this.getDominantStyles(this.application.ninja.selectedElements[j], false); | 386 | elObj["styles"] = this.getDominantStyles(this.application.ninja.selectedElements[j], false); |
@@ -475,7 +476,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
475 | 476 | ||
476 | this.application.ninja.elementMediator.addElements(canvas, styles, false); | 477 | this.application.ninja.elementMediator.addElements(canvas, styles, false); |
477 | 478 | ||
478 | worldData = sourceCanvas.elementModel.shapeModel.GLWorld.exportJSON(); | 479 | worldData = sourceCanvas.elementModel.shapeModel ? sourceCanvas.elementModel.shapeModel.GLWorld.exportJSON(): null; |
479 | if(worldData) | 480 | if(worldData) |
480 | { | 481 | { |
481 | var jObj; | 482 | var jObj; |
@@ -508,7 +509,7 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
508 | 509 | ||
509 | if (!canvas.getAttribute( "data-RDGE-id" )) canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); | 510 | if (!canvas.getAttribute( "data-RDGE-id" )) canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); |
510 | 511 | ||
511 | this.application.ninja.elementMediator.addElements(canvas, null, false); | 512 | this.pastePositioned(canvas, styles, false/*notify*/, false/*from copy*/); |
512 | 513 | ||
513 | worldData = worldJson; | 514 | worldData = worldJson; |
514 | 515 | ||
@@ -572,32 +573,25 @@ var ClipboardController = exports.ClipboardController = Montage.create(Component | |||
572 | 573 | ||
573 | 574 | ||
574 | pastePositioned:{ | 575 | pastePositioned:{ |
575 | value: function(element, styles){// for now can wok for both in-place and centered paste | 576 | value: function(element, styles, notify, fromCopy){// for now can wok for both in-place and centered paste |
576 | var modObject = [], x,y, newX, newY, translation; | 577 | var modObject = [], x,y, newX, newY, counter; |
578 | |||
579 | if((typeof fromCopy === "undefined") || (fromCopy && fromCopy === true)){ | ||
580 | counter = this.pasteCounter; | ||
581 | }else{ | ||
582 | counter = this.pasteCounter - 1; | ||
583 | } | ||
577 | 584 | ||
578 | x = styles ? ("" + styles.left + "px") : "100px"; | 585 | x = styles ? ("" + styles.left + "px") : "100px"; |
579 | y = styles ? ("" + styles.top + "px") : "100px"; | 586 | y = styles ? ("" + styles.top + "px") : "100px"; |
580 | newX = styles ? ("" + (styles.left + (25 * this.pasteCounter)) + "px") : "100px"; | 587 | newX = styles ? ("" + (styles.left + (25 * counter)) + "px") : "100px"; |
581 | newY = styles ? ("" + (styles.top + (25 * this.pasteCounter)) + "px") : "100px"; | 588 | newY = styles ? ("" + (styles.top + (25 * counter)) + "px") : "100px"; |
582 | 589 | ||
583 | if(!styles || (styles && !styles.position)){ | 590 | if(!styles || (styles && !styles.position)){ |
584 | this.application.ninja.elementMediator.addElements(element, null); | 591 | this.application.ninja.elementMediator.addElements(element, null, notify); |
585 | }else if(styles && (styles.position === "absolute")){ | 592 | }else if(styles && (styles.position === "absolute")){ |
586 | this.application.ninja.elementMediator.addElements(element, {"top" : newY, "left" : newX});//displace | 593 | this.application.ninja.elementMediator.addElements(element, {"top" : newY, "left" : newX}, notify);//displace |
587 | } | 594 | } |
588 | |||
589 | //todo: cleanup | ||
590 | // //add pasted object with new position | ||
591 | // translation = {"left": newX, "top": newY}; | ||
592 | // this.application.ninja.elementMediator.addElements(element, translation); | ||
593 | // | ||
594 | |||
595 | // //OR - first paste on top and then move the pasted object to make it visible to user | ||
596 | // this.application.ninja.elementMediator.addElements(element, null, false); | ||
597 | // modObject.push({element:element, properties:{left: newX, top:newY}, previousProperties: {left: x, top:y}}); | ||
598 | // this.application.ninja.elementMediator.setProperties(modObject, "Change", "clipboard-controller" ); | ||
599 | // NJevent("elementAdded", element); | ||
600 | |||
601 | } | 595 | } |
602 | }, | 596 | }, |
603 | 597 | ||