Skip to content

Commit fcaf7fd

Browse files
committed
Added preferences saving and load with defaults
1 parent df55700 commit fcaf7fd

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ui extends Element {
4848
xspacing="${this.data.preferences.spacing.x}"
4949
yspacing="${this.data.preferences.spacing.y}"
5050
startname="${this.data.preferences.start_name}"
51+
wrapinstances="${this.data.preferences.wrap_instances}"
5152
renamestrategy="${this.data.preferences.rename_strategy}"
5253
>
5354
</v-form>

src/Core.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function cmdReorder() {
8787
})
8888
}
8989

90-
function cmdTidy(xSpacing, ySpacing) {
90+
function cmdTidy(xSpacing, ySpacing, wrapInstances) {
9191
var selection = figma.currentPage.selection
9292
var parent = (selection[0].type == 'PAGE') ? figma.currentPage : selection[0].parent
9393
var allNodes = parent.children
@@ -122,7 +122,7 @@ function cmdTidy(xSpacing, ySpacing) {
122122
var newYPos = yPos
123123

124124
// Wrap instances with a frame around
125-
if (match.type == 'INSTANCE') {
125+
if (wrapInstances && match.type == 'INSTANCE') {
126126
var instanceParent = figma.createFrame()
127127
instanceParent.x = newXPos
128128
instanceParent.y = newYPos
@@ -156,11 +156,13 @@ Promise.all([
156156

157157
let SPACING = { x: 100, y: 200 }
158158
let START_NAME = '000'
159+
let WRAP_INSTANCES = true
159160
let RENAME_STRATEGY_REPLACE = 'replace'
160161
let RENAME_STRATEGY_MERGE = 'merge'
161162
let PREFERENCES = {
162163
spacing: SPACING,
163164
start_name: START_NAME,
165+
wrap_instances: WRAP_INSTANCES,
164166
rename_strategy: RENAME_STRATEGY_REPLACE
165167
}
166168

@@ -195,13 +197,13 @@ Promise.all([
195197
} else
196198
if (cmd == 'tidy') {
197199
// RUNS WITHOUT UI
198-
cmdTidy(preferences.spacing.x, preferences.spacing.y)
200+
cmdTidy(preferences.spacing.x, preferences.spacing.y, preferences.wrap_instances)
199201
figma.notify('Super Tidy: Tidy')
200202
setTimeout(() => figma.closePlugin(), 100)
201203
} else
202204
if (cmd == 'all') {
203205
// RUNS WITHOUT UI
204-
cmdTidy(preferences.spacing.x, preferences.spacing.y)
206+
cmdTidy(preferences.spacing.x, preferences.spacing.y, preferences.wrap_instances)
205207
cmdReorder()
206208
cmdRename(preferences.rename_strategy, preferences.start_name)
207209
figma.notify('Super Tidy')
@@ -223,7 +225,7 @@ Promise.all([
223225
var REORDER_ENABLED = msg.options.reorder
224226
var TIDY_ENABLED = msg.options.tidy
225227

226-
if (TIDY_ENABLED) cmdTidy(preferences.spacing.x, preferences.spacing.y)
228+
if (TIDY_ENABLED) cmdTidy(preferences.spacing.x, preferences.spacing.y, preferences.wrap_instances)
227229
if (RENAMING_ENABLED) cmdRename(preferences.rename_strategy, preferences.start_name)
228230
if (REORDER_ENABLED) cmdReorder()
229231
figma.notify('Super Tidy')

src/ui/views/preferences/PreferencesView.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ class PreferencesView extends Element {
1212
let x_spacing = this.find('#x_spacing').value
1313
let y_spacing = this.find('#y_spacing').value
1414
let starting_name = this.find('#starting_name').value
15+
let wrap_instances = this.find('#wrap_instances').checked
1516
let rename_trategy = this.find('#rename_strategy [selected]').getAttribute('data-value')
1617

1718
let preferences = {
1819
spacing: { x: parseInt(x_spacing), y: parseInt(y_spacing) },
1920
start_name: starting_name,
21+
wrap_instances: wrap_instances,
2022
rename_strategy: rename_trategy
2123
}
2224

@@ -32,7 +34,7 @@ class PreferencesView extends Element {
3234
})
3335
}
3436

35-
render() {
37+
render() {
3638
return `
3739
<form id="preferences" action="#">
3840
<fieldset>
@@ -58,6 +60,18 @@ class PreferencesView extends Element {
5860
</label>
5961
</fieldset>
6062
63+
<label>
64+
<strong>Wrap instances with frames</strong>
65+
<p>When using the Tidy action, all instances will be wrapped with a frame of the same dimensions.</p>
66+
67+
<label class="switch">
68+
<div class="switch__container">
69+
<input id="wrap_instances" type="checkbox" class="switch__checkbox" ${(this.attrs.wrapinstances == 'true') ? 'checked' : ''}>
70+
<span class="switch__slider"></span>
71+
</div>
72+
</label>
73+
</label>
74+
6175
<label>
6276
<strong>Starting frame number</strong>
6377
<p>Renames your frames starting from the given number when using the Rename action.</p>

0 commit comments

Comments
 (0)