-
-
Notifications
You must be signed in to change notification settings - Fork 154
/
main.js
57 lines (50 loc) · 1.32 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const { alert, error } = require("./lib/dialogs.js");
var pos_x;
var pos_y;
var node;
var bounds;
function copy(selection) {
if (selection.items.length == 0) {
showAlertCopy()
} else {
bounds = selection.items[0].topLeftInParent;
pos_x = bounds.x;
pos_y = bounds.y;
console.log(pos_y + " , " + pos_x);
}
}
function paste(selection) {
if (pos_x == undefined) {
showAlertPaste()
} else if (selection.items.length == 0) {
showAlertNoSelection()
} else {
let parentCenter = {x: pos_x, y: pos_y};
let nodeTopLeft = {x: 0, y: 0};
var i;
for (i = 0; i < selection.items.length; i++) {
selection.items[i].placeInParentCoordinates(nodeTopLeft, parentCenter);
}
}
}
async function showAlertCopy() {
await alert("No object selected",
"Select an object first before copying its location.");
}
async function showAlertPaste() {
await alert("No saved location",
"First select an object and copy its location (Cmd+Shift+Alt+O) before pasting it to another object.");
}
async function showAlertNoSelection() {
await alert("No objects selected",
"Select an object first to overwrite its location. (Currently saved location: X: " + pos_x + ", Y:" + pos_y + ")");
}
module.exports = {
commands: {
copy: copy,
paste: paste,
showAlertCopy,
showAlertPaste,
showAlertNoSelection
}
};