Skip to content

Commit 68a33d9

Browse files
authored
Merge pull request #39 from weixin/order
Order
2 parents 51349c4 + 98bd229 commit 68a33d9

33 files changed

+160
-21
lines changed

Diff for: WeSketch.sketchplugin/Contents/Sketch/fontCharacters.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ var fontCharacters = function(context){
5353
var range = layer.editingDelegate().textView().selectedRange();
5454
layer.editingDelegate().textView().replaceCharactersInRange_withString(range, obj.ustr);
5555
var range2 = layer.editingDelegate().textView().selectedRange();
56-
range2 = {location:range2-1,length:1};
57-
layer.editingDelegate().textView().setFont_range(fontfamily,range);
56+
range2 = {location:range2.location-1,length:1};
57+
layer.editingDelegate().textView().setFont_range(fontfamily,range2);
5858
}else{
5959
var fontSize = layer.fontSize();
6060
layer.setFont(fontfamily);

Diff for: WeSketch.sketchplugin/Contents/Sketch/i18n/enUS.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@
215215
"m6":"rpx(Mini App)",
216216
"m7":"Saved"
217217
},
218-
"fontSet":{
218+
"fontCharacters":{
219219
"m1":"Please select the text to add characters"
220+
},
221+
"orderLayers":{
222+
"m1":"Sorted successfully",
223+
"m2":"Please select the element to organize"
220224
}
221225
}

Diff for: WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-enUS.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "WeSketch",
33
"author": "Tencent WeChat",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"identifier": "cn.wechat",
66
"description" : "A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing",
77
"icon" : "minicon.png",
@@ -38,6 +38,14 @@
3838
"handler" : "onRun",
3939
"istool":"true"
4040
},
41+
{
42+
"name" : "Layer Order Organize",
43+
"identifier" : "sortingLayers",
44+
"script" : "sortingLayers.js",
45+
"shortcut": "command shift p",
46+
"handler" : "onRun",
47+
"istool":"true"
48+
},
4149
{
4250
"name" : "Icon Manager",
4351
"identifier" : "iconQ",
@@ -280,6 +288,7 @@
280288
"flag",
281289
"toolSetting",
282290
"-",
291+
"sortingLayers",
283292
"textReplace",
284293
"colorReplace",
285294
"fontReplace",

Diff for: WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-jaJP.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "WeSketch",
33
"author": "Tencent WeChat",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"identifier": "cn.wechat",
66
"description" : "A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing",
77
"icon" : "minicon.png",

Diff for: WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-zhCN.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "WeSketch",
33
"author": "Tencent WeChat",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"identifier": "cn.wechat",
66
"description" : "A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing",
77
"icon" : "minicon.png",
@@ -38,6 +38,14 @@
3838
"handler" : "onRun",
3939
"istool":"true",
4040
},
41+
{
42+
"name" : "整理图层顺序",
43+
"identifier" : "sortingLayers",
44+
"script" : "sortingLayers.js",
45+
"shortcut": "command shift p",
46+
"handler" : "onRun",
47+
"istool":"true"
48+
},
4149
{
4250
"name" : "图标库",
4351
"identifier" : "iconQ",
@@ -273,6 +281,7 @@
273281
"flag",
274282
"toolSetting",
275283
"-",
284+
"sortingLayers",
276285
"textReplace",
277286
"colorReplace",
278287
"fontReplace",

Diff for: WeSketch.sketchplugin/Contents/Sketch/i18n/manifest-zhTW.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "WeSketch",
33
"author": "Tencent WeChat",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"identifier": "cn.wechat",
66
"description": "A set of plugins for Sketch include drawing links & marks,UI Kit & Color sync,font & text replacing",
77
"icon": "minicon.png",
@@ -38,6 +38,14 @@
3838
"handler": "onRun",
3939
"istool": "true"
4040
},
41+
{
42+
"name" : "整理圖層順序",
43+
"identifier" : "sortingLayers",
44+
"script" : "sortingLayers.js",
45+
"shortcut": "command shift p",
46+
"handler" : "onRun",
47+
"istool":"true"
48+
},
4149
{
4250
"name": "圖標庫",
4351
"identifier": "iconQ",
@@ -273,6 +281,7 @@
273281
"flag",
274282
"toolSetting",
275283
"-",
284+
"sortingLayers",
276285
"textReplace",
277286
"colorReplace",
278287
"fontReplace",

Diff for: WeSketch.sketchplugin/Contents/Sketch/i18n/zhCN.json

+4
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,9 @@
217217
},
218218
"fontCharacters":{
219219
"m1":"请先选择要添加字符的文字"
220+
},
221+
"orderLayers":{
222+
"m1":"排序成功",
223+
"m2":"请选中要排序的元素"
220224
}
221225
}

