From 315adf51c785250a21d55e8160b6198a486a8503 Mon Sep 17 00:00:00 2001 From: Chris Gurney Date: Fri, 27 Dec 2024 07:55:59 -0500 Subject: [PATCH] docs: removed commented parts per @FeralFlora --- examples/Scripts/Templater/SwapToolbars.js | 59 +++++++++------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/examples/Scripts/Templater/SwapToolbars.js b/examples/Scripts/Templater/SwapToolbars.js index a624b07..197f2bc 100644 --- a/examples/Scripts/Templater/SwapToolbars.js +++ b/examples/Scripts/Templater/SwapToolbars.js @@ -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; - }); - - // }); + }); } \ No newline at end of file