diff --git a/src/main.ts b/src/main.ts index f6293fe..3220f2c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,6 +23,8 @@ export default class CustomSidebarPlugin extends Plugin { }); this.addExtraCommands(); + + this.app.workspace.onLayoutReady(() => this.hideCommands()); } onunload() { @@ -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"; + } + } + } } \ No newline at end of file diff --git a/src/ui/settingsTab.ts b/src/ui/settingsTab.ts index d5f3573..b64b185 100644 --- a/src/ui/settingsTab.ts +++ b/src/ui/settingsTab.ts @@ -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 { @@ -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') @@ -63,6 +88,7 @@ export default class CustomSidebarSettingsTab extends PluginSettingTab { .addButton((bt) => { bt.buttonEl.outerHTML = ``; }); + } }