From 38220884b56404dc80e0519230d281886bae65fd Mon Sep 17 00:00:00 2001 From: Evan Harmon Date: Tue, 7 Nov 2023 12:52:22 -0700 Subject: [PATCH] Add Ribbon Icon for each command --- src/main.ts | 72 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1446cdf..9ab58e2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,6 +30,52 @@ const mediaWikiActionApiUrlBase = "wikipedia.org/w/api.php"; export default class WikipediaData extends Plugin { settings: WikipediaDataSettings; + async onload() { + console.log("Loading Wikipedia Data Plugin"); + await this.loadSettings(); + + this.addCommand({ + id: "apply-template-one-for-active-note", + name: "Apply Template #1 for Active Note Title", + editorCallback: (editor: Editor) => this.applyTemplateForActiveNote(editor, 1), + }); + + this.addCommand({ + id: "apply-template-two-for-active-note", + name: "Apply Template #2 for Active Note Title", + editorCallback: (editor: Editor) => this.applyTemplateForActiveNote(editor, 2), + }); + + this.addCommand({ + id: "apply-template-three-for-active-note", + name: "Apply Template #3 for Active Note Title", + editorCallback: (editor: Editor) => this.applyTemplateForActiveNote(editor, 3), + }); + + this.addRibbonIcon( + 'glasses', 'Wikipedia Data: Apply Template #1 for Active Note Title', (evt: MouseEvent) => { + const editor = this.app.workspace.activeEditor?.editor; + this.applyTemplateForActiveNote(editor as Editor, 1) + }); + + this.addRibbonIcon( + 'heading-2', 'Wikipedia Data: Apply Template #2 for Active Note Title', (evt: MouseEvent) => { + const editor = this.app.workspace.activeEditor?.editor; + this.applyTemplateForActiveNote(editor as Editor, 2) + }); + + this.addRibbonIcon( + 'heading-3', 'Wikipedia Data: Apply Template #3 for Active Note Title', (evt: MouseEvent) => { + const editor = this.app.workspace.activeEditor?.editor; + this.applyTemplateForActiveNote(editor as Editor, 3) + }); + + + this.addSettingTab(new WikipediaDataSettingTab(this.app, this)); + } + + onunload() {} + getLanguage(): string { return this.settings.language ? this.settings.language : "en"; } @@ -266,31 +312,6 @@ export default class WikipediaData extends Plugin { } } - async onload() { - console.log("Loading Wikipedia Data Plugin"); - await this.loadSettings(); - - this.addCommand({ - id: "apply-template-one-for-active-note", - name: "Apply Template #1 for Active Note Title", - editorCallback: (editor: Editor) => this.applyTemplateForActiveNote(editor, 1), - }); - - this.addCommand({ - id: "apply-template-two-for-active-note", - name: "Apply Template #2 for Active Note Title", - editorCallback: (editor: Editor) => this.applyTemplateForActiveNote(editor, 2), - }); - - this.addCommand({ - id: "apply-template-three-for-active-note", - name: "Apply Template #3 for Active Note Title", - editorCallback: (editor: Editor) => this.applyTemplateForActiveNote(editor, 3), - }); - - this.addSettingTab(new WikipediaDataSettingTab(this.app, this)); - } - async loadSettings() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); } @@ -299,5 +320,4 @@ export default class WikipediaData extends Plugin { await this.saveData(this.settings); } - onunload() {} }