0
0
Fork 0

Refactor to have it unhide the file when the user right clicks on a shown hidden file

This commit is contained in:
Oliver Akins 2022-05-27 00:10:48 -06:00
parent 58acaca172
commit 8286693cde
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99
3 changed files with 61 additions and 39 deletions

View file

@ -35,23 +35,39 @@ export default class FileHider extends Plugin {
}; };
if (file instanceof TFolder) { if (file instanceof TFolder) {
menu.addItem((i) => { 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`) i.setTitle(`Hide Folder`)
.setIcon(`minus-with-circle`) .setIcon(`eye-off`)
.onClick(() => { .onClick(() => {
let rule = createStyleLine(`folder`, file.path); let rule = createStyleLine(`folder`, file.path);
this.style.insertRule(rule); this.style.insertRule(rule);
this.settings.hiddenFolders.push(file.path); this.settings.hiddenFolders.push(file.path);
}); });
};
}); });
} else { } else {
menu.addItem((i) => { 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`) i.setTitle(`Hide File`)
.setIcon(`minus-with-circle`) .setIcon(`eye-off`)
.onClick((e) => { .onClick((e) => {
let rule = createStyleLine(`file`, file.path); let rule = createStyleLine(`file`, file.path);
this.style.insertRule(rule); this.style.insertRule(rule);
this.settings.hiddenFiles.push(file.path); this.settings.hiddenFiles.push(file.path);
}); });
};
}); });
}; };
}) })
@ -113,6 +129,35 @@ export default class FileHider extends Plugin {
}; };
this.settings.hidden = !this.settings.hidden; 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;
};
};
}
}; };

View file

@ -23,17 +23,7 @@ export class DirectoryModal extends Modal {
btn.setIcon(`cross`) btn.setIcon(`cross`)
.setTooltip(`Remove Folder`) .setTooltip(`Remove Folder`)
.onClick((e) => { .onClick((e) => {
let i = this.plugin.settings.hiddenFolders.indexOf(folder); this.plugin.unhideFolder(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));
};
};
c.hide(); c.hide();
}); });
}); });

View file

@ -23,20 +23,7 @@ export class FileModal extends Modal {
btn.setIcon(`cross`) btn.setIcon(`cross`)
.setTooltip(`Remove File`) .setTooltip(`Remove File`)
.onClick((e) => { .onClick((e) => {
let i = this.plugin.settings.hiddenFiles.indexOf(file); this.plugin.unhideFile(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;
};
};
c.hide(); c.hide();
}); });
}); });