From 7bc528d17284a4dddd6bb0570ee3fdb858654eb3 Mon Sep 17 00:00:00 2001 From: Ashung Date: Thu, 13 Dec 2018 19:30:07 +0800 Subject: [PATCH] - Symbol list in Replace Symbol With Library Symbol now sorted like Finder. - Fix bug when Export Clean Code SVG opening export window for each selection. #123 --- .../Contents/Resources/manifest_en.json | 2 +- .../Contents/Resources/manifest_zh_Hans.json | 2 +- .../Contents/Resources/manifest_zh_Hant.json | 2 +- ...e_Local_Style_to_Library_Style.cocoascript | 2 +- .../Imported_Symbols_Link_Manage.cocoascript | 2 +- ...ace_Symbol_With_Library_Symbol.cocoascript | 8 +- .../Remove_Unused_Symbols_New.cocoascript | 2 +- .../Replace_Override_Symbol.cocoascript | 2 +- ...Symbol_Master_from_Sketch_File.cocoascript | 5 +- .../Export_Clean_Code_SVG.cocoascript | 102 +++++++++++------- .../Nine_Slice_From_Bitmap_Layer.cocoascript | 2 +- .../Contents/Sketch/manifest.json | 2 +- readme.md | 3 + readme_zh.md | 3 + 14 files changed, 85 insertions(+), 54 deletions(-) diff --git a/automate-sketch.sketchplugin/Contents/Resources/manifest_en.json b/automate-sketch.sketchplugin/Contents/Resources/manifest_en.json index 93ee2e7d..be5283c8 100644 --- a/automate-sketch.sketchplugin/Contents/Resources/manifest_en.json +++ b/automate-sketch.sketchplugin/Contents/Resources/manifest_en.json @@ -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, diff --git a/automate-sketch.sketchplugin/Contents/Resources/manifest_zh_Hans.json b/automate-sketch.sketchplugin/Contents/Resources/manifest_zh_Hans.json index bc1d4ee6..ba0ca6b1 100644 --- a/automate-sketch.sketchplugin/Contents/Resources/manifest_zh_Hans.json +++ b/automate-sketch.sketchplugin/Contents/Resources/manifest_zh_Hans.json @@ -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, diff --git a/automate-sketch.sketchplugin/Contents/Resources/manifest_zh_Hant.json b/automate-sketch.sketchplugin/Contents/Resources/manifest_zh_Hant.json index 64bf00fa..ab934699 100644 --- a/automate-sketch.sketchplugin/Contents/Resources/manifest_zh_Hant.json +++ b/automate-sketch.sketchplugin/Contents/Resources/manifest_zh_Hant.json @@ -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, diff --git a/automate-sketch.sketchplugin/Contents/Sketch/Library/Change_Local_Style_to_Library_Style.cocoascript b/automate-sketch.sketchplugin/Contents/Sketch/Library/Change_Local_Style_to_Library_Style.cocoascript index 0b3e9f25..3b003355 100644 --- a/automate-sketch.sketchplugin/Contents/Sketch/Library/Change_Local_Style_to_Library_Style.cocoascript +++ b/automate-sketch.sketchplugin/Contents/Sketch/Library/Change_Local_Style_to_Library_Style.cocoascript @@ -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()); } } }); diff --git a/automate-sketch.sketchplugin/Contents/Sketch/Library/Imported_Symbols_Link_Manage.cocoascript b/automate-sketch.sketchplugin/Contents/Sketch/Library/Imported_Symbols_Link_Manage.cocoascript index 92dc19ec..4da1e596 100644 --- a/automate-sketch.sketchplugin/Contents/Sketch/Library/Imported_Symbols_Link_Manage.cocoascript +++ b/automate-sketch.sketchplugin/Contents/Sketch/Library/Imported_Symbols_Link_Manage.cocoascript @@ -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); diff --git a/automate-sketch.sketchplugin/Contents/Sketch/Library/Replace_Symbol_With_Library_Symbol.cocoascript b/automate-sketch.sketchplugin/Contents/Sketch/Library/Replace_Symbol_With_Library_Symbol.cocoascript index 42131b86..27b919e0 100644 --- a/automate-sketch.sketchplugin/Contents/Sketch/Library/Replace_Symbol_With_Library_Symbol.cocoascript +++ b/automate-sketch.sketchplugin/Contents/Sketch/Library/Replace_Symbol_With_Library_Symbol.cocoascript @@ -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); @@ -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); diff --git a/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Remove_Unused_Symbols_New.cocoascript b/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Remove_Unused_Symbols_New.cocoascript index 11555d83..1332b281 100644 --- a/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Remove_Unused_Symbols_New.cocoascript +++ b/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Remove_Unused_Symbols_New.cocoascript @@ -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); diff --git a/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Replace_Override_Symbol.cocoascript b/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Replace_Override_Symbol.cocoascript index 75975899..27dfb48b 100644 --- a/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Replace_Override_Symbol.cocoascript +++ b/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Replace_Override_Symbol.cocoascript @@ -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( diff --git a/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Sync_Symbol_Master_from_Sketch_File.cocoascript b/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Sync_Symbol_Master_from_Sketch_File.cocoascript index ce318ddf..664e98e2 100644 --- a/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Sync_Symbol_Master_from_Sketch_File.cocoascript +++ b/automate-sketch.sketchplugin/Contents/Sketch/Symbol/Sync_Symbol_Master_from_Sketch_File.cocoascript @@ -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); diff --git a/automate-sketch.sketchplugin/Contents/Sketch/Utilities/Export_Clean_Code_SVG.cocoascript b/automate-sketch.sketchplugin/Contents/Sketch/Utilities/Export_Clean_Code_SVG.cocoascript index 07fef45d..2fb5f2c6 100644 --- a/automate-sketch.sketchplugin/Contents/Sketch/Utilities/Export_Clean_Code_SVG.cocoascript +++ b/automate-sketch.sketchplugin/Contents/Sketch/Utilities/Export_Clean_Code_SVG.cocoascript @@ -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()) { @@ -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); } } diff --git a/automate-sketch.sketchplugin/Contents/Sketch/Utilities/Nine_Slice_From_Bitmap_Layer.cocoascript b/automate-sketch.sketchplugin/Contents/Sketch/Utilities/Nine_Slice_From_Bitmap_Layer.cocoascript index b05950fc..e9eb3a7a 100644 --- a/automate-sketch.sketchplugin/Contents/Sketch/Utilities/Nine_Slice_From_Bitmap_Layer.cocoascript +++ b/automate-sketch.sketchplugin/Contents/Sketch/Utilities/Nine_Slice_From_Bitmap_Layer.cocoascript @@ -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); diff --git a/automate-sketch.sketchplugin/Contents/Sketch/manifest.json b/automate-sketch.sketchplugin/Contents/Sketch/manifest.json index 93ee2e7d..be5283c8 100644 --- a/automate-sketch.sketchplugin/Contents/Sketch/manifest.json +++ b/automate-sketch.sketchplugin/Contents/Sketch/manifest.json @@ -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, diff --git a/readme.md b/readme.md index c7784ef8..75761a5d 100644 --- a/readme.md +++ b/readme.md @@ -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. | @@ -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. | diff --git a/readme_zh.md b/readme_zh.md index fb61ee1d..d5e38d99 100644 --- a/readme_zh.md +++ b/readme_zh.md @@ -66,6 +66,7 @@ | Resize to Fit Text Height | 自适应文本高度。 | | Toggle Auto and Fixed | 切换选中文本图层的宽度自动和固定。 | | Unfixed Layer Name | 取消文本图层的固定图层名,让文本的图层名跟随内容。 | +| Charater Count | 字数统计。 | | **Slice** | **切片** | | Auto Slice | 基于图层新建切片,并自动添加切片预设,可自定义切尺寸,有弹出层。 | | Fast slice | 快速新建基于图层的切片,并自动添加切片预设,切片名称会修改会开发友好名称,无弹出层。 | @@ -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,根据切片第一项设置的格式和缩放,可以得到不同图像。 |