Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
christianklotz committed Oct 1, 2019
0 parents commit 724ff92
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Contents/Sketch/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const sketch = require("sketch");

function onDocumentChanged(context) {
var changes = context.actionContext;
for (i = 0; i < changes.length; i++) {
var change = changes[i];
var path = change.fullPath();
var type = change.type();

switch (type) {
case 1: // Property change
sketch.UI.message(`Property changed at ${path}`);
break;

case 2: // Deletion
// Objects that got moved in the tree are both deleted from the tree
// and re-added.
if (change.isMove()) break;

sketch.UI.message(`Object deleted at ${path}`);
break;

case 3: // Addition
if (change.isMove()) {
sketch.UI.message(
`Object moved from ${change
.associatedChange()
.fullPath()} to ${path}`
);
} else {
sketch.UI.message(`New object inserted at ${path}`);
}
break;

default:
sketch.UI.message(`⚠️ Unexpected change type ${type}`);
}
}
}
18 changes: 18 additions & 0 deletions Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compatibleVersion": 3,
"bundleVersion": 1,
"identifier": "com.sketch.plugins.document-change-example",
"commands": [
{
"script": "command.js",
"handlers": {
"onDocumentChanged": "onDocumentChanged"
}
}
],
"version": "1.0.0",
"name": "Document Change",
"description": "Sample plugin showcasing how to handle document changes such as object addition, deletions and modifications.",
"author": "Sketch",
"disableCocoaScriptPreprocessor": true
}

0 comments on commit 724ff92

Please sign in to comment.