Skip to content

Commit

Permalink
手动删除 connections 也可以删除连线
Browse files Browse the repository at this point in the history
  • Loading branch information
bugluo committed Nov 17, 2017
1 parent 54664e6 commit 3b66a9c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Miaow",
"author": "Tencent WeChat",
"version": "1.4.0",
"version": "1.4.1",
"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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Miaow",
"author": "Tencent WeChat",
"version": "1.4.0",
"version": "1.4.1",
"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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Miaow",
"author": "Tencent WeChat",
"version": "1.4.0",
"version": "1.4.1",
"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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Miaow",
"author": "Tencent WeChat",
"version": "1.4.0",
"version": "1.4.1",
"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
40 changes: 33 additions & 7 deletions WeSketch.sketchplugin/Contents/Sketch/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,19 +1072,17 @@ var redrawConnections = function (context) {
var selectionLayer = context.selection;

//var selectedLayers = doc.findSelectedLayers();
var linkLayersPredicate = NSPredicate.predicateWithFormat("userInfo != nil && function(userInfo, 'valueForKeyPath:', %@).destinationArtboardID != nil", kPluginDomain),
linkLayers = doc.currentPage().children().filteredArrayUsingPredicate(linkLayersPredicate),
loop = linkLayers.objectEnumerator(),
connections = [],
linkLayer, destinationArtboardID, destinationArtboard, isCondition, linkRect;

var connectionsGroup = getConnectionsGroupInPage(doc.currentPage());
if (connectionsGroup) {
connectionsGroup.removeFromParent();
}

var linkLayersPredicate = NSPredicate.predicateWithFormat("userInfo != nil && function(userInfo, 'valueForKeyPath:', %@).destinationArtboardID != nil", kPluginDomain),
linkLayers = doc.currentPage().children().filteredArrayUsingPredicate(linkLayersPredicate),
loop = linkLayers.objectEnumerator(),
connections = [],
linkLayer, destinationArtboardID, destinationArtboard, isCondition, linkRect;


while (linkLayer = loop.nextObject()) {
destinationArtboardID = context.command.valueForKey_onLayer_forPluginIdentifier("destinationArtboardID", linkLayer, kPluginDomain);
var Message = destinationArtboardID.split('____');
Expand Down Expand Up @@ -1119,6 +1117,34 @@ var redrawConnections = function (context) {
var selection = context.selection;
var destArtboard, linkLayer;

// 检查有没有被手动删掉的
var connectionsGroup = getConnectionsGroupInPage(context.document.currentPage());
if (!connectionsGroup) {
var linkLayersPredicate = NSPredicate.predicateWithFormat("userInfo != nil && function(userInfo, 'valueForKeyPath:', %@).destinationArtboardID != nil", kPluginDomain),
linkLayers = context.document.currentPage().children().filteredArrayUsingPredicate(linkLayersPredicate),
loop = linkLayers.objectEnumerator(),
linkLayer, destinationArtboardID;
while (linkLayer = loop.nextObject()) {
context.command.setValue_forKey_onLayer_forPluginIdentifier(nil, "destinationArtboardID", linkLayer, kPluginDomain);
}
}else{
var linkLayersPredicate = NSPredicate.predicateWithFormat("userInfo != nil && function(userInfo, 'valueForKeyPath:', %@).destinationArtboardID != nil", kPluginDomain),
linkLayers = context.document.currentPage().children().filteredArrayUsingPredicate(linkLayersPredicate),
loop = linkLayers.objectEnumerator(),
linkLayer, destinationArtboardID;
var child = connectionsGroup.layers();
while (linkLayer = loop.nextObject()) {
for(var i = 0;i < child.length; i++){
if(encodeURIComponent(child[i].name()) == encodeURIComponent(linkLayer.objectID())){
break;
}
if(i == child.length-1){
context.command.setValue_forKey_onLayer_forPluginIdentifier(nil, "destinationArtboardID", linkLayer, kPluginDomain);
}
}
}
}

if (selection.count() != 1 && selection.count() != 2) {
redrawConnections(context);
if (!refursh) {
Expand Down
2 changes: 1 addition & 1 deletion WeSketch.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Miaow",
"author": "Tencent WeChat",
"version": "1.4.0",
"version": "1.4.1",
"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

0 comments on commit 3b66a9c

Please sign in to comment.