diff options
author | Valerio Virgillito | 2012-06-21 16:26:52 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-06-21 16:26:52 -0700 |
commit | 2af33f19de48bb8fe269c51ceddd1bc1f591651f (patch) | |
tree | 564528119093e4e3408ccf180d55ac3d5e413813 /js/clipboard/internal-ops | |
parent | c411f76d89c543837548085ff468fee0fb4f2ff9 (diff) | |
parent | 47be0919aa271e97fd7ca86e65cdf93aeee2bf81 (diff) | |
download | ninja-2af33f19de48bb8fe269c51ceddd1bc1f591651f.tar.gz |
Merge pull request #320 from ananyasen/cut-copy-paste
copy cut paste - project phase 1 check in
Diffstat (limited to 'js/clipboard/internal-ops')
-rw-r--r-- | js/clipboard/internal-ops/component-clipboard-agent.js | 40 | ||||
-rw-r--r-- | js/clipboard/internal-ops/css-clipboard-agent.js | 40 | ||||
-rw-r--r-- | js/clipboard/internal-ops/elements-clipboard-agent.js | 364 | ||||
-rw-r--r-- | js/clipboard/internal-ops/timeline-clipboard-agent.js | 40 |
4 files changed, 484 insertions, 0 deletions
diff --git a/js/clipboard/internal-ops/component-clipboard-agent.js b/js/clipboard/internal-ops/component-clipboard-agent.js new file mode 100644 index 00000000..8b589a27 --- /dev/null +++ b/js/clipboard/internal-ops/component-clipboard-agent.js | |||
@@ -0,0 +1,40 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | //////////////////////////////////////////////////////////////////////// | ||
8 | // | ||
9 | |||
10 | var Montage = require("montage/core/core").Montage, | ||
11 | Component = require("montage/ui/component").Component; | ||
12 | |||
13 | var ComponentsClipboardAgent = exports.ComponentsClipboardAgent = Montage.create(Component, { | ||
14 | |||
15 | copy:{ | ||
16 | value: function(clipboardEvent){ | ||
17 | |||
18 | } | ||
19 | }, | ||
20 | |||
21 | cut:{ | ||
22 | value:function(clipboardEvent){ | ||
23 | |||
24 | } | ||
25 | |||
26 | }, | ||
27 | |||
28 | pasteFromCopy:{ | ||
29 | value:function(){ | ||
30 | |||
31 | } | ||
32 | }, | ||
33 | |||
34 | pasteFromCut:{ | ||
35 | value:function(){ | ||
36 | |||
37 | } | ||
38 | } | ||
39 | |||
40 | }); \ No newline at end of file | ||
diff --git a/js/clipboard/internal-ops/css-clipboard-agent.js b/js/clipboard/internal-ops/css-clipboard-agent.js new file mode 100644 index 00000000..690a3a84 --- /dev/null +++ b/js/clipboard/internal-ops/css-clipboard-agent.js | |||
@@ -0,0 +1,40 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | //////////////////////////////////////////////////////////////////////// | ||
8 | // | ||
9 | |||
10 | var Montage = require("montage/core/core").Montage, | ||
11 | Component = require("montage/ui/component").Component; | ||
12 | |||
13 | var CssClipboardAgent = exports.CssClipboardAgent = Montage.create(Component, { | ||
14 | |||
15 | copy:{ | ||
16 | value: function(clipboardEvent){ | ||
17 | |||
18 | } | ||
19 | }, | ||
20 | |||
21 | cut:{ | ||
22 | value:function(clipboardEvent){ | ||
23 | |||
24 | } | ||
25 | |||
26 | }, | ||
27 | |||
28 | pasteFromCopy:{ | ||
29 | value:function(){ | ||
30 | |||
31 | } | ||
32 | }, | ||
33 | |||
34 | pasteFromCut:{ | ||
35 | value:function(){ | ||
36 | |||
37 | } | ||
38 | } | ||
39 | |||
40 | }); \ No newline at end of file | ||
diff --git a/js/clipboard/internal-ops/elements-clipboard-agent.js b/js/clipboard/internal-ops/elements-clipboard-agent.js new file mode 100644 index 00000000..cd8de46e --- /dev/null +++ b/js/clipboard/internal-ops/elements-clipboard-agent.js | |||
@@ -0,0 +1,364 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | //////////////////////////////////////////////////////////////////////// | ||
8 | // | ||
9 | |||
10 | var Montage = require("montage/core/core").Montage, | ||
11 | Component = require("montage/ui/component").Component, | ||
12 | ClipboardUtil = require("js/clipboard/util").ClipboardUtil, | ||
13 | World = require("js/lib/drawing/world").World; | ||
14 | |||
15 | var ElementsClipboardAgent = exports.ElementsClipboardAgent = Montage.create(Component, { | ||
16 | |||
17 | //count how many times pasted | ||
18 | //used to move multiple pastes of same copy | ||
19 | pasteCounter:{ | ||
20 | value: 0 | ||
21 | }, | ||
22 | |||
23 | copiedObjects:{ | ||
24 | value: {} | ||
25 | }, | ||
26 | |||
27 | copy:{ | ||
28 | value: function(clipboardEvent){ | ||
29 | var j=0, htmlToClipboard = "", ninjaClipboardObj = {}, textToClipboard = ""; | ||
30 | this.copiedObjects = {}; | ||
31 | this.pasteCounter = 0; | ||
32 | this.copiedObjects["copy"] = []; | ||
33 | |||
34 | if(clipboardEvent){ | ||
35 | for(j=0; j < this.application.ninja.selectedElements.length; j++){//copying from stage | ||
36 | this.copiedObjects.copy.push(this.application.ninja.selectedElements[j]); | ||
37 | |||
38 | if(this.application.ninja.selectedElements[j].tagName === "CANVAS"){ | ||
39 | if(!ninjaClipboardObj.canvas){ | ||
40 | ninjaClipboardObj.canvas = true; | ||
41 | } | ||
42 | }else{ | ||
43 | htmlToClipboard = htmlToClipboard + this.serializeHTMLElement(this.application.ninja.selectedElements[j]); | ||
44 | if(!ninjaClipboardObj.plainHtml){ | ||
45 | ninjaClipboardObj.plainHtml = true; | ||
46 | } | ||
47 | textToClipboard = textToClipboard + this.getText(this.application.ninja.selectedElements[j]) + " "; | ||
48 | } | ||
49 | |||
50 | } | ||
51 | //set clipboard data | ||
52 | clipboardEvent.clipboardData.setData('ninja', ''+ JSON.stringify(ninjaClipboardObj)); | ||
53 | clipboardEvent.clipboardData.setData('text/html', '<HTML><BODY>' + htmlToClipboard + '</BODY></HTML>'); | ||
54 | clipboardEvent.clipboardData.setData('text/plain', textToClipboard); | ||
55 | } | ||
56 | } | ||
57 | }, | ||
58 | |||
59 | cut:{ | ||
60 | value:function(clipboardEvent){ | ||
61 | var j=0, htmlToClipboard = "", ninjaClipboardObj = {}, textToClipboard = "", elObj = null; | ||
62 | this.copiedObjects = {}; this.pasteCounter = 0; | ||
63 | this.copiedObjects["cut"] = []; | ||
64 | |||
65 | if(clipboardEvent){ | ||
66 | for(j=0; j < this.application.ninja.selectedElements.length; j++){//copying from stage | ||
67 | elObj = {}; | ||
68 | elObj["outerhtml"] = this.application.ninja.selectedElements[j].outerHTML; | ||
69 | |||
70 | if(this.application.ninja.selectedElements[j].tagName === "CANVAS"){ | ||
71 | elObj["styles"] = this.getDominantStyles(this.application.ninja.selectedElements[j], true); | ||
72 | if(!ninjaClipboardObj.canvas){ | ||
73 | ninjaClipboardObj.canvas = true; | ||
74 | } | ||
75 | elObj["worldJson"] = this.application.ninja.selectedElements[j].elementModel.shapeModel ? this.application.ninja.selectedElements[j].elementModel.shapeModel.GLWorld.exportJSON(): null; | ||
76 | elObj["className"] = this.application.ninja.selectedElements[j].className; | ||
77 | }else{ | ||
78 | elObj["styles"] = this.getDominantStyles(this.application.ninja.selectedElements[j], false); | ||
79 | htmlToClipboard = htmlToClipboard + this.serializeHTMLElement(this.application.ninja.selectedElements[j]); | ||
80 | if(!ninjaClipboardObj.plainHtml){ | ||
81 | ninjaClipboardObj.plainHtml = true; | ||
82 | } | ||
83 | textToClipboard = textToClipboard + this.getText(this.application.ninja.selectedElements[j]) + " "; | ||
84 | } | ||
85 | this.copiedObjects.cut.push(elObj); | ||
86 | } | ||
87 | //set clipboard data | ||
88 | clipboardEvent.clipboardData.setData('ninja', ''+ JSON.stringify(ninjaClipboardObj)); | ||
89 | clipboardEvent.clipboardData.setData('text/html', '<HTML><BODY>' + htmlToClipboard + '</BODY></HTML>'); | ||
90 | clipboardEvent.clipboardData.setData('text/plain', textToClipboard); | ||
91 | |||
92 | } | ||
93 | |||
94 | this.application.ninja.elementMediator.removeElements(this.application.ninja.selectedElements); | ||
95 | |||
96 | clipboardEvent.preventDefault(); | ||
97 | } | ||
98 | }, | ||
99 | |||
100 | pasteInternal:{ | ||
101 | value:function(){ | ||
102 | if(this.copiedObjects.copy){ | ||
103 | try{ | ||
104 | this.pasteFromCopy(); | ||
105 | }catch(e){ | ||
106 | console.log(""+e.stack); | ||
107 | } | ||
108 | } | ||
109 | else if(this.copiedObjects.cut){ | ||
110 | try{ | ||
111 | this.pasteFromCut(); | ||
112 | }catch(e){ | ||
113 | console.log(""+e.stack); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | } | ||
118 | }, | ||
119 | |||
120 | pasteFromCopy:{//todo: change to appropriate name | ||
121 | value:function(){ | ||
122 | var i=0, j=0, | ||
123 | pastedElements = [],//array of te pastes clones - for selection | ||