Skip to content

Commit

Permalink
Merge pull request #39 from weixin/order
Browse files Browse the repository at this point in the history
Order
  • Loading branch information
bugluo committed Aug 10, 2017
2 parents 51349c4 + 98bd229 commit 68a33d9
Show file tree
Hide file tree
Showing 33 changed files with 160 additions and 21 deletions.
4 changes: 2 additions & 2 deletions WeSketch.sketchplugin/Contents/Sketch/fontCharacters.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ var fontCharacters = function(context){
var range = layer.editingDelegate().textView().selectedRange();
layer.editingDelegate().textView().replaceCharactersInRange_withString(range, obj.ustr);
var range2 = layer.editingDelegate().textView().selectedRange();
range2 = {location:range2-1,length:1};
layer.editingDelegate().textView().setFont_range(fontfamily,range);
range2 = {location:range2.location-1,length:1};
layer.editingDelegate().textView().setFont_range(fontfamily,range2);
}else{
var fontSize = layer.fontSize();
layer.setFont(fontfamily);
Expand Down
6 changes: 5 additions & 1 deletion WeSketch.sketchplugin/Contents/Sketch/i18n/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@
"m6":"rpx(Mini App)",
"m7":"Saved"
},
"fontSet":{
"fontCharacters":{
"m1":"Please select the text to add characters"
},
"orderLayers":{
"m1":"Sorted successfully",
"m2":"Please select the element to organize"
}
}
11 changes: 10 additions & 1 deletion WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-enUS.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "WeSketch",
"author": "Tencent WeChat",
"version": "1.1.1",
"version": "1.2.0",
"identifier": "cn.wechat",
"description" : "A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing",
"icon" : "minicon.png",
Expand Down Expand Up @@ -38,6 +38,14 @@
"handler" : "onRun",
"istool":"true"
},
{
"name" : "Layer Order Organize",
"identifier" : "sortingLayers",
"script" : "sortingLayers.js",
"shortcut": "command shift p",
"handler" : "onRun",
"istool":"true"
},
{
"name" : "Icon Manager",
"identifier" : "iconQ",
Expand Down Expand Up @@ -280,6 +288,7 @@
"flag",
"toolSetting",
"-",
"sortingLayers",
"textReplace",
"colorReplace",
"fontReplace",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "WeSketch",
"author": "Tencent WeChat",
"version": "1.1.1",
"version": "1.2.0",
"identifier": "cn.wechat",
"description" : "A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing",
"icon" : "minicon.png",
Expand Down
11 changes: 10 additions & 1 deletion WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-zhCN.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "WeSketch",
"author": "Tencent WeChat",
"version": "1.1.1",
"version": "1.2.0",
"identifier": "cn.wechat",
"description" : "A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing",
"icon" : "minicon.png",
Expand Down Expand Up @@ -38,6 +38,14 @@
"handler" : "onRun",
"istool":"true",
},
{
"name" : "整理图层顺序",
"identifier" : "sortingLayers",
"script" : "sortingLayers.js",
"shortcut": "command shift p",
"handler" : "onRun",
"istool":"true"
},
{
"name" : "图标库",
"identifier" : "iconQ",
Expand Down Expand Up @@ -273,6 +281,7 @@
"flag",
"toolSetting",
"-",
"sortingLayers",
"textReplace",
"colorReplace",
"fontReplace",
Expand Down
11 changes: 10 additions & 1 deletion WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-zhTW.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "WeSketch",
"author": "Tencent WeChat",
"version": "1.1.1",
"version": "1.2.0",
"identifier": "cn.wechat",
"description": "A set of plugins for Sketch include drawing links & marks,UI Kit & Color sync,font & text replacing",
"icon": "minicon.png",
Expand Down Expand Up @@ -38,6 +38,14 @@
"handler": "onRun",
"istool": "true"
},
{
"name" : "整理圖層順序",
"identifier" : "sortingLayers",
"script" : "sortingLayers.js",
"shortcut": "command shift p",
"handler" : "onRun",
"istool":"true"
},
{
"name": "圖標庫",
"identifier": "iconQ",
Expand Down Expand Up @@ -273,6 +281,7 @@
"flag",
"toolSetting",
"-",
"sortingLayers",
"textReplace",
"colorReplace",
"fontReplace",
Expand Down
4 changes: 4 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/i18n/zhCN.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,9 @@
},
"fontCharacters":{
"m1":"请先选择要添加字符的文字"
},
"orderLayers":{
"m1":"排序成功",
"m2":"请选中要排序的元素"
}
}
6 changes: 5 additions & 1 deletion WeSketch.sketchplugin/Contents/Sketch/i18n/zhTW.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@
"m6": "小程式rpx",
"m7": "設定成功"
},
"fontSet":{
"fontCharacters":{
"m1":"請先選擇要添加字符的文字"
},
"orderLayers":{
"m1":"排序成功",
"m2":"請選中要排序的元素"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@
}
$('#select').append(select.join('')).select2();
if(flagInit){
SMAction('pushdata',{fontFamily:decodeURIComponent(data.initFamily)});
family = $('#select').val();

SMAction('pushdata',{fontFamily:family});
}
}

Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 18 additions & 9 deletions WeSketch.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "WeSketch",
"author": "Tencent WeChat",
"version": "1.1.1",
"version": "1.2.0",
"identifier": "cn.wechat",
"description" : "A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing",
"icon" : "minicon.png",
Expand Down Expand Up @@ -38,6 +38,14 @@
"handler" : "onRun",
"istool":"true"
},
{
"name" : "Layer Order Organize",
"identifier" : "sortingLayers",
"script" : "sortingLayers.js",
"shortcut": "command shift p",
"handler" : "onRun",
"istool":"true"
},
{
"name" : "Icon Manager",
"identifier" : "iconQ",
Expand All @@ -47,14 +55,6 @@
"istool":"true",
"handler" : "onRun"
},
{
"name" : "Font Characters",
"identifier" : "fontCharacters",
"script" : "fontCharacters.js",
"shortcut": "",
"istool":"true",
"handler" : "onRun"
},
{
"name" : "Advanced Font Replace",
"identifier" : "fontReplace",
Expand Down Expand Up @@ -82,6 +82,14 @@
"istool":"true",
"handler" : "onRun"
},
{
"name" : "Font Characters",
"identifier" : "fontCharacters",
"script" : "fontCharacters.js",
"shortcut": "",
"istool":"true",
"handler" : "onRun"
},
{
"name" : "Upload",
"identifier" : "uploadIcon",
Expand Down Expand Up @@ -280,6 +288,7 @@
"flag",
"toolSetting",
"-",
"sortingLayers",
"textReplace",
"colorReplace",
"fontReplace",
Expand Down
Empty file.
77 changes: 77 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/sortingLayers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@import "common.js"

function sortingLayers(context){
var i18 = _(context).orderLayers;

var by = function(name,minor){
return function(o,p){
var a,b;
if(o && p && typeof o === 'object' && typeof p ==='object'){
a = o[name];
b = p[name];
if(a === b){
return typeof minor === 'function' ? minor(o,p):0;
}
if(typeof a === typeof b){
return a < b ? -1:1;
}
return typeof a < typeof b ? -1 : 1;
}else{
thro("error");
}
}
}

var selection = context.selection;
if(selection.length == 0){
return NSApp.displayDialog(i18.m2);
}
var artboard = selection[0].parentArtboard();
var length = selection.length;
var order = {};

for(var i = 0;i<length;i++){
var x = selection[i].absoluteRect().x();
var y = selection[i].absoluteRect().y();
var width = selection[i].rect().size.width;
var height = selection[i].rect().size.height;
var name = selection[i].name();

var obj = order[width + '_' + height];
if(!obj){
order[width + '_' + height] = [];
obj = order[width + '_' + height];
}

var object = {};
object.x = x;
object.y = y;
object.width = width;
object.height = height;
object.name = selection[i].name();
object.selection = selection[i];
obj.push(object);
}
for(var i in order){
order[i].sort(by('y',by('x')));
var layer = order[i][order[i].length-1].selection.copy();
for(var k = 0;k < order[i].length;k++){
if(k == 0){
artboard.addLayers([layer]);
layer.moveToLayer_beforeLayer(artboard,order[i][k].selection);
order[i][k].selection.moveToLayer_beforeLayer(artboard,layer);
}else{
order[i][k].selection.moveToLayer_beforeLayer(artboard,order[i][k-1].selection);
}
order[i][k].selection.setName(order[i][0].name + (k+1));
if(k == order[i].length - 1){
layer.removeFromParent();
}
}
}
context.document.showMessage(i18.m1);
}

var onRun = function(context) {
sortingLayers(context);
};
18 changes: 15 additions & 3 deletions WeSketch.sketchplugin/Contents/Sketch/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@import 'exportSlice.js';
@import 'codeStyle.js';
@import 'codeColor.js';
@import 'sortingLayers.js';


function toolbar(context,auto){
Expand Down Expand Up @@ -141,6 +142,17 @@ function toolbar(context,auto){
xlocation = xlocation+53;
}

if(obj.indexOf('sortingLayers') > -1){

var flagButton = addButton( NSMakeRect(xlocation+3, 9, 45, 45), "sorting"+prefix,
function(sender){
var nowcontext = uploadContext(context);
sortingLayers(nowcontext);
});
contentView.addSubview(flagButton);
xlocation = xlocation+53;
}

if(obj.indexOf('iconQ') > -1){
var iconButton = addButton( NSMakeRect(xlocation+3, 9, 45, 45), "icon"+prefix,
function(sender){
Expand Down Expand Up @@ -204,13 +216,13 @@ function toolbar(context,auto){
}

if(obj.indexOf('fontCharacters') > -1){
var fontButton = addButton( NSMakeRect(xlocation+3, 9, 51, 45), "fontCharacters"+prefix,
var fontButton = addButton( NSMakeRect(xlocation+3, 9, 47, 45), "fontCharacters"+prefix,
function(sender){
var nowcontext = uploadContext(context);
fontReplace(nowcontext);
fontCharacters(nowcontext);
});
contentView.addSubview(fontButton);
xlocation = xlocation+59;
xlocation = xlocation+55;
}


Expand Down

0 comments on commit 68a33d9

Please sign in to comment.