From eb9cf3f9e735faf550337a72a7d1efaf61724cb6 Mon Sep 17 00:00:00 2001 From: Francesco Bertocci Date: Fri, 9 Mar 2018 15:58:47 -0500 Subject: [PATCH] changed behavior so now symbol instances are renamed to the portion after the last '/' of the master symbol name --- README.md | 1 + .../Contents/Sketch/manifest.json | 13 ++++++++++-- .../Contents/Sketch/script.cocoascript | 20 +++++++++++++++++-- appcast.xml | 4 ++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 35dd93f..0c5f3e7 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ To find your plugins directory... # Changelog +* **2.4.1** - Now all instances of symbol(s) are renamed to last to portion after last '/'. * **2.4** - Added new function to rename all instances of selected symbol(s). * **2.3** - Added new function to rename all instances on all pages, except Symbols page. Added fix for when the master for an instance is missing. * **2.2** - Added appcast plugin support for Sketch 45 and later. Added new function to rename all instances on current page. New shortcuts. diff --git a/Symbol Instance Renamer.sketchplugin/Contents/Sketch/manifest.json b/Symbol Instance Renamer.sketchplugin/Contents/Sketch/manifest.json index 61dbcbd..038dc03 100644 --- a/Symbol Instance Renamer.sketchplugin/Contents/Sketch/manifest.json +++ b/Symbol Instance Renamer.sketchplugin/Contents/Sketch/manifest.json @@ -10,6 +10,15 @@ "icon" : "icon-sr.png", "handler" : "renamePages" }, + { + "name" : "Rename All Instances of Selected Symbol(s) to Portion After Last '/'", + "shortcut" : "cmd option shift k", + "identifier" : "renamePages", + "description" : "Rename All Instances of Selected Symbol(s) to Portion After Last '/'", + "script" : "script.cocoascript", + "icon" : "icon-sr.png", + "handler" : "renameLastSlashPages" + }, { "name" : "Rename All Instances on All Pages (Except Symbols Page)", "shortcut" : "cmd option shift x", @@ -58,8 +67,8 @@ ] }, "identifier" : "com.sonburn.sketchplugins.symbol-instance-renamer", - "version" : "2.4", - "description" : "Rename symbol instances to the name of their master.", + "version" : "2.4.1", + "description" : "Rename symbol instances to the name of their master (Last portion after "/").", "authorEmail" : "jason.burns@synchronoss.com", "name" : "Symbol Instance Renamer", "appcast" : "https://raw.githubusercontent.com/sonburn/symbol-instance-renamer/master/appcast.xml" diff --git a/Symbol Instance Renamer.sketchplugin/Contents/Sketch/script.cocoascript b/Symbol Instance Renamer.sketchplugin/Contents/Sketch/script.cocoascript index 872f0a5..affd134 100644 --- a/Symbol Instance Renamer.sketchplugin/Contents/Sketch/script.cocoascript +++ b/Symbol Instance Renamer.sketchplugin/Contents/Sketch/script.cocoascript @@ -16,6 +16,19 @@ var renamePages = function(context) { context.document.showMessage(count + strRenameSuccess); } +var renameLastSlashPages = function(context) { + var pages = context.document.pages(), + loop = pages.objectEnumerator(), + page, + count = 0; + + while (page = loop.nextObject()) { + count = count + renameInstancesOnPage(page); + } + + context.document.showMessage(count + strRenameSuccess); +} + var renamePagesExceptSymbols = function(context) { var pages = context.document.pages(), loop = pages.objectEnumerator(), @@ -94,8 +107,11 @@ function renameInstancesOnPage(page) { } function renameInstance(instance) { - if (instance.name() != instance.symbolMaster().name().trim()) { - instance.setName(instance.symbolMaster().name()); + var str = instance.symbolMaster().name().trim(); + var str_array = str.split("/"); + var simple_name = str_array[str_array.length - 1]; + if (instance.name() != simple_name.trim()) { + instance.setName(simple_name); return true; } else return false; } diff --git a/appcast.xml b/appcast.xml index f853343..eed3aee 100644 --- a/appcast.xml +++ b/appcast.xml @@ -6,11 +6,11 @@ Rename all symbol instances to the name of their master. en - Version 2.4 + Version 2.4.1 -
  • Added new function to rename all instances of selected symbol(s).
  • +
  • Added new function to rename all instances of selected symbol(s) to portion after last '/'.
  • ]]>