From 426a76e206cb9ad6c4d8f92332fb7bfd711d7af7 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Mon, 3 Jan 2022 16:48:29 +0200 Subject: [PATCH] fix(WriteBCToFile): :bug: Fix write BCs to ALL files command (fix #217) --- main.js | 34 ++++++++++++++++++++-------------- src/main.ts | 51 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/main.js b/main.js index f6a6d3ee..9e0fd67c 100644 --- a/main.js +++ b/main.js @@ -51920,27 +51920,33 @@ class BCPlugin extends require$$0.Plugin { id: "Write-Breadcrumbs-to-All-Files", name: "Write Breadcrumbs to **ALL** Files", callback: async () => { - const first = window.confirm("This action will write the implied Breadcrumbs of each file to that file.\nIt uses the MetaEdit plugins API to update the YAML, so it should only affect that frontmatter of your note.\nI can't promise that nothing bad will happen. **This operation cannot be undone**."); - if (first) { - const second = window.confirm("Are you sure? You have been warned that this operation will attempt to update all files with implied breadcrumbs."); - if (second) { - const third = window.confirm("For real, please make a back up before"); - if (third) { - try { - const files = this.app.vault.getMarkdownFiles(); - for (const file of files) + if (!settings.showWriteAllBCsCmd) { + new require$$0.Notice("You first need to enable this command in Breadcrumbs' settings."); + return; + } + if (window.confirm("This action will write the implied Breadcrumbs of each file to that file.\nIt uses the MetaEdit plugins API to update the YAML, so it should only affect that frontmatter of your note.\nI can't promise that nothing bad will happen. **This operation cannot be undone**.")) { + if (window.confirm("Are you sure? You have been warned that this operation will attempt to update all files with implied breadcrumbs.")) { + if (window.confirm("For real, please make a back up before.")) { + const notice = new require$$0.Notice("Operation Started"); + const problemFiles = []; + for (const file of this.app.vault.getMarkdownFiles()) { + try { await this.writeBCToFile(file); - new require$$0.Notice("Operation Complete"); + } + catch (e) { + problemFiles.push(file.path); + } } - catch (err) { - new require$$0.Notice(err); - loglevel.error(err); + notice.setMessage("Operation Complete"); + if (problemFiles.length) { + new require$$0.Notice("Some files were not updated due to errors. Check the console to see which ones."); + console.log({ problemFiles }); } } } } }, - checkCallback: () => settings.showWriteAllBCsCmd, + // checkCallback: () => settings.showWriteAllBCsCmd, }); this.addCommand({ id: "local-index", diff --git a/src/main.ts b/src/main.ts index 2c983345..86af4b26 100644 --- a/src/main.ts +++ b/src/main.ts @@ -313,31 +313,44 @@ export default class BCPlugin extends Plugin { id: "Write-Breadcrumbs-to-All-Files", name: "Write Breadcrumbs to **ALL** Files", callback: async () => { - const first = window.confirm( - "This action will write the implied Breadcrumbs of each file to that file.\nIt uses the MetaEdit plugins API to update the YAML, so it should only affect that frontmatter of your note.\nI can't promise that nothing bad will happen. **This operation cannot be undone**." - ); - if (first) { - const second = window.confirm( - "Are you sure? You have been warned that this operation will attempt to update all files with implied breadcrumbs." + if (!settings.showWriteAllBCsCmd) { + new Notice( + "You first need to enable this command in Breadcrumbs' settings." ); - if (second) { - const third = window.confirm( - "For real, please make a back up before" - ); - if (third) { - try { - const files = this.app.vault.getMarkdownFiles(); - for (const file of files) await this.writeBCToFile(file); - new Notice("Operation Complete"); - } catch (err) { - new Notice(err); - error(err); + return; + } + if ( + window.confirm( + "This action will write the implied Breadcrumbs of each file to that file.\nIt uses the MetaEdit plugins API to update the YAML, so it should only affect that frontmatter of your note.\nI can't promise that nothing bad will happen. **This operation cannot be undone**." + ) + ) { + if ( + window.confirm( + "Are you sure? You have been warned that this operation will attempt to update all files with implied breadcrumbs." + ) + ) { + if (window.confirm("For real, please make a back up before.")) { + const notice = new Notice("Operation Started"); + const problemFiles = []; + for (const file of this.app.vault.getMarkdownFiles()) { + try { + await this.writeBCToFile(file); + } catch (e) { + problemFiles.push(file.path); + } + } + notice.setMessage("Operation Complete"); + if (problemFiles.length) { + new Notice( + "Some files were not updated due to errors. Check the console to see which ones." + ); + console.log({ problemFiles }); } } } } }, - checkCallback: () => settings.showWriteAllBCsCmd, + // checkCallback: () => settings.showWriteAllBCsCmd, }); this.addCommand({