Skip to content

Commit

Permalink
Add paste center option
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancisVega committed Oct 27, 2018
1 parent 9793638 commit 14581a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion appcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<item>
<enclosure url="https://github.com/FrancisVega/sketch-copy-paste-layout-settings/releases/download/1.1/sketch-copy-paste-layout-settings.1.1.zip" sparkle:version="1.1"/>
<enclosure url="https://github.com/FrancisVega/sketch-copy-paste-layout-settings/files/2521679/sketch-layout-settings.sketchplugin.1.2.zip" sparkle:version="1.2"/>

</item>
</channel>
</rss>
12 changes: 10 additions & 2 deletions sketch-layout-settings.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Francis Vega",
"email": "[email protected]",
"homepage": "",
"version": "1.1",
"version": "1.2",
"identifier": "com.example.sketch.layoutsettings",
"appcast": "https://raw.githubusercontent.com/FrancisVega/sketch-copy-paste-layout-settings/master/appcast.xml",
"compatibleVersion": "40",
Expand All @@ -26,10 +26,18 @@
"run": "pasteSettings"
},
"script": "sketch-layout-settings.js"
},
{
"name": "Paste Layout/Grid (Center)",
"identifier": "pastecenterlayoutsettings",
"handlers": {
"run": "pasteCenterSettings"
},
"script": "sketch-layout-settings.js"
}
],
"menu": {
"title": "Layout Settings",
"items": ["copylayoutsettings", "pastelayoutsettings"]
"items": ["copylayoutsettings", "pastelayoutsettings", "pastecenterlayoutsettings"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ function copySettings (context) {
writeFile(`${NSHomeDirectory()}/${TEMP_FILE_NAME}`, JSON.stringify(data));
}

function pasteSettings (context) {
function pasteCenterSettings(context) {
pasteSettings(context, true)
}

function pasteSettings (context, isCenter) {
const data = readFile(`${NSHomeDirectory()}/${TEMP_FILE_NAME}`);
const layoutSetting = data.layout;
const gridSetting = data.grid;
Expand All @@ -80,7 +84,13 @@ function pasteSettings (context) {

layout.setDrawVertical(layoutSetting.drawVertical);
layout.setTotalWidth(layoutSetting.totalWidth);
layout.setHorizontalOffset(layoutSetting.horizontalOffset);

if (isCenter) {
layout.setHorizontalOffset(artboard.frame().width() - layoutSetting.totalWidth) / 2;
} else {
layout.setHorizontalOffset(layoutSetting.horizontalOffset);
}

layout.setNumberOfColumns(layoutSetting.numberOfColumns);
layout.setGuttersOutside(layoutSetting.guttersOutside);

Expand Down

0 comments on commit 14581a0

Please sign in to comment.