Skip to content

Commit

Permalink
Remove Unused Symbols will now present checklist of removal candidates,
Browse files Browse the repository at this point in the history
requiring the user to review and confirm.
  • Loading branch information
Jason Burns committed Sep 27, 2017
1 parent 26aeca8 commit 4462ca1
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ To find your plugins directory...

# Changelog

* **13.0** - Remove Unused Symbols will now present checklist of removal candidates, requiring the user to review and confirm.
* **12.8** - Another attempt to ensure all/only unused symbols are removed.
* **12.7** - Fix for duplicate groups when alphabetical sorting and multiple depths confuses group definition.
* **12.6** - Fix to only gather local symbols in Sketch 47.
* **12.5** - Simplified code, and implemented enhancement to trim whitespace when generating groups (does not affect alphabetic sorting).
* **12.4** - Fix for titles becoming misaligned when Layout Direction is set to vertical and Symbol Organizer is used in Run mode.
* **12.3** - Added back symbol override protections, as it seems the isSafeToDelete function of MSSymbolMaster has a bug with nested nested symbols. Also fixed a feedback bug, for when Remove Unused Symbols would correctly leave no symbols remaining on the symbols page (would incorrectly state "There are no symbols to organize on this page").
* **12.2** - Fixed (another) issue for when Symbol Organizer is being used on a brand new document, which has no stored settings of any kind (was referring to stored settings to migrate old Symbol Organizer settings to new plugin identifier).
* **12.1** - Fixed issue for when Symbol Organizer is being used on a brand new document, which has no stored settings of any kind (was referring to stored settings to migrate old Symbol Organizer settings to new plugin identifier).
Expand Down
Binary file modified Screenshots/Symbol Organizer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 56 additions & 11 deletions Symbol Organizer.sketchplugin/Contents/Sketch/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,67 @@ function sortLayerList(symbols,output) {
}

function removeUnusedSymbols(context,pluginDomain) {
var symbols = context.document.documentData().allSymbols().filteredArrayUsingPredicate(NSPredicate.predicateWithFormat("isSafeToDelete == 1",pluginDomain));
var loop = symbols.objectEnumerator(), symbol;

var exemptSymbols = getExemptSymbols(context,pluginDomain);
var exemptSymbols = getExemptSymbols(context,pluginDomain),
removeSymbols = [],
listItemHeight = 24,
count = 0;

var count = 0;
var predicate = NSPredicate.predicateWithFormat("isSafeToDelete == 1",pluginDomain),
symbols = context.document.documentData().allSymbols().filteredArrayUsingPredicate(predicate),
loop = symbols.objectEnumerator(),
symbol;

while (symbol = loop.nextObject()) {
if (exemptSymbols.indexOf(String(symbol.symbolID())) == -1) {
symbol.removeFromParent();
log(symbol.name() + " was removed by Symbol Organizer");
count++;
}
if (exemptSymbols.indexOf(String(symbol.symbolID())) == -1) removeSymbols.push(symbol);
}

var alertWindow = COSAlertWindow.new();
alertWindow.setIcon(NSImage.alloc().initByReferencingFile(context.plugin.urlForResourceNamed("icon.png").path()));
alertWindow.setMessageText("Remove Unused Symbols");

alertWindow.addTextLabelWithValue("The following symbols appear to be unused...");

var symbolListInnerFrameHeight = listItemHeight * (removeSymbols.length),
symbolListFrame = NSScrollView.alloc().initWithFrame(NSMakeRect(0,0,300,200)),
symbolListFrameSize = symbolListFrame.contentSize(),
symbolListInnerFrame = NSView.alloc().initWithFrame(NSMakeRect(0,0,symbolListFrameSize.width,symbolListInnerFrameHeight));

symbolListFrame.setHasVerticalScroller(true);
symbolListInnerFrame.setFlipped(true);
symbolListFrame.setDocumentView(symbolListInnerFrame);

for (var i = 0; i < removeSymbols.length; i++) {
symbolListInnerFrame.addSubview(createCheckbox({name:removeSymbols[i].name(),value:i},1,NSMakeRect(0,listItemHeight*count,300,listItemHeight)));
count++;
}

return count;
symbolListInnerFrame.scrollPoint(NSMakePoint(0,0));

alertWindow.addAccessoryView(symbolListFrame);

alertWindow.addButtonWithTitle("Remove Selected");
alertWindow.addButtonWithTitle("Keep All");

var responseCode = alertWindow.runModal();

if (responseCode == 1000) {
var symbolsToRemove = [];

for (var i = 0; i < removeSymbols.length; i++) {
if ([symbolListInnerFrame subviews][i].state() == 1) symbolsToRemove.push([symbolListInnerFrame subviews][i].tag());
}

for (var i = 0; i < symbolsToRemove.length; i++) {
var symbolIndex = symbolsToRemove[i],
symbolToRemove = removeSymbols[symbolIndex];

symbolToRemove.removeFromParent();

log(symbolToRemove.name() + " was removed by Symbol Organizer");
}

return symbolsToRemove.length;
} else return false;
}

function getExemptSymbols(context,pluginDomain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
]
},
"identifier" : "com.sonburn.sketchplugins.symbol-organizer",
"version" : "12.8",
"version" : "13.0",
"description" : "Organize your symbols page, and layer list, alphabetically and into groupings determined by your symbol names.",
"authorEmail" : "jason.burns@synchronoss.com",
"name" : "Symbol Organizer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ function getLayoutSettings(context,type) {
var removeSymbolsCheckbox = createCheckbox({name:"Remove unused symbols",value:1},defaultSettings.removeSymbols,NSMakeRect(0,42,300,18));
otherFrame.addSubview(removeSymbolsCheckbox);

var removeSymbolsDescription = createDescription('Removes unused symbols in your document.\nSymbols which are nested in other symbols, or\nused as overrides, will NOT be removed.',11,NSMakeRect(18,0,282,42));
var removeSymbolsDescription = createDescription('Presents a checklist of unused symbols for your\nconfirmation. Symbols which are nested in other\nsymbols, or used as overrides, will be ignored.',11,NSMakeRect(18,0,282,42));
otherFrame.addSubview(removeSymbolsDescription);

// Buttons
Expand Down
6 changes: 3 additions & 3 deletions appcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<description>Organize your symbols page, and layer list, alphabetically and into groupings determined by your symbol names.</description>
<language>en</language>
<item>
<title>Version 12.8</title>
<title>Version 13.0</title>
<description>
<![CDATA[
<ul>
<li>Another attempt to ensure all/only unused symbols are removed.</li>
<li>Remove Unused Symbols will now present checklist of removal candidates, requiring the user to review and confirm.</li>
</ul>
]]>
</description>
<enclosure url="https://github.com/sonburn/symbol-organizer/archive/master.zip" sparkle:version="12.8" />
<enclosure url="https://github.com/sonburn/symbol-organizer/archive/master.zip" sparkle:version="13.0" />
</item>
</channel>
</rss>

0 comments on commit 4462ca1

Please sign in to comment.