Skip to content

Commit

Permalink
Merge pull request #71 from DWilliames/v1.0.6
Browse files Browse the repository at this point in the history
V1.0.6
  • Loading branch information
DWilliames authored Mar 7, 2018
2 parents cbf42f9 + 328c921 commit 4f1fa6d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .appcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<link>https://raw.githubusercontent.com/DWilliames/paddy-sketch-plugin/master/.appcast.xml</link>
<description>Automated padding, spacing and alignment for your Sketch layers</description>
<language>en</language>
<item>
<title>Version 1.0.6</title>
<description>Squashed some more bugs</description>
<enclosure url="https://github.com/DWilliames/paddy-sketch-plugin/releases/download/v1.0.6/Paddy.sketchplugin.zip" sparkle:version="1.0.6" />
</item>
<item>
<title>Version 1.0.5</title>
<description>More bug fixes</description>
Expand Down
1 change: 1 addition & 0 deletions Paddy.sketchplugin/Contents/Sketch/async.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Work in progress

function loadFramework(name, className) {
if (NSClassFromString(className) == null) {
Expand Down
23 changes: 17 additions & 6 deletions Paddy.sketchplugin/Contents/Sketch/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function getContainerFrameForBGLayer(bg) {
return false
if (layer.isMemberOfClass(MSSliceLayer))
return false
if (layer.name().startsWith('-'))
if (shouldLayerBeIgnored(layer))
return false
return true
})
Expand All @@ -36,13 +36,24 @@ function getContainerFrameForBGLayer(bg) {
}


// If the layer should be ignored when calculating the rect of a layer
function shouldLayerBeIgnored(layer) {
if (!layer) return

if (layer.name().startsWith('-')) {
return true
}

return false
}

// Whether to check for Stack Groups
var takeIntoAccountStackViews = true


// Return the rect for a layer as an MSRect
function rectForLayer(layer, ignoreWithPrefix) {
if (!layer || (ignoreWithPrefix && layer.name().startsWith('-'))) {
if (!layer || (ignoreWithPrefix && shouldLayerBeIgnored(layer))) {
return
}

Expand Down Expand Up @@ -161,7 +172,7 @@ function getBGCandidateFromLayers(layers) {

var candidate
var existingBackground = layers.find(function(layer) {
if (layer.name().startsWith('-'))
if (shouldLayerBeIgnored(layer))
return false

if (canLayerHavePadding(layer)) {
Expand Down Expand Up @@ -451,13 +462,13 @@ function resizeLayer(layer) {
// A hack for resizing – just in case Craft's Duplicator is installed
// Select a 'Fake' layer, so that when we 'resize', the selection is not empty
var nullLayer = MSLayer.alloc().init()
nullLayer.name = "NULL LAYER"
nullLayer.name = "PADDY-NULL-LAYER"
document.currentPage().addLayer(nullLayer)
nullLayer.select_byExtendingSelection(true, true)
nullLayer.select_byExpandingSelection(true, false)

layer.layerDidEndResize()

nullLayer.select_byExtendingSelection(false, false)
nullLayer.select_byExpandingSelection(false, false)
nullLayer.removeFromParent()
}

Expand Down
35 changes: 22 additions & 13 deletions Paddy.sketchplugin/Contents/Sketch/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ var layers = []

function selectionChanged(context) {

var newSelection = context.actionContext.newSelection

if (!automated) {
COScript.currentCOScript().setShouldKeepAround(false)
return
Expand All @@ -325,13 +327,28 @@ function selectionChanged(context) {
COScript.currentCOScript().setShouldKeepAround(true)
}

runInBackground(function() {

layers = []

startBenchmark()
document = context.actionContext.document

// print('Selection changed - OLD/NEW')
// print(context.actionContext.oldSelection)
// print(context.actionContext.newSelection)

if (newSelection.length == 1 && newSelection[0].name() == "PADDY-NULL-LAYER") {
// The selection was becuase of the 'Null layer' used to resolve Craft's stupid Duplicator conflict!!!

log('Selected the NULL layer; will reselect', context.actionContext.oldSelection)

context.actionContext.oldSelection.forEach(function(layer) {
layer.select_byExpandingSelection(true, true)
})

COScript.currentCOScript().setShouldKeepAround(false)
return
}


// Only include layers that had properties change
// Particularly if their frame or position changed
Expand All @@ -350,16 +367,15 @@ function selectionChanged(context) {
if (!persistentLayers) persistentLayers = []

// Only run if nothing is now selected
if (context.actionContext.newSelection.length > 0) {

if (newSelection.length > 0) {

var previouslySelectedParentProps = initialParentProps

initialSelectedProps = {}
initialParentProps = {}
persistentLayers = []

context.actionContext.newSelection.forEach(function(layer) {
newSelection.forEach(function(layer) {

var rect = layer.absoluteRect() //rectForLayer(layer)
var props = {
Expand Down Expand Up @@ -414,11 +430,6 @@ function selectionChanged(context) {
saveValueWithKeyToDoc(initialParentProps, previousParentKey)
saveValueWithKeyToDoc(persistentLayers, persistentLayersKey)

context.actionContext.newSelection.forEach(function(layer) {
layer.select_byExpandingSelection(true, true)
})


return
}

Expand Down Expand Up @@ -510,8 +521,6 @@ function selectionChanged(context) {
COScript.currentCOScript().setShouldKeepAround(false)
}

})

}


Expand Down Expand Up @@ -571,7 +580,7 @@ function updatePaddingAndSpacingForLayer(layer) {

var updateInstances = true

if (total >= 5) {
if (total >= 10) {
// if there are more than 10 to update... ask the user if this is what they want to do

var iconImage = NSImage.alloc().initByReferencingFile(plugin.urlForResourceNamed("icon.png").path())
Expand Down
4 changes: 2 additions & 2 deletions Paddy.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "David Williames",
"homepage": "https://github.com/DWilliames/paddy-sketch-plugin",
"appcast": "https://raw.githubusercontent.com/DWilliames/paddy-sketch-plugin/master/.appcast.xml",
"version": "1.0.5",
"version": "1.0.6",
"identifier": "com.davidwilliames.sketch-plugin.paddy",
"compatibleVersion": 47,
"bundleVersion": 1,
Expand All @@ -21,7 +21,7 @@
{
"name": "Imply padding for selection",
"identifier": "autoApplyPadding",
"shortcut": "command p",
"shortcut": "command shift p",
"script": "main.js",
"handler": "autoApplyPadding",
"description": "Apply implied padding to the currently selected layers",
Expand Down
2 changes: 1 addition & 1 deletion Paddy.sketchplugin/Contents/Sketch/spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function applySpacingToGroup(spacing, groupLayer) {
return false
if (layer.isMemberOfClass(MSSliceLayer))
return false
if (layer.name().startsWith('-'))
if (shouldLayerBeIgnored(layer))
return false
return true
})
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Examples:

Run the plugin command **'Enter padding for selection'** or **`Control + Alt + p`** to bring up an input field, to save padding to all your selected layers easier.

If you don't want to be prompted to enter the specified padding, and instead want it to be automatically inferred from what it already is – run the command **'Imply padding for selection'** or **`Command + p`**.
If you don't want to be prompted to enter the specified padding, and instead want it to be automatically inferred from what it already is – run the command **'Imply padding for selection'** or **`Command + shift + p`**.

![Padding example](.images/GIFs/padding.gif)

Expand Down

0 comments on commit 4f1fa6d

Please sign in to comment.