Skip to content

Commit

Permalink
Finished hide collapse icon feature
Browse files Browse the repository at this point in the history
  • Loading branch information
LostPaul committed Jan 23, 2024
1 parent 402e288 commit 35e53aa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class FolderNotesPlugin extends Plugin {
this.registerEvent(this.app.vault.on('create', (file: TAbstractFile) => {
const folder = file.parent;
if (folder instanceof TFolder) {
if (folder.children.length == 1) {
if (this.isEmptyFolderNoteFolder(folder)) {
this.addCSSClassToTitleEL(folder.path, 'only-has-folder-note');
} else if (folder.children.length == 0 || folder.children.length > 1) {
this.removeCSSClassFromEL(folder.path, 'only-has-folder-note');
Expand Down Expand Up @@ -224,15 +224,15 @@ export default class FolderNotesPlugin extends Plugin {
const folder = file.parent;
const oldFolder = this.app.vault.getAbstractFileByPath(this.getFolderPathFromString(oldPath));
if (folder instanceof TFolder) {
if (folder.children.length == 1) {
if (this.isEmptyFolderNoteFolder(folder)) {
this.addCSSClassToTitleEL(folder.path, 'only-has-folder-note');
} else if (folder.children.length == 0 || folder.children.length > 1) {
this.removeCSSClassFromEL(folder.path, 'only-has-folder-note');
}
}

if (oldFolder instanceof TFolder) {
if (oldFolder.children.length == 1) {
if (this.isEmptyFolderNoteFolder(oldFolder)) {
this.addCSSClassToTitleEL(oldFolder.path, 'only-has-folder-note');
} else if (oldFolder.children.length == 0 || oldFolder.children.length > 1) {
this.removeCSSClassFromEL(oldFolder.path, 'only-has-folder-note');
Expand All @@ -249,9 +249,9 @@ export default class FolderNotesPlugin extends Plugin {
}));

this.registerEvent(this.app.vault.on('delete', (file: TAbstractFile) => {
const folder = file.parent;
if (folder instanceof TFolder) {
if (folder.children.length == 1) {
const folder = this.app.vault.getAbstractFileByPath(this.getFolderPathFromString(file.path));
if (folder instanceof TFolder) {
if (this.isEmptyFolderNoteFolder(folder)) {
this.addCSSClassToTitleEL(folder.path, 'only-has-folder-note');
} else if (folder.children.length == 0 || folder.children.length > 1) {
this.removeCSSClassFromEL(folder.path, 'only-has-folder-note');
Expand Down Expand Up @@ -358,6 +358,31 @@ export default class FolderNotesPlugin extends Plugin {
return this.getFileExplorer().view;
}

isEmptyFolderNoteFolder(folder: TFolder): boolean {
let attachmentFolderPath = this.app.vault.getConfig('attachmentFolderPath') as string;
const cleanAttachmentFolderPath = attachmentFolderPath?.replace('./', '') || '';
const attachmentsAreInRootFolder = attachmentFolderPath === './' || attachmentFolderPath === '';

if (folder.children.length == 1) {
return true;
} else if (folder.children.length > 1) {
if (attachmentsAreInRootFolder) {
return false;
} else if (this.settings.ignoreAttachmentFolder) {
const folderPath = `${folder.path}/${cleanAttachmentFolderPath}`
const attachmentFolder = this.app.vault.getAbstractFileByPath(folderPath);

if (attachmentFolder instanceof TFolder) {
if (!folder.collapsed) {
this.getEL(folder.path)?.click();
}
return attachmentFolder.children.length <= 2;
}
}
}
return true;
}

async addCSSClassToTitleEL(path: string, cssClass: string, waitForCreate = false, count = 0) {
const fileExplorerItem = this.getEL(path);
if (!fileExplorerItem) {
Expand Down Expand Up @@ -466,7 +491,7 @@ export default class FolderNotesPlugin extends Plugin {
} else {
this.addCSSClassToTitleEL(folderNote.path, 'is-folder-note');
this.addCSSClassToTitleEL(file.path, 'has-folder-note');
if (file.children.length == 1) {
if (this.isEmptyFolderNoteFolder(file)) {
this.addCSSClassToTitleEL(file.path, 'only-has-folder-note');
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/settings/FileExplorerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,23 @@ export async function renderFileExplorer(settingsTab: SettingsTab) {
} else {
document.body.classList.remove('fn-hide-collapse-icon');
}
settingsTab.display();
})
);

if (settingsTab.plugin.settings.hideCollapsingIcon) {
new Setting(containerEl)
.setName('Hide collapse icon also when the attachment folder is in the same folder')
.addToggle((toggle) =>
toggle
.setValue(settingsTab.plugin.settings.ignoreAttachmentFolder)
.onChange(async (value) => {
settingsTab.plugin.settings.ignoreAttachmentFolder = value;
await settingsTab.plugin.saveSettings();
})
);
}

new Setting(containerEl)
.setName('Underline the name of folder notes')
.setDesc('Add an underline to folders that have a folder note in the file explorer')
Expand Down
2 changes: 2 additions & 0 deletions src/settings/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface FolderNotesSettings {
excludeFolderDefaultSettings: ExcludedFolder;
excludePatternDefaultSettings: ExcludePattern;
hideCollapsingIcon: boolean;
ignoreAttachmentFolder: boolean;
tabManagerEnabled: boolean;
}

Expand Down Expand Up @@ -137,6 +138,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
},
hideCollapsingIcon: false,
tabManagerEnabled: true,
ignoreAttachmentFolder: true,
};

export class SettingsTab extends PluginSettingTab {
Expand Down

0 comments on commit 35e53aa

Please sign in to comment.