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 0000000..b0411bd
Binary files /dev/null and b/release/HandyTools.sketchplugin.zip differ
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
+
+ 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];
+ })
+ }
+}
+