Skip to content

Commit

Permalink
#2 Rename Selected Items command added.
Browse files Browse the repository at this point in the history
– Commands now have a shortcuts;
– Result message now shows how much instances have been renamed.
  • Loading branch information
exevil committed Oct 25, 2016
1 parent 355a6f0 commit 241a47d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
28 changes: 20 additions & 8 deletions Rename Instances.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@
"author" : "Vyacheslav Dubovitsky",
"commands" : [
{
"script" : "script.cocoascript",
"name" : "Rename Instances",
"handlers" : {
"run" : "onRun"
},
"identifier" : "com.bohemiancoding.sketch.runscriptidentifier"
}
"script" : "script.cocoascript",
"name" : "Rename Selected Instances",
"identifier" : "renameSelected",
"shortcut": "cmd ctrl s",
"handlers" : {
"run" : "renameSelected"
}
},
{
"script" : "script.cocoascript",
"name" : "Rename All Instances",
"identifier" : "renameAll",
"shortcut": "cmd ctrl a",
"handlers" : {
"run" : "renameAll"
}
},

],
"menu" : {
"items" : [
"com.bohemiancoding.sketch.runscriptidentifier"
"renameSelected",
"renameAll"
],
"title" : "Rename Instances"
},
Expand Down
24 changes: 20 additions & 4 deletions Rename Instances.sketchplugin/Contents/Sketch/script.cocoascript
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var onRun = function(context) {
var renameAll = function(context) {

var symbols = NSMutableDictionary.dictionary()
var instances = NSMutableDictionary.dictionary()
Expand All @@ -19,11 +19,27 @@ var onRun = function(context) {
}
}
}
displayResultMessage(context, renamedCount)
}

var renameSelected = function(context) {
var layersLoop = context.selection.objectEnumerator()
var renamedCount = 0

while (item = layersLoop.nextObject()) {
if (item.isMemberOfClass(MSSymbolInstance)) {
item.setName(item.symbolMaster().name())
renamedCount += 1
}
}

log(renamedCount)
displayResultMessage(context, renamedCount)
}

function displayResultMessage(context, renamedCount) {
if (renamedCount > 0) {
context.document.showMessage("All instances names should now be correct")
context.document.showMessage(renamedCount + " instances should now be correct")
} else {
context.document.showMessage("No instances to rename")
}
};
}

0 comments on commit 241a47d

Please sign in to comment.