Fix show folder note in file explorer command

This commit is contained in:
Lost Paul 2025-05-30 20:47:50 +02:00
parent f53e2b6648
commit 94ce26c3e7
15 changed files with 56 additions and 30 deletions

View file

@ -328,9 +328,9 @@ export class Commands {
});
}
if (!(file instanceof TFolder)) return;
const excludedFolder = await getExcludedFolder(this.plugin, file.path, false);
const excludedFolder = getExcludedFolder(this.plugin, file.path, false);
const detachedExcludedFolder = getDetachedFolder(this.plugin, file.path);
if (excludedFolder && !excludedFolder.hideNote) {
if (excludedFolder && !excludedFolder.hideInSettings) {
// I'm not sure if I'm ever going to add this because of the possibility that a folder got more than one excluded
// subMenu.addItem((item) => {
// item.setTitle('Manage excluded folder')
@ -414,13 +414,13 @@ export class Commands {
});
if (this.plugin.settings.hideFolderNote) {
if (excludedFolder?.hideNote) {
if (excludedFolder?.showFolderNote) {
subMenu.addItem((item) => {
item.setTitle('Hide folder note in explorer')
.setIcon('eye-off')
.onClick(() => {
this.plugin.settings.excludeFolders = this.plugin.settings.excludeFolders.filter(
(folder) => (folder.path !== file.path) && folder.hideNote);
(folder) => (folder.path !== file.path) && folder.showFolderNote);
this.plugin.saveSettings(false);
applyCSSClassesToFolder(file.path, this.plugin);
});
@ -431,7 +431,6 @@ export class Commands {
.setIcon('eye')
.onClick(() => {
const excludedFolder = new ExcludedFolder(file.path, this.plugin.settings.excludeFolders.length, undefined, this.plugin);
excludedFolder.hideNote = true;
excludedFolder.subFolders = false;
excludedFolder.disableSync = false;
excludedFolder.disableAutoCreate = false;
@ -439,6 +438,7 @@ export class Commands {
excludedFolder.enableCollapsing = false;
excludedFolder.excludeFromFolderOverview = false;
excludedFolder.hideInSettings = true;
excludedFolder.showFolderNote = true;
addExcludedFolder(this.plugin, excludedFolder, false);
applyCSSClassesToFolder(file.path, this.plugin);
});

View file

@ -14,7 +14,7 @@ export class ExcludedFolder {
hideInSettings: boolean;
detached: boolean;
detachedFilePath?: string;
hideNote: boolean;
showFolderNote?: boolean;
constructor(path: string, position: number, id: string | undefined, plugin: FolderNotesPlugin) {
this.type = 'folder';
this.id = id || crypto.randomUUID();
@ -28,6 +28,6 @@ export class ExcludedFolder {
this.excludeFromFolderOverview = plugin.settings.excludeFolderDefaultSettings.excludeFromFolderOverview;
this.string = '';
this.hideInSettings = false;
this.hideNote = false;
this.showFolderNote = plugin.settings.excludeFolderDefaultSettings.showFolderNote;
}
}

View file

@ -14,7 +14,7 @@ export class ExcludePattern {
hideInSettings: boolean;
detached: boolean;
detachedFilePath?: string;
hideNote: boolean;
showFolderNote?: boolean;
constructor(pattern: string, position: number, id: string | undefined, plugin: FolderNotesPlugin) {
this.type = 'pattern';
this.id = id || crypto.randomUUID();
@ -28,5 +28,6 @@ export class ExcludePattern {
this.excludeFromFolderOverview = plugin.settings.excludePatternDefaultSettings.excludeFromFolderOverview;
this.path = '';
this.hideInSettings = false;
this.showFolderNote = plugin.settings.excludePatternDefaultSettings.showFolderNote;
}
}

View file

@ -32,8 +32,8 @@ export function getExcludedFolder(plugin: FolderNotesPlugin, path: string, inclu
'excludeFromFolderOverview',
'detached',
'hideInSettings',
'hideNote',
'id',
'showFolderNote',
];
if (combinedExcludedFolders.length > 0) {
@ -73,7 +73,6 @@ export function getExcludedFolder(plugin: FolderNotesPlugin, path: string, inclu
excludeFromFolderOverview: false,
hideInSettings: false,
detached: false,
hideNote: false,
};
}

View file

@ -54,6 +54,19 @@ export default class ExcludedFolderSettings extends Modal {
})
);
new Setting(contentEl)
.setName('Show folder note in the file explorer')
.setDesc('Choose if the folder note should be shown in the file explorer')
.addToggle((toggle) =>
toggle
.setValue(this.excludedFolder.showFolderNote ? this.excludedFolder.showFolderNote : false)
.onChange(async (value) => {
this.excludedFolder.showFolderNote = value;
await this.plugin.saveSettings();
this.display();
})
);
new Setting(contentEl)
.setName('Disable auto creation of folder notes in this folder')
.setDesc('Choose if a folder note should be created when a new folder is created')

View file

@ -56,6 +56,19 @@ export default class PatternSettings extends Modal {
})
);
new Setting(contentEl)
.setName('Show folder note in the file explorer')
.setDesc('Choose if the folder note should be shown in the file explorer')
.addToggle((toggle) =>
toggle
.setValue(this.pattern.showFolderNote ? this.pattern.showFolderNote : false)
.onChange(async (value) => {
this.pattern.showFolderNote = value;
await this.plugin.saveSettings();
this.display();
})
);
new Setting(contentEl)
.setName('Disable open folder note')
.setDesc('Choose if the folder note should be opened when the folder is opened')

View file

@ -56,7 +56,7 @@ export async function addObserver(plugin: FolderNotesPlugin) {
breadcrumb.setAttribute('old-name', folder.name || '');
breadcrumb.innerText = folder.newName || '';
}
const excludedFolder = await getExcludedFolder(plugin, folderPath, true);
const excludedFolder = getExcludedFolder(plugin, folderPath, true);
if (excludedFolder?.disableFolderNote) return;
const folderNote = getFolderNote(plugin, folderPath);
if (folderNote) {

View file

@ -13,7 +13,7 @@ export async function handleViewHeaderClick(event: MouseEvent, plugin: FolderNot
const folderPath = event.target.getAttribute('data-path');
if (!folderPath) { return; }
const excludedFolder = await getExcludedFolder(plugin, folderPath, true);
const excludedFolder = getExcludedFolder(plugin, folderPath, true);
if (excludedFolder?.disableFolderNote) {
event.target.onclick = null;
event.target.click();
@ -61,7 +61,7 @@ export async function handleFolderClick(event: MouseEvent, plugin: FolderNotesPl
const folderPath = event.target.parentElement?.getAttribute('data-path');
if (!folderPath) { return; }
const excludedFolder = await getExcludedFolder(plugin, folderPath, true);
const excludedFolder = getExcludedFolder(plugin, folderPath, true);
if (excludedFolder?.disableFolderNote) {
event.target.onclick = null;
event.target.click();

View file

@ -31,7 +31,7 @@ async function handleFileCreation(file: TFile, plugin: FolderNotesPlugin) {
const newFolder = await plugin.app.fileManager.createNewFolder(file.parent);
turnIntoFolderNote(plugin, file, newFolder);
} else if (folder instanceof TFolder) {
const detachedFolder = await getExcludedFolder(plugin, folder.path, true);
const detachedFolder = getExcludedFolder(plugin, folder.path, true);
if (detachedFolder) { return; }
const folderNote = getFolderNote(plugin, folder.path);
@ -59,7 +59,7 @@ async function handleFolderCreation(folder: TFolder, plugin: FolderNotesPlugin)
openFile = false;
}
const excludedFolder = await getExcludedFolder(plugin, folder.path, true);
const excludedFolder = getExcludedFolder(plugin, folder.path, true);
if (excludedFolder?.disableAutoCreate) return;
const folderNote = getFolderNote(plugin, folder.path);

View file

@ -55,7 +55,7 @@ export async function handleFileMove(file: TFile, oldPath: string, plugin: Folde
const oldFileName = removeExtension(getFileNameFromPathString(oldPath));
const newFolder = getFolderNoteFolder(plugin, file, file.basename);
const folderNote = getFolderNote(plugin, oldPath, plugin.settings.storageLocation, file);
let excludedFolder = await getExcludedFolder(plugin, newFolder?.path || '', true);
let excludedFolder = getExcludedFolder(plugin, newFolder?.path || '', true);
const oldFolder = getFolderNoteFolder(plugin, oldPath, oldFileName);
// file has been moved into position where it can be a folder note!
@ -101,7 +101,7 @@ export async function handleFolderRename(file: TFolder, oldPath: string, plugin:
if (!(folderNote instanceof TFile)) return;
const excludedFolder = await getExcludedFolder(plugin, file.path, true);
const excludedFolder = getExcludedFolder(plugin, file.path, true);
if (excludedFolder?.disableSync && !folderNote) {
return removeCSSClassFromEL(file.path, 'has-folder-note', plugin);
}
@ -138,7 +138,7 @@ export async function handleFileRename(file: TFile, oldPath: string, plugin: Fol
const folderName = extractFolderName(plugin.settings.folderNoteName, file.basename) || file.basename;
const oldFolderName = extractFolderName(plugin.settings.folderNoteName, oldFileName) || oldFileName;
const newFolder = getFolderNoteFolder(plugin, file, file.basename);
const excludedFolder = await getExcludedFolder(plugin, newFolder?.path || '', true);
const excludedFolder = getExcludedFolder(plugin, newFolder?.path || '', true);
const detachedExcludedFolder = getDetachedFolder(plugin, newFolder?.path || '');
const folderNote = getFolderNote(plugin, oldPath, plugin.settings.storageLocation, file);

View file

@ -203,7 +203,7 @@ export async function turnIntoFolderNote(plugin: FolderNotesPlugin, file: TFile,
}
export async function tempDisableSync(plugin: FolderNotesPlugin, folder: TFolder): Promise<[excludedFolder: ExcludedFolder | undefined, excludedFolderExisted: boolean, disabledSync: boolean]> {
let excludedFolder = await getExcludedFolder(plugin, folder.path, false);
let excludedFolder = getExcludedFolder(plugin, folder.path, false);
let excludedFolderExisted = true;
let disabledSync = false;

View file

@ -18,7 +18,7 @@ export function loadFileClasses(forceReload = false, plugin: FolderNotesPlugin)
return;
}
const excludedFolder = await getExcludedFolder(plugin, file.path, true);
const excludedFolder = getExcludedFolder(plugin, file.path, true);
// cleanup after ourselves
// Incase settings have changed
if (excludedFolder?.disableFolderNote) {
@ -26,7 +26,7 @@ export function loadFileClasses(forceReload = false, plugin: FolderNotesPlugin)
removeCSSClassFromEL(file.path, 'has-folder-note', plugin);
removeCSSClassFromEL(file?.path, 'only-has-folder-note', plugin);
} else {
if (!excludedFolder?.hideNote) {
if (!excludedFolder?.showFolderNote) {
addCSSClassToTitleEL(folderNote.path, 'is-folder-note', plugin);
}
addCSSClassesToFolder(file, plugin);
@ -48,17 +48,17 @@ export async function applyCSSClassesToFolder(folderPath: string, plugin: Folder
return;
}
const excludedFolder = await getExcludedFolder(plugin, folder.path, true);
const excludedFolder = getExcludedFolder(plugin, folder.path, true);
if (excludedFolder?.disableFolderNote) {
removeCSSClassFromEL(folderNote.path, 'is-folder-note', plugin);
removeCSSClassFromEL(folder.path, 'has-folder-note', plugin);
removeCSSClassFromEL(folder?.path, 'only-has-folder-note', plugin);
} else {
if (!excludedFolder?.hideNote) {
addCSSClassToFolderNote(folderNote, plugin);
}
addCSSClassesToFolder(folder, plugin);
if (excludedFolder?.showFolderNote) {
removeCSSClassFromFolderNote(folderNote, plugin);
return;
}
if (plugin.isEmptyFolderNoteFolder(folder)) {
addCSSClassToTitleEL(folder.path, 'only-has-folder-note', plugin);
} else {

View file

@ -121,7 +121,7 @@ export default class FolderNotesPlugin extends Plugin {
const folder = getFolder(this, openFile);
if (!folder) { return; }
const excludedFolder = await getExcludedFolder(this, folder.path, true);
const excludedFolder = getExcludedFolder(this, folder.path, true);
if (excludedFolder?.disableFolderNote) return;
const folderNote = getFolderNote(this, folder.path);
if (!folderNote) { return; }

View file

@ -154,7 +154,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
string: '',
hideInSettings: false,
detached: false,
hideNote: false,
showFolderNote: false,
},
excludePatternDefaultSettings: {
type: 'pattern',
@ -170,7 +170,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
string: '',
hideInSettings: false,
detached: false,
hideNote: false,
showFolderNote: false,
},
hideCollapsingIcon: false,
hideCollapsingIconForEmptyFolders: false,

View file

@ -65,7 +65,7 @@ export default class ConfirmationModal extends Modal {
const folders = this.app.vault.getAllLoadedFiles().filter((file) => file.parent instanceof TFolder);
for (const folder of folders) {
if (folder instanceof TFolder) {
const excludedFolder = await getExcludedFolder(this.plugin, folder.path, true);
const excludedFolder = getExcludedFolder(this.plugin, folder.path, true);
if (excludedFolder) continue;
if (folder.path === templateFolderPath) continue;
const folderNote = getFolderNote(this.plugin, folder.path);