0
0
Fork 0

style: tab according obsidian recommandation for plugins

Easier reading
This commit is contained in:
Mara 2022-06-14 18:40:21 +02:00
parent aa19795ec5
commit d767bbb31d
6 changed files with 76 additions and 69 deletions

View file

@ -3,12 +3,13 @@ import FileHider from "../main";
// The command used to toggle the visibility. // The command used to toggle the visibility.
export class VisibilityToggleCommand { export class VisibilityToggleCommand {
constructor(plugin: FileHider) { constructor(plugin: FileHider) {
plugin.addCommand({ plugin
id: 'oa-fh-toggle-visibility', .addCommand({
name: 'Toggle Visibility', id: 'oa-fh-toggle-visibility',
callback: () => { name: 'Toggle Visibility',
plugin.toggleVisibility(); callback: () => {
} plugin.toggleVisibility();
}); }
});
}; };
} }

View file

@ -21,42 +21,47 @@ export default class FileHider extends Plugin {
async onload() { async onload() {
await this.loadSettings(); await this.loadSettings();
console.log('FileHider loaded');
this.registerEvent( this.registerEvent(
this.app.workspace.on(`file-menu`, (menu, file) => { this.app.workspace.on(`file-menu`, (menu, file) => {
if (file instanceof TFolder) { if (file instanceof TFolder) {
menu.addItem((i) => { menu.addItem((i) => {
if (this.settings.hiddenList.includes(file.path)) { if (this.settings.hiddenList.includes(file.path)) {
i.setTitle(`Unhide Folder`) i
.setIcon(`eye`) .setTitle(`Unhide Folder`)
.onClick(() => { .setIcon(`eye`)
this.unhidePath(file.path); .onClick(() => {
}); this.unhidePath(file.path);
});
} else { } else {
i.setTitle(`Hide Folder`) i
.setIcon(`eye-off`) .setTitle(`Hide Folder`)
.onClick(() => { .setIcon(`eye-off`)
changePathVisibility(file.path, this.settings.hidden); .onClick(() => {
this.settings.hiddenList.push(file.path); changePathVisibility(file.path, this.settings.hidden);
this.saveSettings(); this.settings.hiddenList.push(file.path);
}); this.saveSettings();
});
} }
}); });
} else { } else {
menu.addItem((i) => { menu.addItem((i) => {
if (this.settings.hiddenList.includes(file.path)) { if (this.settings.hiddenList.includes(file.path)) {
i.setTitle(`Unhide File`) i
.setIcon(`eye`) .setTitle(`Unhide File`)
.onClick(() => { .setIcon(`eye`)
this.unhidePath(file.path); .onClick(() => {
}); this.unhidePath(file.path);
});
} else { } else {
i.setTitle(`Hide File`) i
.setIcon(`eye-off`) .setTitle(`Hide File`)
.onClick(() => { .setIcon(`eye-off`)
changePathVisibility(file.path, this.settings.hidden); .onClick(() => {
this.settings.hiddenList.push(file.path); changePathVisibility(file.path, this.settings.hidden);
this.saveSettings(); this.settings.hiddenList.push(file.path);
}); this.saveSettings();
});
} }
}); });
} }
@ -65,9 +70,9 @@ export default class FileHider extends Plugin {
this.app.workspace.onLayoutReady(async () => { this.app.workspace.onLayoutReady(async () => {
await sleep(50) await sleep(50);
for (const path of this.settings.hiddenList) { for (const path of this.settings.hiddenList) {
await changePathVisibility(path, this.settings.hidden); changePathVisibility(path, this.settings.hidden);
} }
}); });

View file

@ -17,20 +17,21 @@ export class HiddenPathsModal extends Modal {
this.plugin.settings.hiddenList.forEach(path => { this.plugin.settings.hiddenList.forEach(path => {
let c = body.createEl(`div`); let c = body.createEl(`div`);
new Setting(c) new Setting(c)
.setName(path) .setName(path)
.addButton(btn => { .addButton(btn => {
btn.setIcon(`cross`) btn
.setTooltip(`Remove`) .setIcon(`cross`)
.onClick((e) => { .setTooltip(`Remove`)
this.plugin.unhidePath(path); .onClick(() => {
c.hide(); this.plugin.unhidePath(path);
c.hide();
});
});
}); });
}); }
});
}
onClose() { onClose() {
const {contentEl} = this; const {contentEl} = this;
contentEl.empty(); contentEl.empty();
} }
} }

View file

@ -5,14 +5,14 @@ export class VisibilityToggleSetting {
public static create(plugin: FileHider, container: HTMLElement) { public static create(plugin: FileHider, container: HTMLElement) {
return new Setting(container) return new Setting(container)
.setName(`Hidden File Visibility`) .setName(`Hidden File Visibility`)
.setDesc(`Toggle whether or not files and folders that are told to be hidden will be hidden or not.`) .setDesc(`Toggle whether or not files and folders that are told to be hidden will be hidden or not.`)
.addToggle(toggle => { .addToggle(toggle => {
toggle toggle
.setValue(!plugin.settings.hidden) .setValue(!plugin.settings.hidden)
.onChange(() => { .onChange(() => {
plugin.toggleVisibility(); plugin.toggleVisibility();
});
}); });
});
}; };
}; }

View file

@ -7,16 +7,16 @@ export class ManageHiddenPaths {
public static create(plugin: FileHider, container: HTMLElement) { public static create(plugin: FileHider, container: HTMLElement) {
return new Setting(container) return new Setting(container)
.setName(`Hidden Files and Folders`) .setName(`Hidden Files and Folders`)
.setDesc(`Add or remove files and folders from the list that are being hidden`) .setDesc(`Add or remove files and folders from the list that are being hidden`)
.addButton(b => { .addButton(b => {
b.setButtonText(`Manage`) b
.onClick(event => { .setButtonText(`Manage`)
// sanity check to prevent other code from opening the modal .onClick(event => {
if (!event.isTrusted) { return } // sanity check to prevent other code from opening the modal
if (!event.isTrusted) { return }
new HiddenPathsModal(plugin).open() new HiddenPathsModal(plugin).open();
}); });
}); });
}; };
}; }

View file

@ -3,9 +3,9 @@ export function changePathVisibility(path: string, hide: boolean) {
if (!n) { if (!n) {
return; return;
} }
let p = n.parentElement let p = n.parentElement;
if (hide) { if (hide) {
p.style.display = `none` p.style.display = `none`;
} else { } else {
p.style.display = ``; p.style.display = ``;
} }