generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
59 lines (44 loc) · 1.3 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { App, Plugin, PluginSettingTab, Setting } from 'obsidian';
interface PluginSettings {
folder: string;
}
const DEFAULT_SETTINGS: PluginSettings = {
folder: ''
}
class RibbonButtonPluginSettingTab extends PluginSettingTab {
plugin: RibbonButtonPlugin;
constructor(app: App, plugin: RibbonButtonPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
new Setting(containerEl)
.setName('Folder')
.addText(text => text
.setPlaceholder('My Folder')
.setValue(this.plugin.settings.folder)
.onChange(async (value) => {
this.plugin.settings.folder = value;
await this.plugin.saveSettings();
}));
}
}
export default class RibbonButtonPlugin extends Plugin {
settings: PluginSettings;
async onload() {
await this.loadSettings();
const ribbonIconEl = this.addRibbonIcon('banana', 'Mikala\'s Button', (evt: MouseEvent) => {
this.app.vault.create(this.settings.folder + '/Untitled.md', '');
});
ribbonIconEl.addClass('my-plugin-ribbon-class');
this.addSettingTab(new RibbonButtonPluginSettingTab(this.app, this));
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}