diff --git a/src/index.ts b/src/index.ts index fbfdb73..c687612 100644 --- a/src/index.ts +++ b/src/index.ts @@ -357,7 +357,17 @@ joplin.plugins.register({ command: "showPluginDocumentation" } ]); - await commandsPanel.create(); + + await joplin.commands.register({ + name: "showTemplatesPanel", + label: "Templates", + iconName: "far fa-file-alt", + execute: async () => { + await commandsPanel.create(); + } + }); + + await joplin.views.menuItems.create("showTemplatesPanelMenuItem", "showTemplatesPanel", MenuItemLocation.Tools); } }, }); diff --git a/src/views/commandsPanel.ts b/src/views/commandsPanel.ts index 007f5d5..7dc323b 100644 --- a/src/views/commandsPanel.ts +++ b/src/views/commandsPanel.ts @@ -1,5 +1,4 @@ import joplin from "api"; -import { PassThrough } from "stream"; export interface CommandButton { label: string; @@ -10,12 +9,19 @@ export class CommandsPanel { private panelHandle: string; private commands: CommandButton[]; + private created = false; + constructor(commands: CommandButton[]) { this.panelHandle = "templatesCommandsPanel"; this.commands = commands; } public async create(): Promise { + if (this.created) { + await joplin.views.panels.show(this.panelHandle, true); + return; + } + try { // Create the panel this.panelHandle = await joplin.views.panels.create(this.panelHandle); @@ -41,6 +47,7 @@ export class CommandsPanel { // Show the panel await joplin.views.panels.show(this.panelHandle, true); + this.created = true; } catch (error) { console.error("Error creating commands panel:", error); throw error;