Re: One button to toggle on and off the sidebar, notes list and favorites
Hi all. In case anyone is interested, I managed to work out how to fix this. The current visibility of panels is held in a global setting, so I use that. I can't just use the existing toggle commands, because the order in which you make each panel visible and invisible is important, and different depending on whether you are toggling on or off!
If you happen to want a button which toggles the sidebar, notes list and favourites on and off, without screwing up the panel heights, you could save this js file somewhere and reference it in the Advanced Settings of your plugins.
Use at your own risk: Works for my layout, but if you are using any other fancy panels, may have unexpected results
/* joplin-manifest:
{
"manifest_version": 1,
"id": "com.jeffries.customtoggle",
"app_min_version": "1.4",
"name": "Note list, sidebar and favorites toggle buttons",
"description": "Add buttons to toggle everything",
"version": "0.0.1",
"author": "Nick Jeffries",
"homepage_url": "https://joplinapp.org"
}
*/
joplin.plugins.register({
onStart: async function() {
function recurseFind(item, key) {
if (item.key === key) return item;
if (item.children) {
for (const child of item.children) {
const found = recurseFind(child, key);
if (found) return found;
}
}
return null;
}
await joplin.views.toolbarButtons.create('toggleCustomButton', 'toggleCustom', 'noteToolbar');
await joplin.commands.register({
name: 'toggleCustom',
label: 'Custom Toggle',
iconName: 'fas fa-bullseye',
execute: async () => {
const userLayout = await joplin.settings.globalValue('ui.layout');
const sideBarObject = recurseFind(userLayout,'sideBar');
const noteListObject = recurseFind(userLayout,'noteList');
const favBarObject = recurseFind(userLayout,'plugin-view-joplin.plugin.benji.favorites-favorites.panel');
if (!sideBarObject || !noteListObject || !favBarObject) {
alert('Cannot toggle! Sidebar, Notelist or Favorites panel not found in layout!');
return;
}
if (sideBarObject.visible) {
// Sidebar is visible, so we need to hide everything in this order to avoid changes to panel height:
if (favBarObject.visible) await joplin.commands.execute('favsToggleVisibility');
await joplin.commands.execute('toggleSideBar');
if (noteListObject.visible) await joplin.commands.execute('toggleNoteList');
} else {
// Sidebar is invisible, so we need to make visible in this order to avoid changes to panel height:
await joplin.commands.execute('toggleSideBar');
if (!favBarObject.visible) await joplin.commands.execute('favsToggleVisibility');
if (!noteListObject.visible) await joplin.commands.execute('toggleNoteList');
}
}
})
},
});