mirror of
https://github.com/tekknoman/obsidian-prio-plugin.git
synced 2026-07-22 07:30:23 +00:00
152 lines
3.5 KiB
TypeScript
152 lines
3.5 KiB
TypeScript
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',
|
|
levels: 6,
|
|
levelAliases: [
|
|
'Major',
|
|
'Minor',
|
|
'Trivial',
|
|
'Cosmetic',
|
|
'Enhancement',
|
|
'Bug'
|
|
],
|
|
presets: [{
|
|
id: 'default',
|
|
name: 'Default',
|
|
settings: {
|
|
levels: 6,
|
|
levelAliases: [
|
|
'Major',
|
|
'Minor',
|
|
'Trivial',
|
|
'Cosmetic',
|
|
'Enhancement',
|
|
'Bug'
|
|
],
|
|
}
|
|
}]
|
|
}
|
|
|
|
export default class PrioPlugin extends Plugin {
|
|
settings: PrioPluginSettings;
|
|
|
|
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');
|
|
|
|
|
|
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',
|
|
}
|
|
]
|
|
});
|
|
|
|
this.addCommand({
|
|
id: 'remove-prio',
|
|
name: 'Remove priority',
|
|
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',
|
|
}
|
|
]
|
|
});
|
|
// 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',
|
|
}
|
|
]
|
|
});
|
|
|
|
// This adds a settings tab so the user can configure various aspects of the plugin
|
|
this.addSettingTab(new SettingTab(this.app, this));
|
|
|
|
// 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();
|
|
}
|
|
}
|
|
|
|
|