Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from awt2542/master
Browse files Browse the repository at this point in the history
Improved prompt text
  • Loading branch information
rodi01 committed Feb 17, 2014
2 parents 661cfc3 + 6477c86 commit 5159dbb
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Rename It.sketchplugin
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ function rename(layerName, currIdx, width, height) {
newLayerName = newLayerName.substr(0, per) + interStr + newLayerName.substr(per + 1 + interSize);
}

// Add to current name
if (newLayerName[0] == "+")
newLayerName = layerName + basename.substring(1);
// Add to current name
if (newLayerName[0] == "+")
newLayerName = layerName + basename.substring(1);

// Wild Card Selector
var wildCard = newLayerName.search("\\*");
if (wildCard != -1)
newLayerName = newLayerName.substr(0, wildCard) + layerName + newLayerName.substr(wildCard + 1);
// Wild Card Selector
var wildCard = newLayerName.search("\\*");
if (wildCard != -1)
newLayerName = newLayerName.substr(0, wildCard) + layerName + newLayerName.substr(wildCard + 1);

// Add Width and/or height
// Props to GU5TAF (https://github.com/rodi01/RenameIt/issues/1)
newLayerName = newLayerName.replace(new RegExp("%w", "ig"), width);
newLayerName = newLayerName.replace(new RegExp("%h", "ig"), height);
// Add Width and/or height
// Props to GU5TAF (https://github.com/rodi01/RenameIt/issues/1)
newLayerName = newLayerName.replace(new RegExp("%w", "ig"), width);
newLayerName = newLayerName.replace(new RegExp("%h", "ig"), height);

// Return new name
return newLayerName;
}
// Return new name
return newLayerName;
}

// Run
if (selection.length() > 0)
{
// Show dialog
var basename = [doc askForUserInput:'Rename Layer(s): eg. Item %N, Item %W, Item %H' initialValue:'Layer'].toString();
var basename = [doc askForUserInput:'Number %N | Width %W | Height %H | + Add' initialValue:'New name(s)'].toString();

// Run on all selections
for (var i=0; i<selection.length(); i++) {
Expand All @@ -65,6 +65,9 @@ if (selection.length() > 0)
height = [frame height];
var name = rename([layer name], i, width, height);
[layer setName:name];

// Success message
[doc showMessage: "Rename it: Updated "+selection.length()+" layer(s)"];
}
}
else
Expand Down

0 comments on commit 5159dbb

Please sign in to comment.