From d767bbb31d7bd1505344990a102f79213f7f409b Mon Sep 17 00:00:00 2001 From: Mara Date: Tue, 14 Jun 2022 18:40:21 +0200 Subject: [PATCH] style: tab according obsidian recommandation for plugins Easier reading --- src/commands/toggleVisibility.ts | 17 ++++----- src/main.ts | 57 +++++++++++++++++-------------- src/modals/HiddenList.ts | 23 +++++++------ src/settings/hiddenToggle.ts | 18 +++++----- src/settings/manageHiddenPaths.ts | 26 +++++++------- src/utils.ts | 4 +-- 6 files changed, 76 insertions(+), 69 deletions(-) diff --git a/src/commands/toggleVisibility.ts b/src/commands/toggleVisibility.ts index 86d45ac..0012ef6 100644 --- a/src/commands/toggleVisibility.ts +++ b/src/commands/toggleVisibility.ts @@ -3,12 +3,13 @@ import FileHider from "../main"; // The command used to toggle the visibility. export class VisibilityToggleCommand { constructor(plugin: FileHider) { - plugin.addCommand({ - id: 'oa-fh-toggle-visibility', - name: 'Toggle Visibility', - callback: () => { - plugin.toggleVisibility(); - } - }); + plugin + .addCommand({ + id: 'oa-fh-toggle-visibility', + name: 'Toggle Visibility', + callback: () => { + plugin.toggleVisibility(); + } + }); }; -} \ No newline at end of file +} diff --git a/src/main.ts b/src/main.ts index 2e8e18e..2ee63c6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,42 +21,47 @@ export default class FileHider extends Plugin { async onload() { await this.loadSettings(); + console.log('FileHider loaded'); this.registerEvent( this.app.workspace.on(`file-menu`, (menu, file) => { if (file instanceof TFolder) { menu.addItem((i) => { if (this.settings.hiddenList.includes(file.path)) { - i.setTitle(`Unhide Folder`) - .setIcon(`eye`) - .onClick(() => { - this.unhidePath(file.path); - }); + i + .setTitle(`Unhide Folder`) + .setIcon(`eye`) + .onClick(() => { + this.unhidePath(file.path); + }); } else { - i.setTitle(`Hide Folder`) - .setIcon(`eye-off`) - .onClick(() => { - changePathVisibility(file.path, this.settings.hidden); - this.settings.hiddenList.push(file.path); - this.saveSettings(); - }); + i + .setTitle(`Hide Folder`) + .setIcon(`eye-off`) + .onClick(() => { + changePathVisibility(file.path, this.settings.hidden); + this.settings.hiddenList.push(file.path); + this.saveSettings(); + }); } }); } else { menu.addItem((i) => { if (this.settings.hiddenList.includes(file.path)) { - i.setTitle(`Unhide File`) - .setIcon(`eye`) - .onClick(() => { - this.unhidePath(file.path); - }); + i + .setTitle(`Unhide File`) + .setIcon(`eye`) + .onClick(() => { + this.unhidePath(file.path); + }); } else { - i.setTitle(`Hide File`) - .setIcon(`eye-off`) - .onClick(() => { - changePathVisibility(file.path, this.settings.hidden); - this.settings.hiddenList.push(file.path); - this.saveSettings(); - }); + i + .setTitle(`Hide File`) + .setIcon(`eye-off`) + .onClick(() => { + changePathVisibility(file.path, this.settings.hidden); + this.settings.hiddenList.push(file.path); + this.saveSettings(); + }); } }); } @@ -65,9 +70,9 @@ export default class FileHider extends Plugin { this.app.workspace.onLayoutReady(async () => { - await sleep(50) + await sleep(50); for (const path of this.settings.hiddenList) { - await changePathVisibility(path, this.settings.hidden); + changePathVisibility(path, this.settings.hidden); } }); diff --git a/src/modals/HiddenList.ts b/src/modals/HiddenList.ts index 5a0ee38..7682b01 100644 --- a/src/modals/HiddenList.ts +++ b/src/modals/HiddenList.ts @@ -17,20 +17,21 @@ export class HiddenPathsModal extends Modal { this.plugin.settings.hiddenList.forEach(path => { let c = body.createEl(`div`); new Setting(c) - .setName(path) - .addButton(btn => { - btn.setIcon(`cross`) - .setTooltip(`Remove`) - .onClick((e) => { - this.plugin.unhidePath(path); - c.hide(); + .setName(path) + .addButton(btn => { + btn + .setIcon(`cross`) + .setTooltip(`Remove`) + .onClick(() => { + this.plugin.unhidePath(path); + c.hide(); + }); + }); }); - }); - }); - } + } onClose() { const {contentEl} = this; contentEl.empty(); } -} \ No newline at end of file +} diff --git a/src/settings/hiddenToggle.ts b/src/settings/hiddenToggle.ts index 7dad744..e5b9ec8 100644 --- a/src/settings/hiddenToggle.ts +++ b/src/settings/hiddenToggle.ts @@ -5,14 +5,14 @@ export class VisibilityToggleSetting { public static create(plugin: FileHider, container: HTMLElement) { return new Setting(container) - .setName(`Hidden File Visibility`) - .setDesc(`Toggle whether or not files and folders that are told to be hidden will be hidden or not.`) - .addToggle(toggle => { - toggle - .setValue(!plugin.settings.hidden) - .onChange(() => { - plugin.toggleVisibility(); + .setName(`Hidden File Visibility`) + .setDesc(`Toggle whether or not files and folders that are told to be hidden will be hidden or not.`) + .addToggle(toggle => { + toggle + .setValue(!plugin.settings.hidden) + .onChange(() => { + plugin.toggleVisibility(); + }); }); - }); }; -}; \ No newline at end of file +} diff --git a/src/settings/manageHiddenPaths.ts b/src/settings/manageHiddenPaths.ts index b05d173..1bc3686 100644 --- a/src/settings/manageHiddenPaths.ts +++ b/src/settings/manageHiddenPaths.ts @@ -7,16 +7,16 @@ export class ManageHiddenPaths { public static create(plugin: FileHider, container: HTMLElement) { return new Setting(container) - .setName(`Hidden Files and Folders`) - .setDesc(`Add or remove files and folders from the list that are being hidden`) - .addButton(b => { - b.setButtonText(`Manage`) - .onClick(event => { - // sanity check to prevent other code from opening the modal - if (!event.isTrusted) { return } - - new HiddenPathsModal(plugin).open() - }); - }); - }; -}; \ No newline at end of file + .setName(`Hidden Files and Folders`) + .setDesc(`Add or remove files and folders from the list that are being hidden`) + .addButton(b => { + b + .setButtonText(`Manage`) + .onClick(event => { + // sanity check to prevent other code from opening the modal + if (!event.isTrusted) { return } + new HiddenPathsModal(plugin).open(); + }); + }); + }; +} diff --git a/src/utils.ts b/src/utils.ts index 7a044d4..4301990 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,9 +3,9 @@ export function changePathVisibility(path: string, hide: boolean) { if (!n) { return; } - let p = n.parentElement + let p = n.parentElement; if (hide) { - p.style.display = `none` + p.style.display = `none`; } else { p.style.display = ``; }