Skip to content

Commit

Permalink
docs: removed commented parts per @FeralFlora
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgurney committed Dec 27, 2024
1 parent 3ac2dee commit 315adf5
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions examples/Scripts/Templater/SwapToolbars.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,33 @@

module.exports = async function SwapToolbars(tp) {

// Check if anything is selected. If it is, return it, so it's not lost.
// const selection = tp.file.selection();
// if (selection.length > 0) {
// tR += selection;
// }
// tp.hooks.on_all_templates_executed(async () => {

// Get all the configured toolbars and the toolbar property from the plugin settings
const { toolbars, toolbarProp } = app.plugins.getPlugin("note-toolbar").settings;

// Option to revert to default folder mapping
const defaultOption = "Default folder mapping";

// Extract only the toolbar names and add the default option
const toolbarOptions = toolbars.map(toolbar => toolbar.name).concat(defaultOption);
// Get all the configured toolbars and the toolbar property from the plugin settings
const { toolbars, toolbarProp } = app.plugins.getPlugin("note-toolbar").settings;

// Option to revert to default folder mapping
const defaultOption = "Default folder mapping";

// Extract only the toolbar names and add the default option
const toolbarOptions = toolbars.map(toolbar => toolbar.name).concat(defaultOption);

// Prompt the user to pick a toolbar
const pickedToolbar = await tp.system.suggester((item) => item, toolbarOptions, true, "Swap to toolbar:");

// Get the current file
const currentFile = app.workspace.getActiveFile();

// Update the frontmatter of the current file with the selected toolbar option
await app.fileManager.processFrontMatter(currentFile, (frontmatter) => {

// Prompt the user to pick a toolbar
const pickedToolbar = await tp.system.suggester((item) => item, toolbarOptions, true, "Swap to toolbar:");
// If the user picked the default option, delete the toolbar property
if (pickedToolbar === defaultOption) {
delete frontmatter[toolbarProp];
return;
}

// Get the current file
const currentFile = app.workspace.getActiveFile();

// Update the frontmatter of the current file with the selected toolbar option
await app.fileManager.processFrontMatter(currentFile, (frontmatter) => {

// If the user picked the default option, delete the toolbar property
if (pickedToolbar === defaultOption) {
delete frontmatter[toolbarProp];
return;
}

// Otherwise, set the toolbar property to the chosen toolbar
frontmatter[toolbarProp] = pickedToolbar;
// Otherwise, set the toolbar property to the chosen toolbar
frontmatter[toolbarProp] = pickedToolbar;

});

// });
});

}

0 comments on commit 315adf5

Please sign in to comment.