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.
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();
}
});
};
}
}

View file

@ -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);
}
});

View file

@ -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();
}
}
}

View file

@ -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();
});
});
});
};
};
}

View file

@ -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()
});
});
};
};
.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();
});
});
};
}

View file

@ -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 = ``;
}