tekknoman_obsidian-prio-plugin/main.ts

153 lines
3.5 KiB
TypeScript
Raw Normal View History

2023-03-08 13:42:10 +00:00
import {App, Editor, MarkdownView, Modal, Notice, 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 = {
selectedPreset: 'default',
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 creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => {
// Called when the user clicks the icon.
new Notice('This is a notice!');
});
// Perform additional things with the ribbon
ribbonIconEl.addClass('my-plugin-ribbon-class');
// This adds a status bar item to the bottom of the app. Does not work on mobile apps.
const statusBarItemEl = this.addStatusBarItem();
statusBarItemEl.setText('Status Bar Text');
2023-03-08 07:13:43 +00:00
this.addCommand({
id: 'set-prio',
name: 'Set priority',
editorCallback: (editor: Editor, view: MarkdownView) => {
setPrio(editor, view, this.settings);
},
hotkeys: [
{
modifiers: ['Ctrl', 'Shift', 'Alt'],
key: 'p',
}
]
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);
},
hotkeys: [
{
modifiers: ['Ctrl', 'Shift', 'Alt'],
key: 'd',
}
]
})
this.addCommand({
id: 'increase-prio',
name: 'Increase priority',
editorCallback: (editor: Editor, view: MarkdownView) => {
increasePrio(editor, view, this.settings);
},
hotkeys: [
{
modifiers: ['Ctrl', 'Shift', 'Alt'],
key: 'ArrowUp',
}
]
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);
},
hotkeys: [
{
modifiers: ['Ctrl', 'Shift', 'Alt'],
key: 'ArrowDown',
2023-03-08 07:13:43 +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
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
// Using this function will automatically remove the event listener when this plugin is disabled.
this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
console.log('click', evt);
});
// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
}
onunload() {
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}
class SampleModal extends Modal {
constructor(app: App) {
super(app);
}
onOpen() {
const {contentEl} = this;
contentEl.setText('Woah!');
}
onClose() {
const {contentEl} = this;
contentEl.empty();
}
}