Skip to content

Commit

Permalink
chore: settings: only add item collapse button if there's 1+ items
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgurney committed May 15, 2024
1 parent 458d717 commit a28d5a3
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions src/Settings/ToolbarSettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,36 +133,40 @@ export default class ToolbarSettingsModal extends Modal {
itemsContainer.addClass('note-toolbar-setting-items-container');
itemsContainer.setAttribute('data-active', this.itemListOpen.toString());

new Setting(itemsContainer)
let itemsSetting = new Setting(itemsContainer)
.setName("Items")
.setHeading()
.setDesc(learnMoreFr(
"Items in the toolbar, in order from left to right.",
"https://github.com/chrisgurney/obsidian-note-toolbar/wiki/Creating-toolbar-items"))
.addExtraButton((cb) => {
cb.setIcon('right-triangle')
.setTooltip("Collapse all items")
.onClick(async () => {
let itemsContainer = settingsDiv.querySelector('.note-toolbar-setting-items-container');
if (itemsContainer) {
this.itemListOpen = !this.itemListOpen;
itemsContainer.setAttribute('data-active', this.itemListOpen.toString());
let heading = itemsContainer.querySelector('.setting-item-heading .setting-item-name');
this.itemListOpen ? heading?.setText("Items") : heading?.setText("Items (" + this.toolbar.items.length + ")");
cb.setTooltip(this.itemListOpen ? "Collapse all items" : "Expand all items");
}
})
.extraSettingsEl.tabIndex = 0;
this.plugin.registerDomEvent(
cb.extraSettingsEl, 'keydown', (e) => {
switch (e.key) {
case "Enter":
case " ":
e.preventDefault();
cb.extraSettingsEl.click();
"https://github.com/chrisgurney/obsidian-note-toolbar/wiki/Creating-toolbar-items"));

if (this.toolbar.items.length > 0) {
itemsSetting
.addExtraButton((cb) => {
cb.setIcon('right-triangle')
.setTooltip("Collapse all items")
.onClick(async () => {
let itemsContainer = settingsDiv.querySelector('.note-toolbar-setting-items-container');
if (itemsContainer) {
this.itemListOpen = !this.itemListOpen;
itemsContainer.setAttribute('data-active', this.itemListOpen.toString());
let heading = itemsContainer.querySelector('.setting-item-heading .setting-item-name');
this.itemListOpen ? heading?.setText("Items") : heading?.setText("Items (" + this.toolbar.items.length + ")");
cb.setTooltip(this.itemListOpen ? "Collapse all items" : "Expand all items");
}
});
});
})
.extraSettingsEl.tabIndex = 0;
this.plugin.registerDomEvent(
cb.extraSettingsEl, 'keydown', (e) => {
switch (e.key) {
case "Enter":
case " ":
e.preventDefault();
cb.extraSettingsEl.click();
}
});
});
}

let itemLinkFields: {
command: Setting;
Expand Down

0 comments on commit a28d5a3

Please sign in to comment.