Refactor to have it unhide the file when the user right clicks on a shown hidden file
This commit is contained in:
parent
58acaca172
commit
8286693cde
3 changed files with 61 additions and 39 deletions
49
src/main.ts
49
src/main.ts
|
|
@ -35,23 +35,39 @@ export default class FileHider extends Plugin {
|
|||
};
|
||||
if (file instanceof TFolder) {
|
||||
menu.addItem((i) => {
|
||||
if (this.settings.hiddenFolders.includes(file.path)) {
|
||||
i.setTitle(`Unhide Folder`)
|
||||
.setIcon(`eye`)
|
||||
.onClick(() => {
|
||||
this.unhideFolder(file.path);
|
||||
});
|
||||
} else {
|
||||
i.setTitle(`Hide Folder`)
|
||||
.setIcon(`minus-with-circle`)
|
||||
.setIcon(`eye-off`)
|
||||
.onClick(() => {
|
||||
let rule = createStyleLine(`folder`, file.path);
|
||||
this.style.insertRule(rule);
|
||||
this.settings.hiddenFolders.push(file.path);
|
||||
});
|
||||
};
|
||||
});
|
||||
} else {
|
||||
menu.addItem((i) => {
|
||||
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(`minus-with-circle`)
|
||||
.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;
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue