-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 724ff92
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |