From b93e472f8db2b764a047d543fe789aa10a3f6877 Mon Sep 17 00:00:00 2001 From: Endeavorance Date: Mon, 28 Oct 2024 07:49:39 -0400 Subject: [PATCH] Rework icons --- main.ts | 70 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/main.ts b/main.ts index 61da81c..3c85a75 100644 --- a/main.ts +++ b/main.ts @@ -20,6 +20,13 @@ const DEFAULT_SETTINGS: ScrapsPluginSettings = { scrapsFileName: "{time DDDD} {A} {N}", }; +const ICON = { + New: "file-plus", + Convert: "shuffle", + Move: "replace", + Copy: "copy-plus", +} as const; + async function mkdirp(vault: Vault, folderPath: string): Promise { const pathParts = folderPath.split("/"); @@ -77,7 +84,7 @@ export default class ScrapsPlugin extends Plugin { await this.app.workspace.getLeaf(false).openFile(newScrap); } - async convertToScrap() { + async convertToScrap(rename = true) { const currentFile = this.app.workspace.getActiveFile(); if (currentFile === null) { @@ -87,10 +94,28 @@ export default class ScrapsPlugin extends Plugin { await this.ensureScrapDir(); - await this.app.fileManager.renameFile( + const filename = rename ? this.getScrapFileName() : currentFile.name; + const renamePath = `${this.getScrapDir()}/${filename}`; + + await this.app.fileManager.renameFile(currentFile, renamePath); + } + + async copyToScrap() { + const currentFile = this.app.workspace.getActiveFile(); + + if (currentFile === null) { + new Notice("No file is currently open"); + return; + } + + await this.ensureScrapDir(); + + const newScrap = await this.app.vault.copy( currentFile, this.getScrapFilePath() ); + + await this.app.workspace.getLeaf(false).openFile(newScrap); } async onload() { @@ -100,48 +125,47 @@ export default class ScrapsPlugin extends Plugin { this.addCommand({ id: "scraps-new", name: "Scraps: Create new Scrap", - icon: "badge-plus", + icon: ICON.New, callback: async () => { this.createScrap(); }, }); - this.addRibbonIcon("badge-plus", "Create new Scrap", async () => { + this.addRibbonIcon(ICON.New, "Create new Scrap", async () => { this.createScrap(); }); this.addCommand({ id: "scraps-convert", name: "Scraps: Convert current file to Scrap", - icon: "file-plus", + icon: ICON.Convert, editorCallback: async () => this.convertToScrap(), }); - this.addRibbonIcon("file-plus", "Convert file to Scrap", async () => { + this.addRibbonIcon(ICON.Convert, "Convert file to Scrap", async () => { this.convertToScrap(); }); + this.addCommand({ + id: "scraps-move", + name: "Scraps: Move current file to Scraps", + icon: ICON.Move, + editorCallback: async () => this.convertToScrap(false), + }); + + this.addRibbonIcon(ICON.Move, "Move file to Scraps", async () => { + this.convertToScrap(false); + }); + this.addCommand({ id: "scraps-copy", name: "Scraps: Copy current file to Scraps", - icon: "copy-plus", - editorCallback: async () => { - const currentFile = this.app.workspace.getActiveFile(); + icon: ICON.Copy, + editorCallback: () => this.copyToScrap(), + }); - if (currentFile === null) { - new Notice("No file is currently open"); - return; - } - - await this.ensureScrapDir(); - - const newScrap = await this.app.vault.copy( - currentFile, - this.getScrapFilePath() - ); - - await this.app.workspace.getLeaf(false).openFile(newScrap); - }, + this.addRibbonIcon(ICON.Copy, "Copy file to Scraps", async () => { + this.copyToScrap(); }); }