Skip to content

Commit

Permalink
Added new Group Space feature and improved appearance of settings
Browse files Browse the repository at this point in the history
window. Improved sorting and grouping; group title case will now be
ignored, and group titles which are numbers will now sort properly.
  • Loading branch information
Jason Burns committed Oct 11, 2017
1 parent 9d4dca6 commit 1fca97f
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 151 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

* **14.0** - Added new Group Space feature and improved appearance of settings window. Improved sorting and grouping; group title case will now be ignored, and group titles which are numbers will now sort properly.
* **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.
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.
150 changes: 94 additions & 56 deletions Symbol Organizer.sketchplugin/Contents/Sketch/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,92 +35,102 @@ function createTextStyle(styleData) {
}

function createSelect(items,selectedItemIndex,frame) {
selectedItemIndex = (selectedItemIndex > -1) ? selectedItemIndex : 0;
var comboBox = [[NSComboBox alloc] initWithFrame:frame];
[comboBox addItemsWithObjectValues:items];
[comboBox selectItemAtIndex:selectedItemIndex];
var comboBox = NSComboBox.alloc().initWithFrame(frame),
selectedItemIndex = (selectedItemIndex > -1) ? selectedItemIndex : 0;

comboBox.addItemsWithObjectValues(items);
comboBox.selectItemAtIndex(selectedItemIndex);

return comboBox;
}

