Skip to content

Commit

Permalink
Display Group Titles will now prefer to use "SFProText-Bold" by
Browse files Browse the repository at this point in the history
default, and if the font doesn't exist, will fall back to
"SFUIText-Bold", or "HelveticaNeue-Bold". Remove Unused Symbols will
now only remove symbols on current page.
  • Loading branch information
Jason Burns committed Sep 27, 2017
1 parent 4462ca1 commit 9d4dca6
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 41 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ To find your plugins directory...

# Changelog

* **13.1** - Display Group Titles will now prefer to use "SFProText-Bold" by default, and if the font doesn't exist, will fall back to "SFUIText-Bold", or "HelveticaNeue-Bold". Remove Unused Symbols will now only remove symbols on current page.
* **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.
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.
17 changes: 15 additions & 2 deletions Symbol Organizer.sketchplugin/Contents/Sketch/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ function removeUnusedSymbols(context,pluginDomain) {
listItemHeight = 24,
count = 0;

var predicate = NSPredicate.predicateWithFormat("isSafeToDelete == 1",pluginDomain),
symbols = context.document.documentData().allSymbols().filteredArrayUsingPredicate(predicate),
var predicate = NSPredicate.predicateWithFormat("className == %@ && isSafeToDelete == 1","MSSymbolMaster",pluginDomain),
symbols = context.document.currentPage().children().filteredArrayUsingPredicate(predicate),
loop = symbols.objectEnumerator(),
symbol;

Expand Down Expand Up @@ -387,3 +387,16 @@ function getExemptSymbols(context,pluginDomain) {

return exemptSymbols;
}

function systemFontExists(fontName) {
var systemFonts = NSFontManager.sharedFontManager().availableFonts(),
loop = systemFonts.objectEnumerator(),
font,
fontExists = false;

while (font = loop.nextObject()) {
if (font == fontName) fontExists = true;
}

return fontExists;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
]
},
"identifier" : "com.sonburn.sketchplugins.symbol-organizer",
"version" : "13.0",
"version" : "13.1",
"description" : "Organize your symbols page, and layer list, alphabetically and into groupings determined by your symbol names.",
"authorEmail" : "[email protected]",
"name" : "Symbol Organizer",
Expand Down
98 changes: 63 additions & 35 deletions Symbol Organizer.sketchplugin/Contents/Sketch/symbol-organizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var strProblemSavingSettings = "Unable to save settings";
// Style variables
var titleStyleName = "Symbol Organizer/Group Title";
var titleStyleFont = {
fontFace : "SF UI Text Bold",
fontFamily : ["SFProText-Bold","SFUIText-Bold","HelveticaNeue-Bold"],
fontFace : "SFProText-Bold",
fontSize : 20,
lineHeight : 24,
textAlignment : 0
Expand Down Expand Up @@ -103,20 +104,37 @@ var symbolOrganizer = function(context,type) {

// If title style does not exist...
if (!titleStyle) {
// System font variable
var systemFontToUse;

// Iterate through family fonts...
for (var i = 0; i < titleStyleFont.fontFamily.length; i++) {
// If a system font has not been determined to exist yet...
if (!systemFontToUse) {
// If this system font exists, set system font variable
if (systemFontExists(titleStyleFont.fontFamily[i])) systemFontToUse = titleStyleFont.fontFamily[i];
}
}

// Update the titleStyleFont object's font face to an existing system font
titleStyleFont.fontFace = systemFontToUse;

// Add title style
titleStyle = addTextStyle(context,titleStyleName,createTextStyle(titleStyleFont));
} else {
// Respect potential for user modified style
var tempLayer = MSTextLayer.new();
tempLayer.setStringValue('Temp');
tempLayer.setName('Temp');
tempLayer.setStyle(titleStyle.newInstance());

titleStyleFont.fontFace = tempLayer.fontPostscriptName();
titleStyleFont.fontSize = tempLayer.fontSize();
titleStyleFont.lineHeight = tempLayer.lineHeight();
titleStyleFont.fontFace = titleStyle.style().textStyle().attributes().NSFont.fontDescriptor().objectForKey(NSFontNameAttribute);
titleStyleFont.fontSize = titleStyle.style().textStyle().attributes().NSFont.fontDescriptor().objectForKey(NSFontSizeAttribute);
titleStyleFont.lineHeight = titleStyle.style().textStyle().attributes().NSParagraphStyle.minimumLineHeight();

// If lineHeight (and thus offset) is 0...
if (titleStyleFont.lineHeight == 0) {
// Apply style to a temporary layer
var tempLayer = MSTextLayer.new();
tempLayer.setStringValue('Temp');
tempLayer.setStyle(titleStyle.newInstance());

// Get temporary layer height and use as offset
offsetHeight = tempLayer.frame().height();
}

Expand Down Expand Up @@ -314,77 +332,87 @@ function getLayoutSettings(context,type) {

// If type is set and equal to "config", operate in config mode...
if (type && type == "config") {
// Establish the alert window
// Layout variables
var groupPadding = 16;

// Create the alert window
var alertWindow = COSAlertWindow.new();

alertWindow.setIcon(NSImage.alloc().initByReferencingFile(context.plugin.urlForResourceNamed("icon.png").path()));
alertWindow.setMessageText(pluginName);

// Grouping options
var groupFrame = NSView.alloc().initWithFrame(NSMakeRect(0,0,300,124));
alertWindow.addAccessoryView(groupFrame);
var groupFrame = NSView.alloc().initWithFrame(NSMakeRect(0,0,300,118+groupPadding));
groupFrame.setFlipped(true);

var groupGranularityLabel = createLabel('Group Definition',12,NSMakeRect(0,108,140,16));
var groupGranularityLabel = createLabel('Group Definition',12,NSMakeRect(0,0,140,16));
groupFrame.addSubview(groupGranularityLabel);

var groupGranularityDescription = createDescription('Symbol Organizer uses a "/" in the name of\neach symbol to determine the grouping. This\nsetting specifies which "/" should be used.',11,NSMakeRect(0,62,300,42));
var groupGranularityDescription = createDescription('Symbol Organizer uses a "/" in the name of each symbol to determine the grouping. This setting specifies which "/" should be used.',11,NSMakeRect(0,20,300,42));
groupFrame.addSubview(groupGranularityDescription);

var groupGranularityValue = createSelect(['1st','2nd','3rd','4th','5th','6th','7th','8th'],defaultSettings.groupDepth,NSMakeRect(0,26,60,28));
var groupGranularityValue = createSelect(['1st','2nd','3rd','4th','5th','6th','7th','8th'],defaultSettings.groupDepth,NSMakeRect(0,70,60,28));
groupFrame.addSubview(groupGranularityValue);

var groupTitlesCheckbox = createCheckbox({name:"Display group titles",value:1},defaultSettings.displayTitles,NSMakeRect(0,0,300,18));
var groupTitlesCheckbox = createCheckbox({name:"Display group titles",value:1},defaultSettings.displayTitles,NSMakeRect(0,108,300,14));
groupFrame.addSubview(groupTitlesCheckbox);

alertWindow.addAccessoryView(groupFrame);

// Layout options
var layoutFrame = NSView.alloc().initWithFrame(NSMakeRect(0,0,300,239));
alertWindow.addAccessoryView(layoutFrame);
var layoutFrame = NSView.alloc().initWithFrame(NSMakeRect(0,0,300,214+groupPadding));
layoutFrame.setFlipped(true);

var layoutDirectionLabel = createLabel('Layout Direction',12,NSMakeRect(0,208,140,16));
var layoutDirectionLabel = createLabel('Layout Direction',12,NSMakeRect(0,0,140,16));
layoutFrame.addSubview(layoutDirectionLabel);

var layoutDirectionValue = createRadioButtons(['Horizontal','Vertical'],defaultSettings.sortDirection,0,0,153);
var layoutDirectionValue = createRadioButtons(['Horizontal','Vertical'],defaultSettings.sortDirection,0,0,24);
layoutFrame.addSubview(layoutDirectionValue);

var layoutHorizontalLabel = createLabel('Horizontal Space',12,NSMakeRect(0,137,140,16));
var layoutHorizontalLabel = createLabel('Horizontal Space',12,NSMakeRect(0,72,140,16));
layoutFrame.addSubview(layoutHorizontalLabel);

var layoutHorizontalValue = createField(defaultSettings.xPad,NSMakeRect(0,110,60,22));
var layoutHorizontalValue = createField(defaultSettings.xPad,NSMakeRect(0,92,60,22));
layoutFrame.addSubview(layoutHorizontalValue);

var layoutVerticalLabel = createLabel('Vertical Space',12,NSMakeRect(0,82,140,16));
var layoutVerticalLabel = createLabel('Vertical Space',12,NSMakeRect(0,122,140,16));
layoutFrame.addSubview(layoutVerticalLabel);

var layoutVerticalValue = createField(defaultSettings.yPad,NSMakeRect(0,55,60,22));
var layoutVerticalValue = createField(defaultSettings.yPad,NSMakeRect(0,142,60,22));
layoutFrame.addSubview(layoutVerticalValue);

var layoutMaxLabel = createLabel('Max Per Row/Column',12,NSMakeRect(0,27,140,16));
var layoutMaxLabel = createLabel('Max Per Row/Column',12,NSMakeRect(0,172,140,16));
layoutFrame.addSubview(layoutMaxLabel);

var layoutMaxValue = createField(defaultSettings.maxPer,NSMakeRect(0,0,60,22));
var layoutMaxValue = createField(defaultSettings.maxPer,NSMakeRect(0,192,60,22));
layoutFrame.addSubview(layoutMaxValue);

alertWindow.addAccessoryView(layoutFrame);

// Other options
var otherFrame = NSView.alloc().initWithFrame(NSMakeRect(0,0,300,161));
alertWindow.addAccessoryView(otherFrame);
var otherFrame = NSView.alloc().initWithFrame(NSMakeRect(0,0,300,138));
otherFrame.setFlipped(true);

var reverseOrderCheckbox = createCheckbox({name:"Reverse layer list sort order",value:1},defaultSettings.reverseOrder,NSMakeRect(0,126,300,18));
var reverseOrderCheckbox = createCheckbox({name:"Reverse layer list sort order",value:1},defaultSettings.reverseOrder,NSMakeRect(0,0,300,14));
otherFrame.addSubview(reverseOrderCheckbox);

var renameSymbolsCheckbox = createCheckbox({name:"Sequentially number duplicate symbols",value:1},defaultSettings.renameSymbols,NSMakeRect(0,98,300,18));
var renameSymbolsCheckbox = createCheckbox({name:"Sequentially number duplicate symbols",value:1},defaultSettings.renameSymbols,NSMakeRect(0,26,300,14));
otherFrame.addSubview(renameSymbolsCheckbox);

var gatherSymbolsCheckbox = createCheckbox({name:"Gather symbols from other pages",value:1},defaultSettings.gatherSymbols,NSMakeRect(0,70,300,18));
var gatherSymbolsCheckbox = createCheckbox({name:"Gather symbols from other pages",value:1},defaultSettings.gatherSymbols,NSMakeRect(0,52,300,14));
otherFrame.addSubview(gatherSymbolsCheckbox);

var removeSymbolsCheckbox = createCheckbox({name:"Remove unused symbols",value:1},defaultSettings.removeSymbols,NSMakeRect(0,42,300,18));
var removeSymbolsCheckbox = createCheckbox({name:"Remove unused symbols on page",value:1},defaultSettings.removeSymbols,NSMakeRect(0,78,300,14));
otherFrame.addSubview(removeSymbolsCheckbox);

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));
var removeSymbolsDescription = createDescription('Presents a checklist of unused symbols for your confirmation. Symbols which are nested in other symbols, or used as overrides, will be ignored.',11,NSMakeRect(18,96,282,42));
otherFrame.addSubview(removeSymbolsDescription);

alertWindow.addAccessoryView(otherFrame);

// Buttons
alertWindow.addButtonWithTitle('OK');
alertWindow.addButtonWithTitle('Cancel');
alertWindow.addButtonWithTitle("OK");
alertWindow.addButtonWithTitle("Cancel");

// Set key order and first responder
setKeyOrder(alertWindow,[
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 13.0</title>
<title>Version 13.1</title>
<description>
<![CDATA[
<ul>
<li>Remove Unused Symbols will now present checklist of removal candidates, requiring the user to review and confirm.</li>
<li>Display Group Titles will now prefer to use "SFProText-Bold" by default, and if the font doesn't exist, will fall back to "SFUIText-Bold", or "HelveticaNeue-Bold". Remove Unused Symbols will now only remove symbols on current page.</li>
</ul>
]]>
</description>
<enclosure url="https://github.com/sonburn/symbol-organizer/archive/master.zip" sparkle:version="13.0" />
<enclosure url="https://github.com/sonburn/symbol-organizer/archive/master.zip" sparkle:version="13.1" />
</item>
</channel>
</rss>

0 comments on commit 9d4dca6

Please sign in to comment.