separate settings to another file
This commit is contained in:
parent
8db1b06aac
commit
7dd1911042
35
src/main.ts
35
src/main.ts
|
@ -1,13 +1,5 @@
|
||||||
import { Plugin, PluginSettingTab, Setting } from 'obsidian';
|
import { Plugin } from 'obsidian';
|
||||||
|
import { DEFAULT_SETTINGS, MyPluginSettings, SampleSettingTab } from './settings';
|
||||||
|
|
||||||
interface MyPluginSettings {
|
|
||||||
mySetting: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const DEFAULT_SETTINGS: MyPluginSettings = {
|
|
||||||
mySetting: 'default'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export default class MyPlugin extends Plugin {
|
export default class MyPlugin extends Plugin {
|
||||||
|
@ -31,26 +23,3 @@ export default class MyPlugin extends Plugin {
|
||||||
await this.saveData(this.settings);
|
await this.saveData(this.settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SampleSettingTab extends PluginSettingTab {
|
|
||||||
constructor(public plugin: MyPlugin) {
|
|
||||||
super(plugin.app, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
display(): void {
|
|
||||||
const {containerEl} = this;
|
|
||||||
containerEl.empty();
|
|
||||||
|
|
||||||
new Setting(containerEl)
|
|
||||||
.setName('Setting #1')
|
|
||||||
.setDesc('It\'s a secret')
|
|
||||||
.addText(text => text
|
|
||||||
.setPlaceholder('Enter your secret')
|
|
||||||
.setValue(this.plugin.settings.mySetting)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.mySetting = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import { PluginSettingTab, Setting } from 'obsidian';
|
||||||
|
import MyPlugin from './main';
|
||||||
|
|
||||||
|
|
||||||
|
export interface MyPluginSettings {
|
||||||
|
mySetting: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_SETTINGS: MyPluginSettings = {
|
||||||
|
mySetting: 'default'
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SampleSettingTab extends PluginSettingTab {
|
||||||
|
constructor(public plugin: MyPlugin) {
|
||||||
|
super(plugin.app, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
display(): void {
|
||||||
|
const {containerEl} = this;
|
||||||
|
containerEl.empty();
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Setting #1')
|
||||||
|
.setDesc('It\'s a secret')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('Enter your secret')
|
||||||
|
.setValue(this.plugin.settings.mySetting)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.mySetting = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue