Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kiny authored and kiny committed Dec 5, 2015
1 parent ab3cf37 commit b1ad7b7
Show file tree
Hide file tree
Showing 17 changed files with 555 additions and 108 deletions.
23 changes: 0 additions & 23 deletions Hidden & UnHidden/Hidden Other Layers.sketchplugin

This file was deleted.

20 changes: 0 additions & 20 deletions Hidden & UnHidden/Unhidden All Layers.sketchplugin

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Some handy tools for Sketch

##Installing Plugins

1. [Download the ZIP file](https://github.com/webpatch/Handy-Tools/archive/master.zip)
2. Extract the files to the plugin folder (Open up Sketch, and go to Plugins › Reveal Plugins Folder… to open it.)
1. [Download the ZIP file](https://github.com/webpatch/Handy-Tools/release/HandyTools.sketchplugin.zip)
2. Extract the files, dobule click the "HandyTools.sketchplugin", it will install automatic.
3. You can find these tools in Sketch's "plugins" menu

## Feature
Expand Down
Binary file added release/HandyTools.sketchplugin.zip
Binary file not shown.
1 change: 1 addition & 0 deletions src/Contents/Sketch/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Contents/Sketch/.idea/Sketch.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Contents/Sketch/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/Contents/Sketch/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Contents/Sketch/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

317 changes: 317 additions & 0 deletions src/Contents/Sketch/.idea/workspace.xml

Large diffs are not rendered by default.

60 changes: 33 additions & 27 deletions Align To....sketchplugin → src/Contents/Sketch/algin.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import 'libs/common.js'
@import 'libs/common.js'

var lastDir = getConfig('last_algin_dir');
lastDir = lastDir == null ? 1 : parseInt(lastDir)
lastDir = lastDir == null ? 1 : parseInt(lastDir);

function disableCell(cell)
{
Expand All @@ -20,7 +20,7 @@ function qq(cellArr,idxArr,call)

function createAlert(msg, items, selectedItemIndex)
{
selectedItemIndex = selectedItemIndex || 0
selectedItemIndex = selectedItemIndex || 0;
var viewBox = [[NSBox alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
[viewBox setTitle:""];
[viewBox setTransparent:true];
Expand Down Expand Up @@ -134,7 +134,7 @@ var fnObj = {
}
}

function getSeletedLayersName()
function getSeletedLayersName(selection)
{
var layers = [];
for (var i=0; i < [selection count]; i++){
Expand All @@ -144,26 +144,32 @@ function getSeletedLayersName()
return layers;
}

if([selection count] < 2){
[doc showMessage:"Please select 2 or more layers."]
}else {
var choice = createAlert('Align relative to', getSeletedLayersName(), 0)
if (choice[0] == 1000)
{
var direction = choice[2],
getKeyPosition = fnObj[direction].getKeyPosition,
alignObj = fnObj[direction].alignObj,
index = choice[1],
keyLayer = [selection objectAtIndex:index],
keyFrame = [keyLayer frame];

getKeyPosition(keyFrame)
for (var i=0; i < [selection count]; i++){
layer = [selection objectAtIndex:i]
frame = [layer frame]
alignObj(frame)
}

setConfig('last_algin_dir',fnObj[direction].position);
}
}
var onRun = function (context){
var doc = context.document;
var selection = context.selection;

if([selection count] < 2){
[doc showMessage:"Please select 2 or more layers."]
}else {
var choice = createAlert('Align relative to', getSeletedLayersName(selection), 0);
if (choice[0] == 1000)
{
var direction = choice[2],
getKeyPosition = fnObj[direction].getKeyPosition,
alignObj = fnObj[direction].alignObj,
index = choice[1],
keyLayer = [selection objectAtIndex:index],
keyFrame = [keyLayer frame];

getKeyPosition(keyFrame)
for (var i=0; i < [selection count]; i++){
layer = [selection objectAtIndex:i]
frame = [layer frame]
alignObj(frame)
}

setConfig('last_algin_dir',fnObj[direction].position);
}
}
};

30 changes: 30 additions & 0 deletions src/Contents/Sketch/hidden_others.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@import 'libs/common.js'

var onRun = function(context){
const selection = context.selection,
doc = context.document,
page = [doc currentPage],
artboard = [page currentArtboard],
g_layers = [artboard layers],
MAX_COUNT = [selection count];

if (MAX_COUNT > 0){
processAllLayers(g_layers,function(layer){
[layer setIsVisible:false];
});
}

function processAllLayers(layers,callback) {
for (var i = 0; i < [layers count]; i++) {
var layer = [layers objectAtIndex:i];
var isSkip = [selection indexOfObject:layer] < MAX_COUNT
if (isGroup(layer)) {
if (isSkip) continue;
processAllLayers([layer layers], callback);
}else{
if (!isSkip) callback(layer);
}
}
}
}

19 changes: 11 additions & 8 deletions libs/common.js → src/Contents/Sketch/libs/common.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
const page = [doc currentPage],
artboard = [page currentArtboard],
artboards = [doc artboards],
selection = context.selection,
doc = context.document,
current = artboard ? artboard : page,
prefix = 'kiny',
measureRegEx = /\$SIZE|\$WIDTH|\$HEIGHT|\$DISTANCE|\$PROPERTY|\$LABEL|\$OVERLAYER|\$COORDINATE/;
// const page = [doc currentPage],
// artboard = [page currentArtboard],
// artboards = [doc artboards],
// selection = context.selection,
// doc = context.document,
// current = artboard ? artboard : page,
const prefix = 'kiny',
measureRegEx = /\$SIZE|\$WIDTH|\$HEIGHT|\$DISTANCE|\$PROPERTY|\$LABEL|\$OVERLAYER|\$COORDINATE/;




function isMeasure(layer)
{
Expand Down
61 changes: 61 additions & 0 deletions src/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "Handy Tools",
"description": "Some handy tools for Sketch",
"author": "webpatch",
"homepage": "https://github.com/webpatch/Handy-Tools",
"version": 1.0,
"identifier": "com.hikiny.sketch.handytools",
"compatibleVersion": 3,
"commands": [
{
"name": "Algin to...",
"identifier": "algin",
"shortcut": "ctrl shift a",
"script": "algin.js",
"handler": "onRun"
},
{
"name": "Space...",
"identifier": "space",
"shortcut": "ctrl shift s",
"script": "space.js",
"handler": "onRun"
},
{
"name": "Hidden others",
"identifier": "hideOthers",
"shortcut": "",
"script": "hidden_others.js",
"handler": "onRun"
},
{
"name": "Unhidden all",
"identifier": "unhiddenAll",
"shortcut": "",
"script": "unhidden_all.js",
"handler": "onRun"
},
{
"name": "Unhidden all Artboards",
"identifier": "unhiddenAllArtboards",
"shortcut": "",
"script": "unhidden_all_artboard.js",
"handler": "onRun"
}
],
"menu": {
"items": [
"algin",
"space",
{
"title": "Hidden & Unhidden",
"items": [
"hideOthers",
"unhiddenAll",
"unhiddenAllArtboards"
]
}
],
"title": "Handy Tools"
}
}
45 changes: 25 additions & 20 deletions Spacing....sketchplugin → src/Contents/Sketch/space.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import 'libs/common.js'
@import 'libs/common.js'

var lastDir = getConfig('last_spacing_dir');
lastDir = lastDir == null ? 1 : parseInt(lastDir)
Expand Down Expand Up @@ -49,7 +49,7 @@ function sort_by_position_top(a,b){
return [[a frame] top] - [[b frame] top];
}

function horizontalSpacing(spacing)
function horizontalSpacing(spacing,selection)
{
var sorted_selection = toJSArray(selection).sort(sort_by_position_left),
first_element = sorted_selection[0],
Expand All @@ -61,7 +61,7 @@ function horizontalSpacing(spacing)
});
}

function verticallSpacing(spacing)
function verticallSpacing(spacing,selection)
{
var sorted_selection = toJSArray(selection).sort(sort_by_position_top),
first_element = sorted_selection[0],
Expand All @@ -73,22 +73,27 @@ function verticallSpacing(spacing)
});
}

if([selection count] < 2){
[doc showMessage:"Please select 2 or more layers."]
}else {
var choice = createAlert("Layers Spacing")
if (choice[0] == 1000)
{
var spacing = choice[1];
switch(choice[2]){
case "⬌":
horizontalSpacing(spacing);
setConfig('last_spacing_dir',0);
break;
case "⬍":
verticallSpacing(spacing);
setConfig('last_spacing_dir',1);
break;
var onRun = function(context) {
var doc = context.document;
var selection = context.selection;

if([selection count] < 2){
[doc showMessage:"Please select 2 or more layers."];
}else {
var choice = createAlert("Layers Spacing");
if (choice[0] == 1000)
{
var spacing = choice[1];
switch(choice[2]){
case "⬌":
horizontalSpacing(spacing,selection);
setConfig('last_spacing_dir',0);
break;
case "⬍":
verticallSpacing(spacing,selection);
setConfig('last_spacing_dir',1);
break;
}
}
}
}
}
Loading

0 comments on commit b1ad7b7

Please sign in to comment.