Skip to content

Commit 819e59d

Browse files
Improved settings
1 parent 3909604 commit 819e59d

File tree

1 file changed

+39
-46
lines changed

1 file changed

+39
-46
lines changed

src/settings.ts

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,19 @@ export class AdvancedCanvasPluginSettingTab extends PluginSettingTab {
9898

9999
containerEl.createEl('h1', { cls: 'main-header', text: 'Advanced Canvas' })
100100

101-
new Setting(containerEl)
102-
.setHeading()
103-
.setName("Shapes")
104-
.setDesc("Shape your nodes for creating e.g. mind maps or flow charts.")
105-
.addToggle((toggle) =>
106-
toggle
107-
.setTooltip("Requires a reload to take effect.")
108-
.setValue(this.settingsManager.getSetting('shapesFeatureEnabled'))
109-
.onChange(async (value) => await this.settingsManager.setSetting({ shapesFeatureEnabled: value }))
110-
)
111-
112-
new Setting(containerEl)
113-
.setHeading()
114-
.setName("Extended Commands")
115-
.setDesc("Add more commands to the canvas.")
116-
.addToggle((toggle) =>
117-
toggle
118-
.setTooltip("Requires a reload to take effect.")
119-
.setValue(this.settingsManager.getSetting('commandsFeatureEnabled'))
120-
.onChange(async (value) => await this.settingsManager.setSetting({ commandsFeatureEnabled: value }))
121-
)
101+
this.createFeatureHeading(
102+
containerEl,
103+
"Shapes",
104+
"Shape your nodes for creating e.g. mind maps or flow charts.",
105+
'shapesFeatureEnabled'
106+
)
107+
108+
this.createFeatureHeading(
109+
containerEl,
110+
"Extended Commands",
111+
"Add more commands to the canvas.",
112+
'commandsFeatureEnabled'
113+
)
122114

123115
new Setting(containerEl)
124116
.setName("Zoom to cloned node")
@@ -147,16 +139,12 @@ export class AdvancedCanvasPluginSettingTab extends PluginSettingTab {
147139
.onChange(async (value) => await this.settingsManager.setSetting({ expandNodeStepSize: parseInt(value) }))
148140
)
149141

150-
new Setting(containerEl)
151-
.setHeading()
152-
.setName("Better readonly")
153-
.setDesc("Improve the readonly mode.")
154-
.addToggle((toggle) =>
155-
toggle
156-
.setTooltip("Requires a reload to take effect.")
157-
.setValue(this.settingsManager.getSetting('betterReadonlyEnabled'))
158-
.onChange(async (value) => await this.settingsManager.setSetting({ betterReadonlyEnabled: value }))
159-
)
142+
this.createFeatureHeading(
143+
containerEl,
144+
"Better readonly",
145+
"Improve the readonly mode.",
146+
'betterReadonlyEnabled'
147+
)
160148

161149
/* Would require a solution to sync the settings with the canvas */
162150
/*new Setting(containerEl)
@@ -195,16 +183,12 @@ export class AdvancedCanvasPluginSettingTab extends PluginSettingTab {
195183
.onChange(async (value) => await this.settingsManager.setSetting({ disablePan: value }))
196184
)*/
197185

198-
new Setting(containerEl)
199-
.setHeading()
200-
.setName("Presentations")
201-
.setDesc("Create a presentation from your canvas.")
202-
.addToggle((toggle) =>
203-
toggle
204-
.setTooltip("Requires a reload to take effect.")
205-
.setValue(this.settingsManager.getSetting('presentationFeatureEnabled'))
206-
.onChange(async (value) => await this.settingsManager.setSetting({ presentationFeatureEnabled: value }))
207-
)
186+
this.createFeatureHeading(
187+
containerEl,
188+
"Presentations",
189+
"Create a presentation from your canvas.",
190+
'presentationFeatureEnabled'
191+
)
208192

209193
new Setting(containerEl)
210194
.setName("Default slize ratio")
@@ -252,15 +236,24 @@ export class AdvancedCanvasPluginSettingTab extends PluginSettingTab {
252236
.onChange(async (value) => await this.settingsManager.setSetting({ slideTransitionAnimationIntensity: parseFloat(value) }))
253237
)
254238

255-
new Setting(containerEl)
239+
this.createFeatureHeading(
240+
containerEl,
241+
"Canvas encapsulation",
242+
"Encapsulate a selection of nodes and edges into a new canvas.",
243+
'canvasEncapsulationEnabled'
244+
)
245+
}
246+
247+
private createFeatureHeading(containerEl: HTMLElement, label: string, description: string, settingsKey: keyof AdvancedCanvasPluginSettings): Setting {
248+
return new Setting(containerEl)
256249
.setHeading()
257-
.setName("Canvas encapsulation")
258-
.setDesc("Encapsulate a selection of nodes and edges into a new canvas.")
250+
.setName(label)
251+
.setDesc(description)
259252
.addToggle((toggle) =>
260253
toggle
261254
.setTooltip("Requires a reload to take effect.")
262-
.setValue(this.settingsManager.getSetting('canvasEncapsulationEnabled'))
263-
.onChange(async (value) => await this.settingsManager.setSetting({ canvasEncapsulationEnabled: value }))
255+
.setValue(this.settingsManager.getSetting(settingsKey) as boolean)
256+
.onChange(async (value) => await this.settingsManager.setSetting({ [settingsKey]: value }))
264257
)
265258
}
266259
}

0 commit comments

Comments
 (0)