Skip to content

Commit

Permalink
feat(WriteBCToFile): ✨ Write Breadcrumbs to All files
Browse files Browse the repository at this point in the history
Three warning messages to ensure people are aware
  • Loading branch information
SkepticMystic committed Sep 8, 2021
1 parent a2e3a40 commit 289b701
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
27 changes: 25 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6674,13 +6674,13 @@ const writeBCToFile = (app, plugin, currGraphs, file) => {
Object.keys(hier[dir]).forEach(field => {
const fieldG = hier[dir][field];
const succs = fieldG.predecessors(file.basename);
succs.forEach(succ => {
succs.forEach(async (succ) => {
const { fieldName } = fieldG.node(succ);
const currHier = plugin.settings.userHierarchies.filter(hier => hier[dir].includes(fieldName))[0];
let oppField = currHier[oppDir][0];
if (!oppField)
oppField = `<Reverse>${fieldName}`;
createOrUpdateYaml(oppField, succ, file, frontmatter, api);
await createOrUpdateYaml(oppField, succ, file, frontmatter, api);
});
});
});
Expand Down Expand Up @@ -37389,6 +37389,29 @@ class BreadcrumbsPlugin extends obsidian.Plugin {
writeBCToFile(this.app, this, this.currGraphs, currFile);
},
});
this.addCommand({
id: "Write-Breadcrumbs-to-All-Files",
name: "Write Breadcrumbs to **ALL** Files",
callback: () => {
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 {
this.app.vault.getMarkdownFiles().forEach(file => writeBCToFile(this.app, this, this.currGraphs, file));
new obsidian.Notice('Operation Complete');
}
catch (error) {
new obsidian.Notice(error);
console.log(error);
}
}
}
}
},
});
this.addRibbonIcon("dice", "Breadcrumbs Visualisation", () => new VisModal(this.app, this).open());
this.addSettingTab(new BreadcrumbsSettingTab(this.app, this));
}
Expand Down
28 changes: 26 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {
addIcon,
EventRef,
MarkdownView,
Notice,
Plugin,
Notice, Plugin,
TFile,
WorkspaceLeaf
} from "obsidian";
Expand Down Expand Up @@ -324,6 +323,31 @@ export default class BreadcrumbsPlugin extends Plugin {
},
});

this.addCommand({
id: "Write-Breadcrumbs-to-All-Files",
name: "Write Breadcrumbs to **ALL** Files",
callback: () => {
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 {
this.app.vault.getMarkdownFiles().forEach(file => writeBCToFile(this.app, this, this.currGraphs, file))
new Notice('Operation Complete')
}
catch (error) {
new Notice(error)
console.log(error)
}
}
}
}

},
});

this.addRibbonIcon("dice", "Breadcrumbs Visualisation", () =>
new VisModal(this.app, this).open()
Expand Down
4 changes: 2 additions & 2 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,13 @@ export const writeBCToFile = (app: App, plugin: BreadcrumbsPlugin, currGraphs: B
const fieldG = hier[dir][field];
const succs = fieldG.predecessors(file.basename) as string[];

succs.forEach(succ => {
succs.forEach(async succ => {
const { fieldName } = fieldG.node(succ);
const currHier = plugin.settings.userHierarchies.filter(hier => hier[dir].includes(fieldName))[0]
let oppField: string = currHier[oppDir][0];
if (!oppField) oppField = `<Reverse>${fieldName}`

createOrUpdateYaml(oppField, succ, file, frontmatter, api)
await createOrUpdateYaml(oppField, succ, file, frontmatter, api)
})
})
})
Expand Down

0 comments on commit 289b701

Please sign in to comment.