diff --git a/src/main.ts b/src/main.ts index b45578e..b9131d6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -35,23 +35,39 @@ export default class FileHider extends Plugin { }; if (file instanceof TFolder) { menu.addItem((i) => { - i.setTitle(`Hide Folder`) - .setIcon(`minus-with-circle`) - .onClick(() => { - let rule = createStyleLine(`folder`, file.path); - this.style.insertRule(rule); - this.settings.hiddenFolders.push(file.path); - }); + if (this.settings.hiddenFolders.includes(file.path)) { + i.setTitle(`Unhide Folder`) + .setIcon(`eye`) + .onClick(() => { + this.unhideFolder(file.path); + }); + } else { + i.setTitle(`Hide Folder`) + .setIcon(`eye-off`) + .onClick(() => { + let rule = createStyleLine(`folder`, file.path); + this.style.insertRule(rule); + this.settings.hiddenFolders.push(file.path); + }); + }; }); } else { menu.addItem((i) => { - i.setTitle(`Hide File`) - .setIcon(`minus-with-circle`) - .onClick((e) => { - let rule = createStyleLine(`file`, file.path); - this.style.insertRule(rule); - this.settings.hiddenFiles.push(file.path); - }); + if (this.settings.hiddenFiles.includes(file.path)) { + i.setTitle(`Unhide File`) + .setIcon(`eye`) + .onClick((e) => { + this.unhideFile(file.path); + }); + } else { + i.setTitle(`Hide File`) + .setIcon(`eye-off`) + .onClick((e) => { + let rule = createStyleLine(`file`, file.path); + this.style.insertRule(rule); + this.settings.hiddenFiles.push(file.path); + }); + }; }); }; }) @@ -113,6 +129,35 @@ export default class FileHider extends Plugin { }; this.settings.hidden = !this.settings.hidden; }; + + unhideFolder(folder: string) { + let i = this.settings.hiddenFolders.indexOf(folder); + this.settings.hiddenFolders.splice(i, 1); + + // Find and remove the CSS style from the system + for (var j in this.style.cssRules) { + let rule = this.style.cssRules[j]; + if (rule.cssText == createStyleLine(`folder`, folder)) { + this.style.deleteRule(parseInt(j)); + }; + }; + }; + + unhideFile(file: string) { + let i = this.settings.hiddenFiles.indexOf(file); + this.settings.hiddenFiles.splice(i, 1); + + // Find and remove the CSS style from the system + for (var j in this.style.cssRules) { + try { parseInt(j) } catch (e) { console.log(`skipping`, j); continue; }; + + let rule = this.style.cssRules[j]; + if (rule.cssText == createStyleLine(`file`, file)) { + this.style.deleteRule(parseInt(j)); + break; + }; + }; + } }; diff --git a/src/modals/DirectoryModal.ts b/src/modals/DirectoryModal.ts index 03d0785..9a8815c 100644 --- a/src/modals/DirectoryModal.ts +++ b/src/modals/DirectoryModal.ts @@ -23,17 +23,7 @@ export class DirectoryModal extends Modal { btn.setIcon(`cross`) .setTooltip(`Remove Folder`) .onClick((e) => { - let i = this.plugin.settings.hiddenFolders.indexOf(folder); - this.plugin.settings.hiddenFolders.splice(i, 1); - - // Find and remove the CSS style from the system - for (var j in this.plugin.style.cssRules) { - let rule = this.plugin.style.cssRules[j]; - if (rule.cssText == createStyleLine(`folder`, folder)) { - this.plugin.style.deleteRule(parseInt(j)); - }; - }; - + this.plugin.unhideFolder(folder); c.hide(); }); }); diff --git a/src/modals/FileModal.ts b/src/modals/FileModal.ts index 6569b5b..9aca18f 100644 --- a/src/modals/FileModal.ts +++ b/src/modals/FileModal.ts @@ -23,20 +23,7 @@ export class FileModal extends Modal { btn.setIcon(`cross`) .setTooltip(`Remove File`) .onClick((e) => { - let i = this.plugin.settings.hiddenFiles.indexOf(file); - this.plugin.settings.hiddenFiles.splice(i, 1); - - // Find and remove the CSS style from the system - for (var j in this.plugin.style.cssRules) { - try { parseInt(j) } catch (e) { console.log(`skipping`, j); continue; }; - - let rule = this.plugin.style.cssRules[j]; - if (rule.cssText == createStyleLine(`file`, file)) { - this.plugin.style.deleteRule(parseInt(j)); - break; - }; - }; - + this.plugin.unhideFile(file); c.hide(); }); });