Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Commit

Permalink
Hide Commands Feature, close #3
Browse files Browse the repository at this point in the history
  • Loading branch information
phibr0 committed Aug 15, 2021
1 parent 31e5864 commit c5fc64b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default class CustomSidebarPlugin extends Plugin {
});

this.addExtraCommands();

this.app.workspace.onLayoutReady(() => this.hideCommands());
}

onunload() {
Expand Down Expand Up @@ -105,4 +107,14 @@ export default class CustomSidebarPlugin extends Plugin {
}
});
}

hideCommands() {
//@ts-ignore
const children: HTMLCollection = this.app.workspace.leftRibbon.ribbonActionsEl.children;
for (let i = 0; i < children.length; i++) {
if(this.settings.hiddenCommands.contains(children.item(i).getAttribute("aria-label"))) {
(children.item(i) as HTMLElement).style.display = "none";
}
}
}
}
28 changes: 27 additions & 1 deletion src/ui/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import CommandSuggester from "./commandSuggester";

export interface CustomSidebarSettings {
sidebarCommands: Command[];
hiddenCommands: string[];
}

export const DEFAULT_SETTINGS: CustomSidebarSettings = {
sidebarCommands: [],
hiddenCommands: [],
}

export default class CustomSidebarSettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -54,7 +56,30 @@ export default class CustomSidebarSettingsTab extends PluginSettingTab {
});
setting.nameEl.prepend(iconDiv);
setting.nameEl.addClass("CS-flex");
})
});

//@ts-ignore
const children: HTMLCollection = this.app.workspace.leftRibbon.ribbonActionsEl.children;
for (let i = 0; i < children.length; i++) {
if (!this.plugin.settings.sidebarCommands.contains(this.plugin.settings.sidebarCommands.find(c => c.name === (children.item(i) as HTMLElement).getAttribute("aria-label")))) {
new Setting(containerEl)
.setName("Hide " + (children.item(i) as HTMLElement).getAttribute("aria-label") + "?")
.addToggle(cb => {
cb.setValue((children.item(i) as HTMLElement).style.display === "none")
cb.onChange(async value => {
if(value === true) {
(children.item(i) as HTMLElement).style.display = "none";
this.plugin.settings.hiddenCommands.push((children.item(i) as HTMLElement).getAttribute("aria-label"));
await this.plugin.saveSettings();
} else {
(children.item(i) as HTMLElement).style.display = "flex";
this.plugin.settings.hiddenCommands.remove((children.item(i) as HTMLElement).getAttribute("aria-label"));
await this.plugin.saveSettings();
}
});
});
}
}

new Setting(containerEl)
.setName('Donate')
Expand All @@ -63,6 +88,7 @@ export default class CustomSidebarSettingsTab extends PluginSettingTab {
.addButton((bt) => {
bt.buttonEl.outerHTML = `<a href="https://www.buymeacoffee.com/phibr0"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=phibr0&button_colour=5F7FFF&font_colour=ffffff&font_family=Inter&outline_colour=000000&coffee_colour=FFDD00"></a>`;
});

}
}

Expand Down

0 comments on commit c5fc64b

Please sign in to comment.