Kaynağa Gözat

Add deletion and duplication of selection

dev_h
Finn Krein 4 yıl önce
ebeveyn
işleme
6b4ec13a0f

+ 17
- 0
client-data/tools/hand/delete.svg Dosyayı Görüntüle

1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<svg role="img" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
3
+ <title>Instagram icon</title>
4
+ <g transform="matrix(2.3668 2.3668 -2.3668 2.3668 13.98 -131.11)" fill="#ff002d">
5
+  <g transform="translate(-.5821 .16648)" fill="#f00">
6
+   <rect transform="scale(1,-1)" x="30.056" y="-33.755" width=".6819" height="6.5387" ry=".34186"/>
7
+   <rect transform="matrix(0,1,1,0,0,0)" x="30.145" y="27.128" width=".6819" height="6.5387" ry=".34186"/>
8
+  </g>
9
+ </g>
10
+ <metadata>
11
+  <rdf:RDF>
12
+   <cc:Work rdf:about="">
13
+    <dc:title>Delete icon</dc:title>
14
+   </cc:Work>
15
+  </rdf:RDF>
16
+ </metadata>
17
+</svg>

+ 17
- 0
client-data/tools/hand/duplicate.svg Dosyayı Görüntüle

1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<svg role="img" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
3
+ <title>Instagram icon</title>
4
+ <path d="m7.1549 7.1542v-3.5315c0-0.65725 0.52912-1.1864 1.1864-1.1864h11.991c0.65725 0 1.1864 0.52912 1.1864 1.1864v12.036c0 0.65725-0.52912 1.1864-1.1864 1.1864h-3.4867" fill="none" stroke="#000" stroke-linejoin="round" stroke-width=".3"/>
5
+ <rect x="2.481" y="7.155" width="14.364" height="14.409" ry="1.1864" fill="none" stroke="#000" stroke-linejoin="round" stroke-width=".3"/>
6
+ <g transform="translate(-20.734 -16.126)">
7
+  <rect transform="scale(1,-1)" x="30.056" y="-33.755" width=".6819" height="6.5387" ry=".34186"/>
8
+  <rect transform="matrix(0,1,1,0,0,0)" x="30.145" y="27.128" width=".6819" height="6.5387" ry=".34186"/>
9
+ </g>
10
+ <metadata>
11
+  <rdf:RDF>
12
+   <cc:Work rdf:about="">
13
+    <dc:title>Duplicate icon</dc:title>
14
+   </cc:Work>
15
+  </rdf:RDF>
16
+ </metadata>
17
+</svg>

+ 63
- 0
client-data/tools/hand/hand.js Dosyayı Görüntüle

55
 		return target || el;
55
 		return target || el;
56
 	}
56
 	}
57
 
57
 
58
+	function deleteSelection() {
59
+		var msgs = selected_els.map(function(el) {
60
+                return ({
61
+                    "type": "delete",
62
+                    "id": el.id
63
+                });
64
+            });
65
+		var data = {
66
+			_children: msgs
67
+		}
68
+		Tools.drawAndSend(data);
69
+		selected_els = [];
70
+	}
71
+
72
+	function duplicateSelection() {
73
+		if (!(selectorState == selectorStates.pointing)
74
+			|| (selected_els.length == 0)) return;
75
+		var msgs = [];
76
+		var newids = [];
77
+		for (var i=0; i<selected_els.length; i++) {
78
+			var id = selected_els[i].id;
79
+			msgs[i] = {
80
+				type: "copy",
81
+				id: id,
82
+				newid: Tools.generateUID(id[0])
83
+			};
84
+			newids[i] = id;
85
+		}
86
+		Tools.drawAndSend({_children: msgs});
87
+		selected_els = newids.map(function(id) {
88
+                return Tools.svg.getElementById(id);
89
+            });
90
+	}
91
+
58
 	function createSelectorRect() {
92
 	function createSelectorRect() {
59
 		var shape = Tools.createSVGElement("rect");
93
 		var shape = Tools.createSVGElement("rect");
60
 		shape.id = "selectionRect";
94
 		shape.id = "selectionRect";
181
 					tmatrix.e = data.deltax || 0;
215
 					tmatrix.e = data.deltax || 0;
182
 					tmatrix.f = data.deltay || 0;
216
 					tmatrix.f = data.deltay || 0;
183
 					break;
217
 					break;
218
+				case "copy":
219
+					var newElement = Tools.svg.getElementById(data.id).cloneNode(true);
220
+					newElement.id = data.newid;
221
+					Tools.drawingArea.appendChild(newElement);
222
+				    break;
223
+				case "delete":
224
+					data.tool = "Eraser";
225
+					messageForTool(data);
226
+					break;
184
 				default:
227
 				default:
185
 					throw new Error("Mover: 'move' instruction with unknown type. ", data);
228
 					throw new Error("Mover: 'move' instruction with unknown type. ", data);
186
 			}
229
 			}
251
 		selected = null;
294
 		selected = null;
252
 	}
295
 	}
253
 
296
 
297
+	function deleteShortcut(e) {
298
+		if (e.key == "Delete" &&
299
+			!e.target.matches("input[type=text], textarea"))
300
+			deleteSelection();
301
+	}
302
+
303
+	function duplicateShortcut(e) {
304
+		if (e.key == "d" &&
305
+			!e.target.matches("input[type=text], textarea"))
306
+			duplicateSelection();
307
+	}
308
+
254
 	function switchTool() {
309
 	function switchTool() {
255
 		selected = null;
310
 		selected = null;
311
+		if (handTool.secondary.active) {
312
+			window.addEventListener("keydown", deleteShortcut);
313
+			window.addEventListener("keydown", duplicateShortcut);
314
+		}
315
+		else {
316
+			window.removeEventListener("keydown", deleteShortcut);
317
+			window.removeEventListener("keydown", duplicateShortcut);
318
+		}
256
 	}
319
 	}
257
 
320
 
258
 	var handTool = { //The new tool
321
 	var handTool = { //The new tool

+ 25
- 0
server/boardData.js Dosyayı Görüntüle

100
     this.delaySave();
100
     this.delaySave();
101
   }
101
   }
102
 
102
 
103
+  /** Copy elements in the board
104
+   * @param {string} id - Identifier of the data to copy.
105
+   * @param {BoardElem} data - Object containing the id of the new copied element.
106
+   */
107
+  copy(id, data) {
108
+    var obj = this.board[id];
109
+    var newid = data.newid;
110
+    if (obj) {
111
+      var newobj = JSON.parse(JSON.stringify(obj));
112
+      newobj.id = newid;
113
+      if (newobj._children) {
114
+	for (var child of newobj._children) {
115
+	    child.parent = newid;
116
+	}
117
+      }
118
+      this.board[newid] = newobj;
119
+    } else  {
120
+      log("Copied object does not exist in board.", {object: id});
121
+    }
122
+    this.delaySave();
123
+  }
124
+
103
   /** Removes data from the board
125
   /** Removes data from the board
104
    * @param {string} id - Identifier of the data to delete.
126
    * @param {string} id - Identifier of the data to delete.
105
    */
127
    */
137
       case "update":
159
       case "update":
138
         if (id) this.update(id, message);
160
         if (id) this.update(id, message);
139
         break;
161
         break;
162
+      case "copy":
163
+        if (id) this.copy(id, message);
164
+        break;
140
       case "child":
165
       case "child":
141
         this.addChild(message.parent, message);
166
         this.addChild(message.parent, message);
142
         break;
167
         break;

Loading…
İptal
Kaydet