From 14ee7634a01cf625e710b76a036631ebcc63e45f Mon Sep 17 00:00:00 2001 From: Mike Farr Date: Sun, 9 Mar 2025 11:52:52 -0400 Subject: [PATCH] Only allow archive if item isn't already archived --- main.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/main.ts b/main.ts index a734042..fdeebc7 100644 --- a/main.ts +++ b/main.ts @@ -25,11 +25,25 @@ export default class SimpleArchiver extends Plugin { this.addCommand({ id: "move-to-archive", - name: "Move to Archive", - editorCallback: async (editor: Editor, view: MarkdownView) => { - if (view.file != null) { - await this.moveToArchive(view.file); + name: "Move to archive", + editorCheckCallback: ( + checking: boolean, + editor: Editor, + view: MarkdownView + ) => { + let canBeArchived = !view.file?.path.startsWith( + this.settings.archiveFolder + ); + + if (canBeArchived && view.file != null) { + if (!checking) { + this.moveToArchive(view.file).then(); + } + + return true; } + + return false; }, }); @@ -37,8 +51,12 @@ export default class SimpleArchiver extends Plugin { this.registerEvent( this.app.workspace.on("file-menu", (menu, file) => { + if (file.path.startsWith(this.settings.archiveFolder)) { + return; + } + menu.addItem((item) => { - item.setTitle("Archive") + item.setTitle("Move to archive") .setIcon("archive") .onClick(async () => { await this.moveToArchive(file);