Skip to content

Commit b8d66e7

Browse files
committed
remember previous library
1 parent 5e82594 commit b8d66e7

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Library Symbol Replacer",
33
"identifier": "com.zeroheight.library-symbol-replacer",
4-
"version": "1.0.10",
4+
"version": "1.0.11",
55
"description": "replace local symbols with library symbols",
66
"authorEmail": "[email protected]",
77
"author": "zeroheight team",
@@ -12,8 +12,14 @@
1212
"commands": [{
1313
"script": "script.js",
1414
"handler": "replaceSymbols",
15-
"shortcut": "ctrl shift y",
16-
"name": "Replace Symbols from Library",
15+
"name": "Replace symbols from a new library",
1716
"identifier": "com.zeroheight.library-symbol-replacer.replace"
17+
},
18+
{
19+
"script": "script.js",
20+
"handler": "replaceFromLast",
21+
"shortcut": "ctrl shift y",
22+
"name": "Replace symbols from the previous library",
23+
"identifier": "com.zeroheight.library-symbol-replacer.replace-from-last"
1824
}]
1925
}

library-symbol-replacer.sketchplugin/Contents/Sketch/script.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
var replaceFromLast = function(context){
2+
var userDefaults = this.getUserDefaults();
3+
var urlString = userDefaults.objectForKey('url');
4+
if(!urlString){
5+
this.replaceSymbols(context);
6+
}else{
7+
var url = NSURL.URLWithString(urlString);
8+
this.replaceFromUrl(context, url);
9+
}
10+
}
11+
112
var replaceSymbols = function(context) {
213
var decision = yesNoDialog('Select the Library file you want to replace symbols from',
314
'Choose','Cancel');
@@ -11,6 +22,15 @@ var replaceSymbols = function(context) {
1122
return;
1223
}
1324

25+
var userDefaults = this.getUserDefaults();
26+
27+
userDefaults.setObject_forKey(String(url),"url");
28+
userDefaults.synchronize();
29+
30+
this.replaceFromUrl(context,url);
31+
}
32+
33+
var replaceFromUrl = function(context,url){
1434
var library = findLibraryByUrl(url);
1535
if(!library){
1636
showAlert('Sorry, that file is not a Library. Add it as a Library and try again');
@@ -82,7 +102,6 @@ var replaceSymbols = function(context) {
82102
// ensure there are no dangling overrides still pointing to local symbols
83103
var allInstances = getAllInstances(context.document);
84104
for(var i = 0 ; i < allInstances.length ; ++i){
85-
log('updating instance ' + allInstances[i]);
86105
MSLayerPaster.updateOverridesOnInstance_withIDMap_(allInstances[i], idmap);
87106
}
88107

@@ -99,6 +118,10 @@ var replaceSymbols = function(context) {
99118
}
100119
}
101120

121+
var getUserDefaults = function(){
122+
return NSUserDefaults.alloc().initWithSuiteName("com.zeroheight.library-symbol-replacer");
123+
}
124+
102125
var getAllInstances = function(document){
103126
var predicate = NSPredicate.predicateWithFormat("className == %@", "MSSymbolInstance");
104127
var filteredArray = NSArray.array()

0 commit comments

Comments
 (0)