Skip to content

Commit

Permalink
- Symbol list in Replace Symbol With Library Symbol now sorted like F…
Browse files Browse the repository at this point in the history
…inder.

- Fix bug when Export Clean Code SVG opening export window for each selection. #123
  • Loading branch information
Ashung committed Dec 13, 2018
1 parent b3f9307 commit 7bc528d
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 54 deletions.
Expand Up @@ -5,7 +5,7 @@
"email": "Ashung.hung@gmail.com",
"homepage": "https://github.com/Ashung/Automate-Sketch",
"appcast": "https://ashung.github.io/Automate-Sketch/appcast.xml",
"version": "52.4.20181123",
"version": "52.5.20181213",
"identifier": "com.ashung.hung.automate_sketch",
"icon": "icon.png",
"suppliesData" : true,
Expand Down
Expand Up @@ -5,7 +5,7 @@
"email": "Ashung.hung@gmail.com",
"homepage": "https://github.com/Ashung/Automate-Sketch",
"appcast": "https://ashung.github.io/Automate-Sketch/appcast.xml",
"version": "52.4.20181123",
"version": "52.5.20181213",
"identifier": "com.ashung.hung.automate_sketch",
"icon": "icon.png",
"suppliesData" : true,
Expand Down
Expand Up @@ -5,7 +5,7 @@
"email": "Ashung.hung@gmail.com",
"homepage": "https://github.com/Ashung/Automate-Sketch",
"appcast": "https://ashung.github.io/Automate-Sketch/appcast.xml",
"version": "52.4.20181123",
"version": "52.5.20181213",
"identifier": "com.ashung.hung.automate_sketch",
"icon": "icon.png",
"suppliesData" : true,
Expand Down
Expand Up @@ -124,7 +124,7 @@ var onRun = function(context) {
}
// Reset Text/Layer Style
else {
layer.setStyle(localStyleIDToForeignStyleMapping[localStyleID].localSharedStyle().newInstance())
layer.setStyle(localStyleIDToForeignStyleMapping[localStyleID].localSharedStyle().newInstance());
}
}
});
Expand Down
Expand Up @@ -117,7 +117,7 @@ function loadData(scrollView, symbols) {
var imageView = NSImageView.alloc().initWithFrame(NSMakeRect(10, 10, 40, 40));
var layerAncestry = importedSymbol.symbolMaster().ancestry();;
var symbolPreviewImage = MSSymbolPreviewGenerator.imageForSymbolAncestry_withSize_colorSpace_trimmed(
layerAncestry, CGSizeMake(80, 80), NSColorSpace.sRGBColorSpace(), true
layerAncestry, CGSizeMake(80, 80), NSColorSpace.sRGBColorSpace(), false
);
imageView.setImage(symbolPreviewImage);
itemView.addSubview(imageView);
Expand Down
Expand Up @@ -125,8 +125,10 @@ function reloadSymbolData(context, view, symbol, library, checkboxSize) {
var documentData = document.documentData();

var allSymbols = library.document().allSymbols().mutableCopy();
var sortByName = NSSortDescriptor.sortDescriptorWithKey_ascending("name", true);
allSymbols.sortUsingDescriptors(NSArray.arrayWithObject(sortByName));
var sortDescriptor = NSSortDescriptor.sortDescriptorWithKey_ascending_selector(
"name", true, "localizedStandardCompare:"
);
allSymbols = allSymbols.sortedArrayUsingDescriptors([sortDescriptor]).mutableCopy();

var symbolWithSameID = library.document().symbolWithID(originalSymbolID);

Expand Down Expand Up @@ -173,7 +175,7 @@ function reloadSymbolData(context, view, symbol, library, checkboxSize) {
var imageView = NSImageView.alloc().initWithFrame(NSMakeRect(5, 5, itemHeight - 10, itemHeight - 10));
var layerAncestry = symbol_2.ancestry();
var symbolPreviewImage = MSSymbolPreviewGenerator.imageForSymbolAncestry_withSize_colorSpace_trimmed(
layerAncestry, CGSizeMake((itemHeight - 10) * 2, (itemHeight - 10) * 2), NSColorSpace.sRGBColorSpace(), true
layerAncestry, CGSizeMake((itemHeight - 10) * 2, (itemHeight - 10) * 2), NSColorSpace.sRGBColorSpace(), false
);
imageView.setImage(symbolPreviewImage);
itemView.addSubview(imageView);
Expand Down
Expand Up @@ -93,7 +93,7 @@ var onRun = function(context) {
var imageView = NSImageView.alloc().initWithFrame(NSMakeRect(35, 5, imageSize, imageSize));
var layerAncestry = unusedSymbol.ancestry();
var symbolPreviewImage = MSSymbolPreviewGenerator.imageForSymbolAncestry_withSize_colorSpace_trimmed(
layerAncestry, CGSizeMake(imageSize * 2, imageSize * 2), NSColorSpace.sRGBColorSpace(), true
layerAncestry, CGSizeMake(imageSize * 2, imageSize * 2), NSColorSpace.sRGBColorSpace(), false
);
var backgroundImage = NSImage.alloc().initWithContentsOfURL(context.plugin.urlForResourceNamed("bg_alpha.png"));
imageView.setWantsLayer(true);
Expand Down
Expand Up @@ -230,7 +230,7 @@ function symbolMasterThumb(symbolMaster) {
var size = 20;
var image = NSImage.alloc().initWithSize(CGSizeMake(size, size));
var symbolPreviewImage = MSSymbolPreviewGenerator.imageForSymbolAncestry_withSize_colorSpace_trimmed(
symbolMaster.ancestry(), CGSizeMake(size, size), NSColorSpace.sRGBColorSpace(), true
symbolMaster.ancestry(), CGSizeMake(size, size), NSColorSpace.sRGBColorSpace(), false
);
image.lockFocus();
symbolPreviewImage.drawAtPoint_fromRect_operation_fraction(
Expand Down
Expand Up @@ -229,9 +229,10 @@ function symbolThumbView(symbol, x, y, imageWidth, imageHeight, label) {
var imageView = NSImageView.alloc().initWithFrame(NSMakeRect(0, 0, imageWidth, imageHeight));
var layerAncestry = symbol.ancestry();
var symbolPreviewImage = MSSymbolPreviewGenerator.imageForSymbolAncestry_withSize_colorSpace_trimmed(
layerAncestry, CGSizeMake(imageWidth * 2, imageHeight * 2), NSColorSpace.sRGBColorSpace(), true
layerAncestry, CGSizeMake(imageWidth * 2, imageHeight * 2), NSColorSpace.sRGBColorSpace(), false
);
var backgroundImage = NSImage.alloc().initWithContentsOfFile("/Applications/Sketch.app/Contents/Resources/touchbar_color_alpha@2x.png");

var backgroundImage = NSImage.alloc().initWithContentsOfURL(context.plugin.urlForResourceNamed("bg_alpha.png"));
imageView.setWantsLayer(true);
imageView.setBackgroundColor(NSColor.colorWithPatternImage(backgroundImage));
imageView.setImage(symbolPreviewImage);
Expand Down
Expand Up @@ -130,8 +130,29 @@ var onRun = function(context) {
setPreferences(context, "ignoreLayerName", ignoreLayerNamesArray.toString());
}

var exportedSVGFiles = NSMutableArray.alloc().init();
var savePanel;
var savePath;
if (responseCode == 1000) {
if (selection.count() == 1) {
var fileName = fixedLayerName(selection.firstObject().name(), nameType.indexOfSelectedItem() + 1);
savePanel = NSSavePanel.savePanel();
savePanel.setTitle("Save as SVG");
savePanel.setShowsTagField(false);
savePanel.setNameFieldStringValue(fileName);
savePanel.setCanCreateDirectories(true);
} else {
savePanel = NSOpenPanel.openPanel();
savePanel.setMessage("Export select layers as SVG");
savePanel.setCanChooseDirectories(true);
savePanel.setCanChooseFiles(false);
savePanel.setCanCreateDirectories(true);
}
if (savePanel.runModal() == NSOKButton) {
savePath = savePanel.URL().path();
}
}

var exportedSVGFiles = NSMutableArray.alloc().init();
var loopSelection = selection.objectEnumerator();
var layer;
while (layer = loopSelection.nextObject()) {
Expand Down Expand Up @@ -264,50 +285,51 @@ var onRun = function(context) {
pboard.setString_forType_(svgCode, NSStringPboardType);
}

if (responseCode == 1000) {

var savePanel;
var savePath;
// if (responseCode == 1000) {

// var savePanel;
// var savePath;
// if (selection.count() == 1) {
// var fileName = fixedLayerName(selection.firstObject().name(), nameType.indexOfSelectedItem() + 1);
// savePanel = NSSavePanel.savePanel();
// savePanel.setTitle("Save as SVG");
// savePanel.setShowsTagField(false);
// savePanel.setNameFieldStringValue(fileName);
// savePanel.setCanCreateDirectories(true);
// } else {
// savePanel = NSOpenPanel.openPanel();
// savePanel.setMessage("Export select layers as SVG");
// savePanel.setCanChooseDirectories(true);
// savePanel.setCanChooseFiles(false);
// savePanel.setCanCreateDirectories(true);
// }
// if (savePanel.runModal() == NSOKButton) {
// savePath = savePanel.URL().path();
// }

if (savePath) {
var svgPath;
if (selection.count() == 1) {
var fileName = fixedLayerName(selection.firstObject().name(), nameType.indexOfSelectedItem() + 1);
savePanel = NSSavePanel.savePanel();
savePanel.setTitle("Save as SVG");
savePanel.setShowsTagField(false);
savePanel.setNameFieldStringValue(fileName);
savePanel.setCanCreateDirectories(true);
} else {
savePanel = NSOpenPanel.openPanel();
savePanel.setMessage("Export select layers as SVG");
savePanel.setCanChooseDirectories(true);
savePanel.setCanChooseFiles(false);
savePanel.setCanCreateDirectories(true);
}
if (savePanel.runModal() == NSOKButton) {
savePath = savePanel.URL().path();
}

if (savePath) {
var svgPath;
if (selection.count() == 1) {
if (savePath.pathExtension() != "svg") {
svgPath = savePath.stringByAppendingString(".svg");
} else {
svgPath = savePath;
}
if (savePath.pathExtension() != "svg") {
svgPath = savePath.stringByAppendingString(".svg");
} else {
var layerName = fixedLayerName(layer.name(), nameType.indexOfSelectedItem());
var fileName = NSString.stringWithString(layerName);
if (fileName.pathExtension() != "svg") {
fileName = fileName.stringByAppendingString(".svg");
}
svgPath = savePath.stringByAppendingPathComponent(fileName);
svgPath = savePath;
}
writeContentToFile(svgPath, svgCode);
exportedSVGFiles.addObject(NSURL.fileURLWithPath(svgPath));
} else {
var layerName = fixedLayerName(layer.name(), nameType.indexOfSelectedItem());
var fileName = NSString.stringWithString(layerName);
if (fileName.pathExtension() != "svg") {
fileName = fileName.stringByAppendingString(".svg");
}
svgPath = savePath.stringByAppendingPathComponent(fileName);
}
NSWorkspace.sharedWorkspace().activateFileViewerSelectingURLs(exportedSVGFiles);
writeContentToFile(svgPath, svgCode);
exportedSVGFiles.addObject(NSURL.fileURLWithPath(svgPath));
}

}

if (exportedSVGFiles.count() > 0) {
NSWorkspace.sharedWorkspace().activateFileViewerSelectingURLs(exportedSVGFiles);
}

}
Expand Down
Expand Up @@ -54,7 +54,7 @@ var onRun = function(context) {
var imageWrapper = NSView.alloc().initWithFrame(NSMakeRect(0, 0, thumbWidth, thumbHeight));
imageWrapper.setFlipped(true);
var imageView = NSImageView.alloc().initWithFrame(NSMakeRect(0, 0, thumbWidth, thumbHeight));
var backgroundImage = NSImage.alloc().initWithContentsOfFile("/Applications/Sketch.app/Contents/Resources/touchbar_color_alpha@2x.png");
var backgroundImage = NSImage.alloc().initWithContentsOfURL(context.plugin.urlForResourceNamed("bg_alpha.png"));
imageView.setWantsLayer(true);
imageView.setBackgroundColor(NSColor.colorWithPatternImage(backgroundImage));
imageView.setImage(resizedImage);
Expand Down
2 changes: 1 addition & 1 deletion automate-sketch.sketchplugin/Contents/Sketch/manifest.json
Expand Up @@ -5,7 +5,7 @@
"email": "Ashung.hung@gmail.com",
"homepage": "https://github.com/Ashung/Automate-Sketch",
"appcast": "https://ashung.github.io/Automate-Sketch/appcast.xml",
"version": "52.4.20181123",
"version": "52.5.20181213",
"identifier": "com.ashung.hung.automate_sketch",
"icon": "icon.png",
"suppliesData" : true,
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Expand Up @@ -65,6 +65,7 @@ Make your workflow more efficient.
| Resize to Fit Text Height | Resize text layer to fit text field height. |
| Toggle Auto and Fixed | Toggle selected text layers auto and fixed. |
| Unfixed Layer Name | Cancels the fixed layer name of the text layer so that the layer name of the text follows the content. |
| Charater Count | Charater cout from selected text layer or select range. |
| **Slice** | |
| Auto Slice | Create a slice based on layer with export preset. |
| Fast slice | Create a URL-friendly slice based on layer with export preset, without modal window. |
Expand Down Expand Up @@ -138,6 +139,8 @@ Make your workflow more efficient.
| Data - (Random) Text From File | Apply text data to text layer or overrides from text file. |
| **Prototyping** | |
| Bring All Hotspot to Front | Bring all hotspot layer to front. |
| Reset Flow | Reset flow. |
| Remove All Hotspot | Remove all hotspot layer. |
| **Development** | |
| Pick Color and Copy the HEX Code | Pick a color from screen and copy the HEX code. |
| Copy Slice as Base64 | The slice image is copied to Base64, depending on the format and scale of the first item of the slice, you can get a different image. |
Expand Down
3 changes: 3 additions & 0 deletions readme_zh.md
Expand Up @@ -66,6 +66,7 @@
| Resize to Fit Text Height | 自适应文本高度。 |
| Toggle Auto and Fixed | 切换选中文本图层的宽度自动和固定。 |
| Unfixed Layer Name | 取消文本图层的固定图层名,让文本的图层名跟随内容。 |
| Charater Count | 字数统计。 |
| **Slice** | **切片** |
| Auto Slice | 基于图层新建切片,并自动添加切片预设,可自定义切尺寸,有弹出层。 |
| Fast slice | 快速新建基于图层的切片,并自动添加切片预设,切片名称会修改会开发友好名称,无弹出层。 |
Expand Down Expand Up @@ -139,6 +140,8 @@
| Data - (Random) Text From File | 从文本文件获取文本数据,并随机或有序应用到文本图层或组件override上。 |
| **Prototyping** | **原型** |
| Bring All Hotspot to Front | 置顶所有热区图层。 |
| Reset Flow | 重置 flow 设置。 |
| Remove All Hotspot | 删除所有 hotspot 图层和设置。 |
| **Development** | **开发** |
| Pick Color and Copy the HEX Code | 从屏幕取色并负责色彩的十六进制值。 |
| Copy Slice as Base64 | 切片图像复制为 Base64,根据切片第一项设置的格式和缩放,可以得到不同图像。 |
Expand Down

0 comments on commit 7bc528d

Please sign in to comment.