tekknoman_obsidian-prio-plugin/main.ts

90 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

2023-03-09 13:32:09 +00:00
import {Editor, MarkdownView, Plugin} from 'obsidian';
import {PrioPluginSettings} from "./utils/Settings";
import {SettingTab} from "./utils/SettingTab";
import {decreasePrio, increasePrio, removePrio, setPrio} from "./utils/Priority";
const DEFAULT_SETTINGS: PrioPluginSettings = {
2023-03-08 13:42:10 +00:00
levels: 6,
levelAliases: [
'Major',
'Minor',
'Trivial',
'Cosmetic',
'Enhancement',
'Bug'
],
presets: [{
id: 'default',
name: 'Default',
settings: {
2023-03-08 13:42:10 +00:00
levels: 6,
levelAliases: [
'Major',
'Minor',
'Trivial',
'Cosmetic',
'Enhancement',
'Bug'
],
}
}]
2023-03-08 07:13:43 +00:00
}
export default class PrioPlugin extends Plugin {
settings: PrioPluginSettings;
2023-03-08 07:13:43 +00:00
async onload() {
await this.loadSettings();
this.addCommand({
id: 'set-prio',
name: 'Set priority',
editorCallback: (editor: Editor, view: MarkdownView) => {
setPrio(editor, view, this.settings);
2023-03-16 06:48:44 +00:00
}
2023-03-08 07:13:43 +00:00
});
2023-03-08 07:13:43 +00:00
this.addCommand({
id: 'remove-prio',
name: 'Remove priority',
2023-03-08 07:13:43 +00:00
editorCallback: (editor: Editor, view: MarkdownView) => {
removePrio(editor, view, this.settings);
2023-03-16 06:48:44 +00:00
}
})
this.addCommand({
id: 'increase-prio',
name: 'Increase priority',
editorCallback: (editor: Editor, view: MarkdownView) => {
increasePrio(editor, view, this.settings);
2023-03-16 06:48:44 +00:00
}
2023-03-08 07:13:43 +00:00
});
// This adds a complex command that can check whether the current state of the app allows execution of the command
this.addCommand({
id: 'decrease-prio',
name: 'Decrease priority',
editorCallback: (editor: Editor, view: MarkdownView) => {
decreasePrio(editor, view, this.settings);
2023-03-16 06:48:44 +00:00
}
2023-03-08 07:13:43 +00:00
});
// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SettingTab(this.app, this));
2023-03-08 07:13:43 +00:00
}
onunload() {
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}