Skip to content

Commit

Permalink
fix(WriteBCToFile): 🐛 Fix write BCs to ALL files command (fix #217)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 3, 2022
1 parent ddbdd7b commit 426a76e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
34 changes: 20 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
51 changes: 32 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 426a76e

Please sign in to comment.