From b1ad7b7249417b42c15c7a2590e47f395d9645cb Mon Sep 17 00:00:00 2001 From: kiny Date: Sat, 5 Dec 2015 22:19:34 +0800 Subject: [PATCH] update --- .../Hidden Other Layers.sketchplugin | 23 -- .../Unhidden All Layers.sketchplugin | 20 -- README.md | 4 +- release/HandyTools.sketchplugin.zip | Bin 0 -> 6574 bytes src/Contents/Sketch/.idea/.name | 1 + src/Contents/Sketch/.idea/Sketch.iml | 8 + src/Contents/Sketch/.idea/encodings.xml | 6 + src/Contents/Sketch/.idea/misc.xml | 13 + src/Contents/Sketch/.idea/modules.xml | 8 + src/Contents/Sketch/.idea/workspace.xml | 317 ++++++++++++++++++ .../Contents/Sketch/algin.js | 60 ++-- src/Contents/Sketch/hidden_others.js | 30 ++ {libs => src/Contents/Sketch/libs}/common.js | 19 +- src/Contents/Sketch/manifest.json | 61 ++++ .../Contents/Sketch/space.js | 45 +-- .../Contents/Sketch/unhidden_all.js | 20 +- src/Contents/Sketch/unhidden_all_artboard.js | 28 ++ 17 files changed, 555 insertions(+), 108 deletions(-) delete mode 100755 Hidden & UnHidden/Hidden Other Layers.sketchplugin delete mode 100644 Hidden & UnHidden/Unhidden All Layers.sketchplugin create mode 100755 release/HandyTools.sketchplugin.zip create mode 100644 src/Contents/Sketch/.idea/.name create mode 100644 src/Contents/Sketch/.idea/Sketch.iml create mode 100644 src/Contents/Sketch/.idea/encodings.xml create mode 100644 src/Contents/Sketch/.idea/misc.xml create mode 100644 src/Contents/Sketch/.idea/modules.xml create mode 100644 src/Contents/Sketch/.idea/workspace.xml rename Align To....sketchplugin => src/Contents/Sketch/algin.js (76%) mode change 100644 => 100755 create mode 100755 src/Contents/Sketch/hidden_others.js rename {libs => src/Contents/Sketch/libs}/common.js (77%) mode change 100644 => 100755 create mode 100644 src/Contents/Sketch/manifest.json rename Spacing....sketchplugin => src/Contents/Sketch/space.js (77%) mode change 100644 => 100755 rename Hidden & UnHidden/Unhidden Current Page's All Layers.sketchplugin => src/Contents/Sketch/unhidden_all.js (50%) mode change 100644 => 100755 create mode 100755 src/Contents/Sketch/unhidden_all_artboard.js diff --git a/Hidden & UnHidden/Hidden Other Layers.sketchplugin b/Hidden & UnHidden/Hidden Other Layers.sketchplugin deleted file mode 100755 index 53232bd..0000000 --- a/Hidden & UnHidden/Hidden Other Layers.sketchplugin +++ /dev/null @@ -1,23 +0,0 @@ -#import 'libs/common.js' - -const g_layers = [artboard layers]; -const 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); - } - } -} diff --git a/Hidden & UnHidden/Unhidden All Layers.sketchplugin b/Hidden & UnHidden/Unhidden All Layers.sketchplugin deleted file mode 100644 index 7b38433..0000000 --- a/Hidden & UnHidden/Unhidden All Layers.sketchplugin +++ /dev/null @@ -1,20 +0,0 @@ -#import 'libs/common.js' - -function processAllLayers(layers, callback) { - for (var i = 0; i < [layers count]; i++) { - var layer = [layers objectAtIndex:i]; - if (isMeasure(layer)) continue; - if ([layer isMemberOfClass:[MSLayerGroup class]]) { - callback(layer); - processAllLayers([layer layers], callback); - } - else { - callback(layer); - } - } -} - -const layers = [artboard layers]; -processAllLayers(layers,function(layer){ - if(![layer isVisible])[layer setIsVisible:true]; -}) \ No newline at end of file diff --git a/README.md b/README.md index 9ce24f1..3f0ca0e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/release/HandyTools.sketchplugin.zip b/release/HandyTools.sketchplugin.zip new file mode 100755 index 0000000000000000000000000000000000000000..b0411bd7a70b59274637d8e62abb5ede083206de GIT binary patch literal 6574 zcmbVRbyU>d)*iYM2|+?YLb_9=LApaahoNDlyJRTolrHIR5DDq-9$@HDN>C7~5AS__ z_1@+CExl*fn%|i}_Os8K=bXLwvwzBR2#ENAZ^J1ABK5DyUtdJGPibR2pu4)gy^SM_ zqqUinsRh`^+1%2ORrzl#n)Ls)qWpiX#O>{z%oz+kLiKUC^=LCPN!YDz1LR`ctJoozS1%UX!g;axg!81d<#ME^ zXo!1W{#<$~#4J%}+`EWJAf1=%5xvG&q0xSQ4r33B?pI2S3Z!15lW2sjxEb~yS0f!| zt<7>0G5H(3)e7(&c}*t4V$FH?^PPGiA>2s;)OzD81ISDYOGGRN+ur6>T>?3;uEn$1 z(R#Qvn5>8t9U1TeoY@HJghr{nB8F`|S}5)ZCmW=`COTqKW{P^$y@#;|nXsx;yMZo= z%+KdDiL>*72CVhiGz9t&caID2bcU=4(eTCOCNa&Rd{w62djjZ1okj2=InjLbe54SB zLO)oSS`@0(2ueQomqtI)c0i3n?hI_?Ko>2I)YlWaB*WV#8ChPA+qoAM73_whGQjsx z4}3*9YktQerE2BlQAn%FBfs@iFV*XlXiY6jBT$o~_6i^4`r!RwhLq`orYY6Y{8F8^ zF&%U!3rjL|$@+72CALGE?2$-FQ)KT9Zi03{ zNJ@SCt*qSnkz?{a)PJx-a0f|@BRQ)VO`-8gfG0*^;^We+)=py;AXOrHl+uPS!5)tk zG6ypU+zX9xGph0X$l563xdS*A!G63Tr#@Jf(b1!8qpkykQCJ;~{AQOk!xcZUWI~4o zF%|VWHWwlx6UIqTxs(Z>iE`v+we`T;F}(D1<55`XWssfVAWgS9M1r)}_4?w%urVdo zcj$9XlTXKoU{-KTdvgVOy2X7TD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Sx+AmIf%ptO$zLvj(T}EMuXlIfgq`2hJ6q z!c@e^MZFSNpPzlrT;O&lj-YGXmHI>}t&V#|niD!!9_MTv(J3_D6hiDq;B#98z`^4q z{BvLSmcQG91K1b+_WURL^fSt@`n2C{|Bdon%IRmgU-fN&z&YPe|7lVGt?7QC{<@F* zZ&Uza-@o|}P``I|e@6dR2jK^L=BtKT2X|Fxj_?&Gz8-E9^6yMNMu$cvv{{Hm<|?qc6R7VGz2d@pi;M*mex z`hm`M`*z@WH}GEx>Srgv3aCGvK=J-JCqIW*WjUnV0|@|N+;FW8Z@>Nzo1I#K literal 0 HcmV?d00001 diff --git a/src/Contents/Sketch/.idea/.name b/src/Contents/Sketch/.idea/.name new file mode 100644 index 0000000..106004a --- /dev/null +++ b/src/Contents/Sketch/.idea/.name @@ -0,0 +1 @@ +Sketch \ No newline at end of file diff --git a/src/Contents/Sketch/.idea/Sketch.iml b/src/Contents/Sketch/.idea/Sketch.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/src/Contents/Sketch/.idea/Sketch.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Contents/Sketch/.idea/encodings.xml b/src/Contents/Sketch/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/src/Contents/Sketch/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Contents/Sketch/.idea/misc.xml b/src/Contents/Sketch/.idea/misc.xml new file mode 100644 index 0000000..72abef0 --- /dev/null +++ b/src/Contents/Sketch/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Contents/Sketch/.idea/modules.xml b/src/Contents/Sketch/.idea/modules.xml new file mode 100644 index 0000000..330d319 --- /dev/null +++ b/src/Contents/Sketch/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Contents/Sketch/.idea/workspace.xml b/src/Contents/Sketch/.idea/workspace.xml new file mode 100644 index 0000000..4ed7d54 --- /dev/null +++ b/src/Contents/Sketch/.idea/workspace.xml @@ -0,0 +1,317 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $PROJECT_DIR$ + true + + bdd + + DIRECTORY + + false + + + + + + + + 1449318869886 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Align To....sketchplugin b/src/Contents/Sketch/algin.js old mode 100644 new mode 100755 similarity index 76% rename from Align To....sketchplugin rename to src/Contents/Sketch/algin.js index 40337f7..fe2ddbe --- a/Align To....sketchplugin +++ b/src/Contents/Sketch/algin.js @@ -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) { @@ -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]; @@ -134,7 +134,7 @@ var fnObj = { } } -function getSeletedLayersName() +function getSeletedLayersName(selection) { var layers = []; for (var i=0; i < [selection count]; i++){ @@ -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); + } + } +}; + diff --git a/src/Contents/Sketch/hidden_others.js b/src/Contents/Sketch/hidden_others.js new file mode 100755 index 0000000..1dad6e3 --- /dev/null +++ b/src/Contents/Sketch/hidden_others.js @@ -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); + } + } + } +} + diff --git a/libs/common.js b/src/Contents/Sketch/libs/common.js old mode 100644 new mode 100755 similarity index 77% rename from libs/common.js rename to src/Contents/Sketch/libs/common.js index d39ae13..c330545 --- a/libs/common.js +++ b/src/Contents/Sketch/libs/common.js @@ -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) { diff --git a/src/Contents/Sketch/manifest.json b/src/Contents/Sketch/manifest.json new file mode 100644 index 0000000..ddf666a --- /dev/null +++ b/src/Contents/Sketch/manifest.json @@ -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" + } +} \ No newline at end of file diff --git a/Spacing....sketchplugin b/src/Contents/Sketch/space.js old mode 100644 new mode 100755 similarity index 77% rename from Spacing....sketchplugin rename to src/Contents/Sketch/space.js index 3e0f28d..7eceab7 --- a/Spacing....sketchplugin +++ b/src/Contents/Sketch/space.js @@ -1,4 +1,4 @@ -#import 'libs/common.js' +@import 'libs/common.js' var lastDir = getConfig('last_spacing_dir'); lastDir = lastDir == null ? 1 : parseInt(lastDir) @@ -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], @@ -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], @@ -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; + } } } -} \ No newline at end of file +} diff --git a/Hidden & UnHidden/Unhidden Current Page's All Layers.sketchplugin b/src/Contents/Sketch/unhidden_all.js old mode 100644 new mode 100755 similarity index 50% rename from Hidden & UnHidden/Unhidden Current Page's All Layers.sketchplugin rename to src/Contents/Sketch/unhidden_all.js index bd248c2..d2fd485 --- a/Hidden & UnHidden/Unhidden Current Page's All Layers.sketchplugin +++ b/src/Contents/Sketch/unhidden_all.js @@ -1,6 +1,13 @@ -#import 'libs/common.js' +@import 'libs/common.js' -function processAllLayers(layers, callback) { +var onRun = function(context){ + const selection = context.selection, + doc = context.document, + page = [doc currentPage], + artboard = [page currentArtboard], + layers = [artboard layers]; + + function processAllLayers(layers, callback) { for (var i = 0; i < [layers count]; i++) { var layer = [layers objectAtIndex:i]; if (isMeasure(layer)) continue; @@ -8,16 +15,13 @@ function processAllLayers(layers, callback) { callback(layer); processAllLayers([layer layers], callback); } - else { + else { callback(layer); } } -} + } -for (var j = 0; j < [artboards count]; j++){ - var artboard = [artboards objectAtIndex:j]; - var layers = [artboard layers]; processAllLayers(layers,function(layer){ - if(![layer isVisible]) [layer setIsVisible:true]; + if(![layer isVisible])[layer setIsVisible:true]; }) } diff --git a/src/Contents/Sketch/unhidden_all_artboard.js b/src/Contents/Sketch/unhidden_all_artboard.js new file mode 100755 index 0000000..4821773 --- /dev/null +++ b/src/Contents/Sketch/unhidden_all_artboard.js @@ -0,0 +1,28 @@ +@import 'libs/common.js' + +var onRun = function(context){ + const doc = context.document, + artboards = [doc artboards]; + + function processAllLayers(layers, callback) { + for (var i = 0; i < [layers count]; i++) { + var layer = [layers objectAtIndex:i]; + if (isMeasure(layer)) continue; + if ([layer isMemberOfClass:[MSLayerGroup class]]) { + callback(layer); + processAllLayers([layer layers], callback); + }else { + callback(layer); + } + } + } + + for (var j = 0; j < [artboards count]; j++){ + var artboard = [artboards objectAtIndex:j]; + var layers = [artboard layers]; + processAllLayers(layers,function(layer){ + if(![layer isVisible]) [layer setIsVisible:true]; + }) + } +} +