function createRadioButtons(options,selected,format,x,y) {
// Set number of rows and columns
if (!format || format == 0) {
var rows = options.length;
var columns = 1;
var buttonMatrixWidth = 300;
var buttonCellWidth = buttonMatrixWidth;
} else {
var rows = options.length / 2;
var columns = 2;
var buttonMatrixWidth = 300;
var buttonCellWidth = buttonMatrixWidth / columns;
var rows = options.length,
columns = 1,
buttonMatrixWidth = 300,
buttonCellWidth = buttonMatrixWidth,
x = (x) ? x : 0,
y = (y) ? y : 0;

if (format && format != 0) {
rows = options.length / 2;
columns = 2;
buttonMatrixWidth = 300;
buttonCellWidth = buttonMatrixWidth / columns;
}

var x = (x) ? x : 0;
var y = (y) ? y : 0;
var buttonCell = NSButtonCell.alloc().init();

buttonCell.setButtonType(NSRadioButton);

// Make a prototype cell
var buttonCell = [[NSButtonCell alloc] init];
[buttonCell setButtonType:NSRadioButton]
var buttonMatrix = NSMatrix.alloc().initWithFrame_mode_prototype_numberOfRows_numberOfColumns(
NSMakeRect(x,y,buttonMatrixWidth,rows*20),
NSRadioModeMatrix,
buttonCell,
rows,
columns
);

// Make a matrix to contain the radio cells
var buttonMatrix = [[NSMatrix alloc] initWithFrame: NSMakeRect(x,y,buttonMatrixWidth,rows*25) mode:NSRadioModeMatrix prototype:buttonCell numberOfRows:rows numberOfColumns:columns];
[buttonMatrix setCellSize: NSMakeSize(buttonCellWidth,20)];
buttonMatrix.setCellSize(NSMakeSize(buttonCellWidth,20));

// Create a cell for each option
for (i = 0; i < options.length; i++) {
[[[buttonMatrix cells] objectAtIndex: i] setTitle: options[i]];
[[[buttonMatrix cells] objectAtIndex: i] setTag: i];
buttonMatrix.cells().objectAtIndex(i).setTitle(options[i]);
buttonMatrix.cells().objectAtIndex(i).setTag(i);
}

// Select the default cell
[buttonMatrix selectCellAtRow:selected column:0]
buttonMatrix.selectCellAtRow_column(selected,0);

// Return the matrix
return buttonMatrix;
}

function createField(value,frame) {
var field = [[NSTextField alloc] initWithFrame:frame];
[field setStringValue:value];
var field = NSTextField.alloc().initWithFrame(frame);

field.setStringValue(value);

return field;
}

function createLabel(text,size,frame) {
var label = [[NSTextField alloc] initWithFrame:frame];
[label setStringValue:text];
[label setFont:[NSFont boldSystemFontOfSize:size]];
[label setBezeled:false];
[label setDrawsBackground:false];
[label setEditable:false];
[label setSelectable:false];
var label = NSTextField.alloc().initWithFrame(frame);

label.setStringValue(text);
label.setFont(NSFont.boldSystemFontOfSize(size));
label.setBezeled(false);
label.setDrawsBackground(false);
label.setEditable(false);
label.setSelectable(false);

return label;
}

function createDescription(text,size,frame) {
var label = [[NSTextField alloc] initWithFrame:frame];
[label setStringValue:text];
[label setFont:[NSFont systemFontOfSize:size]];
[label setTextColor:[NSColor colorWithCalibratedRed:(0/255) green:(0/255) blue:(0/255) alpha:0.6]];
[label setBezeled:false];
[label setDrawsBackground:false];
[label setEditable:false];
[label setSelectable:false];
function createDescription(text,size,frame,alpha) {
var label = NSTextField.alloc().initWithFrame(frame),
alpha = (alpha) ? alpha : 0.6;

label.setStringValue(text);
label.setFont(NSFont.systemFontOfSize(size));
label.setTextColor(NSColor.colorWithCalibratedRed_green_blue_alpha(0/255,0/255,0/255,alpha));
label.setBezeled(false);
label.setDrawsBackground(false);
label.setEditable(false);
label.setSelectable(false);

return label;
}

function createCheckbox(item,flag,frame) {
flag = ( flag == false ) ? NSOffState : NSOnState;
var checkbox = [[NSButton alloc] initWithFrame:frame];
[checkbox setButtonType: NSSwitchButton];
[checkbox setBezelStyle: 0];
[checkbox setTitle: item.name];
[checkbox setTag: item.value];
[checkbox setState: flag];
var checkbox = NSButton.alloc().initWithFrame(frame),
flag = (flag == false) ? NSOffState : NSOnState;

checkbox.setButtonType(NSSwitchButton);
checkbox.setBezelStyle(0);
checkbox.setTitle(item.name);
checkbox.setTag(item.value);
checkbox.setState(flag);

return checkbox;
}
Expand Down Expand Up @@ -200,13 +210,13 @@ function renameDuplicateSymbols(symbols) {

function setKeyOrder(alert,order) {
for (var i = 0; i < order.length; i++) {
var thisItem = order[i];
var nextItem = order[i+1];
var thisItem = order[i],
nextItem = order[i+1];

if (nextItem) thisItem.setNextKeyView(nextItem);
}

alert.alert().window().setInitialFirstResponder(order[0]);
alert.window().setInitialFirstResponder(order[0]);
}

function createGroupObject(symbols,depth) {
Expand Down Expand Up @@ -237,7 +247,7 @@ function createGroupObject(symbols,depth) {
// If no symbol group has been set yet...
if (symbolGroup == 0) {
// Set symbol group if a match was found
if (groupLayout[key]['prefix'] == groupPrefix) symbolGroup = groupLayout[key]['group'];
if (groupLayout[key]['prefix'].toLowerCase() == groupPrefix.toLowerCase()) symbolGroup = groupLayout[key]['group'];
}
}

Expand Down Expand Up @@ -295,7 +305,7 @@ function removeUnusedSymbols(context,pluginDomain) {
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...");
alertWindow.setInformativeText("The following symbols appear to be unused. Symbols which are nested in other symbols, or used as overrides, were ignored.");

var symbolListInnerFrameHeight = listItemHeight * (removeSymbols.length),
symbolListFrame = NSScrollView.alloc().initWithFrame(NSMakeRect(0,0,300,200)),
Expand Down Expand Up @@ -400,3 +410,31 @@ function systemFontExists(fontName) {

return fontExists;
}

function createDivider(frame) {
var divider = NSView.alloc().initWithFrame(frame);

divider.setWantsLayer(1);
divider.layer().setBackgroundColor(CGColorCreateGenericRGB(204/255,204/255,204/255,1.0));

return divider;
}

function sortSymbolsByName(a,b) {
var match = /([^a-zA-Z0-9])|([0-9]+)|([a-zA-Z]+)/g,
ax = [],
bx = [];

a.name().replace(match,function(_,$1,$2,$3) { ax.push([$1 || "", $2 || Infinity, $3 || "0"])});
b.name().replace(match,function(_,$1,$2,$3) { bx.push([$1 || "", $2 || Infinity, $3 || "0"])});

while (ax.length && bx.length) {
var an = ax.shift(),
bn = bx.shift(),
nn = an[0].localeCompare(bn[0]) || (an[1] - bn[1]) || an[2].localeCompare(bn[2]);

if (nn) return nn;
}

return ax.length - bx.length;
}
14 changes: 7 additions & 7 deletions Symbol Organizer.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@
"commands" : [
{
"name" : "Configure Symbol Organizer",
"shortcut": "cmd option shift o",
"shortcut" : "cmd option shift o",
"identifier" : "symbol-organizer-config",
"description" : "Configure and run Symbol Organizer.",
"script" : "symbol-organizer.js",
"script" : "script.cocoascript",
"icon" : "icon-sr.png",
"handler" : "config"
},
{
"name" : "Run Symbol Organizer",
"shortcut": "cmd option control o",
"shortcut" : "cmd option control o",
"identifier" : "symbol-organizer-run",
"description" : "Run Symbol Organizer using last settings.",
"script" : "symbol-organizer.js",
"script" : "script.cocoascript",
"icon" : "icon-sr.png",
"handler" : "run"
}
],
"menu" : {
"title": "Symbol Organizer",
"items": [
"title" : "Symbol Organizer",
"items" : [
"symbol-organizer-config",
"symbol-organizer-run"
]
},
"identifier" : "com.sonburn.sketchplugins.symbol-organizer",
"version" : "13.1",
"version" : "14.0",
"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
Loading

0 comments on commit 1fca97f

Please sign in to comment.