Diff for: WeSketch.sketchplugin/Contents/Sketch/i18n/zhTW.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@
215215
"m6": "小程式rpx",
216216
"m7": "設定成功"
217217
},
218-
"fontSet":{
218+
"fontCharacters":{
219219
"m1":"請先選擇要添加字符的文字"
220+
},
221+
"orderLayers":{
222+
"m1":"排序成功",
223+
"m2":"請選中要排序的元素"
220224
}
221225
}

Diff for: WeSketch.sketchplugin/Contents/Sketch/library/panel/fontSet.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@
8484
}
8585
$('#select').append(select.join('')).select2();
8686
if(flagInit){
87-
SMAction('pushdata',{fontFamily:decodeURIComponent(data.initFamily)});
87+
family = $('#select').val();
88+
89+
SMAction('pushdata',{fontFamily:family});
8890
}
8991
}
9092

Binary file not shown.
Binary file not shown.
-44 Bytes
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading
Loading
Loading
Loading
Loading

Diff for: WeSketch.sketchplugin/Contents/Sketch/manifest.json

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "WeSketch",
33
"author": "Tencent WeChat",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"identifier": "cn.wechat",
66
"description" : "A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing",
77
"icon" : "minicon.png",
@@ -38,6 +38,14 @@
3838
"handler" : "onRun",
3939
"istool":"true"
4040
},
41+
{
42+
"name" : "Layer Order Organize",
43+
"identifier" : "sortingLayers",
44+
"script" : "sortingLayers.js",
45+
"shortcut": "command shift p",
46+
"handler" : "onRun",
47+
"istool":"true"
48+
},
4149
{
4250
"name" : "Icon Manager",
4351
"identifier" : "iconQ",
@@ -47,14 +55,6 @@
4755
"istool":"true",
4856
"handler" : "onRun"
4957
},
50-
{
51-
"name" : "Font Characters",
52-
"identifier" : "fontCharacters",
53-
"script" : "fontCharacters.js",
54-
"shortcut": "",
55-
"istool":"true",
56-
"handler" : "onRun"
57-
},
5858
{
5959
"name" : "Advanced Font Replace",
6060
"identifier" : "fontReplace",
@@ -82,6 +82,14 @@
8282
"istool":"true",
8383
"handler" : "onRun"
8484
},
85+
{
86+
"name" : "Font Characters",
87+
"identifier" : "fontCharacters",
88+
"script" : "fontCharacters.js",
89+
"shortcut": "",
90+
"istool":"true",
91+
"handler" : "onRun"
92+
},
8593
{
8694
"name" : "Upload",
8795
"identifier" : "uploadIcon",
@@ -280,6 +288,7 @@
280288
"flag",
281289
"toolSetting",
282290
"-",
291+
"sortingLayers",
283292
"textReplace",
284293
"colorReplace",
285294
"fontReplace",

Diff for: WeSketch.sketchplugin/Contents/Sketch/miniPreview.js

Whitespace-only changes.
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
@import "common.js"
2+
3+
function sortingLayers(context){
4+
var i18 = _(context).orderLayers;
5+
6+
var by = function(name,minor){
7+
return function(o,p){
8+
var a,b;
9+
if(o && p && typeof o === 'object' && typeof p ==='object'){
10+
a = o[name];
11+
b = p[name];
12+
if(a === b){
13+
return typeof minor === 'function' ? minor(o,p):0;
14+
}
15+
if(typeof a === typeof b){
16+
return a < b ? -1:1;
17+
}
18+
return typeof a < typeof b ? -1 : 1;
19+
}else{
20+
thro("error");
21+
}
22+
}
23+
}
24+
25+
var selection = context.selection;
26+
if(selection.length == 0){
27+
return NSApp.displayDialog(i18.m2);
28+
}
29+
var artboard = selection[0].parentArtboard();
30+
var length = selection.length;
31+
var order = {};
32+
33+
for(var i = 0;i<length;i++){
34+
var x = selection[i].absoluteRect().x();
35+
var y = selection[i].absoluteRect().y();
36+
var width = selection[i].rect().size.width;
37+
var height = selection[i].rect().size.height;
38+
var name = selection[i].name();
39+
40+
var obj = order[width + '_' + height];
41+
if(!obj){
42+
order[width + '_' + height] = [];
43+
obj = order[width + '_' + height];
44+
}
45+
46+
var object = {};
47+
object.x = x;
48+
object.y = y;
49+
object.width = width;
50+
object.height = height;
51+
object.name = selection[i].name();
52+
object.selection = selection[i];
53+
obj.push(object);
54+
}
55+
for(var i in order){
56+
order[i].sort(by('y',by('x')));
57+
var layer = order[i][order[i].length-1].selection.copy();
58+
for(var k = 0;k < order[i].length;k++){
59+
if(k == 0){
60+
artboard.addLayers([layer]);
61+
layer.moveToLayer_beforeLayer(artboard,order[i][k].selection);
62+
order[i][k].selection.moveToLayer_beforeLayer(artboard,layer);
63+
}else{
64+
order[i][k].selection.moveToLayer_beforeLayer(artboard,order[i][k-1].selection);
65+
}
66+
order[i][k].selection.setName(order[i][0].name + (k+1));
67+
if(k == order[i].length - 1){
68+
layer.removeFromParent();
69+
}
70+
}
71+
}
72+
context.document.showMessage(i18.m1);
73+
}
74+
75+
var onRun = function(context) {
76+
sortingLayers(context);
77+
};

Diff for: WeSketch.sketchplugin/Contents/Sketch/toolbar.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@import 'exportSlice.js';
1212
@import 'codeStyle.js';
1313
@import 'codeColor.js';
14+
@import 'sortingLayers.js';
1415

1516

1617
function toolbar(context,auto){
@@ -141,6 +142,17 @@ function toolbar(context,auto){
141142
xlocation = xlocation+53;
142143
}
143144

145+
if(obj.indexOf('sortingLayers') > -1){
146+
147+
var flagButton = addButton( NSMakeRect(xlocation+3, 9, 45, 45), "sorting"+prefix,
148+
function(sender){
149+
var nowcontext = uploadContext(context);
150+
sortingLayers(nowcontext);
151+
});
152+
contentView.addSubview(flagButton);
153+
xlocation = xlocation+53;
154+
}
155+
144156
if(obj.indexOf('iconQ') > -1){
145157
var iconButton = addButton( NSMakeRect(xlocation+3, 9, 45, 45), "icon"+prefix,
146158
function(sender){
@@ -204,13 +216,13 @@ function toolbar(context,auto){
204216
}
205217

206218
if(obj.indexOf('fontCharacters') > -1){
207-
var fontButton = addButton( NSMakeRect(xlocation+3, 9, 51, 45), "fontCharacters"+prefix,
219+
var fontButton = addButton( NSMakeRect(xlocation+3, 9, 47, 45), "fontCharacters"+prefix,
208220
function(sender){
209221
var nowcontext = uploadContext(context);
210-
fontReplace(nowcontext);
222+
fontCharacters(nowcontext);
211223
});
212224
contentView.addSubview(fontButton);
213-
xlocation = xlocation+59;
225+
xlocation = xlocation+55;
214226
}
215227

216228

0 commit comments

Comments
 (0)