diff --git a/src/ExcludeFolders/ExcludeFolder.ts b/src/ExcludeFolders/ExcludeFolder.ts index 9dd11d6..5a56fdb 100644 --- a/src/ExcludeFolders/ExcludeFolder.ts +++ b/src/ExcludeFolders/ExcludeFolder.ts @@ -12,6 +12,8 @@ export class ExcludedFolder { position: number; excludeFromFolderOverview: boolean; hideInSettings: boolean; + detached: boolean; + detachedFilePath?: string; constructor(path: string, position: number, id: string | undefined, plugin: FolderNotesPlugin) { this.type = 'folder'; this.id = id || crypto.randomUUID(); diff --git a/src/ExcludeFolders/ExcludePattern.ts b/src/ExcludeFolders/ExcludePattern.ts index 9dead29..e342890 100644 --- a/src/ExcludeFolders/ExcludePattern.ts +++ b/src/ExcludeFolders/ExcludePattern.ts @@ -12,6 +12,8 @@ export class ExcludePattern { enableCollapsing: boolean; excludeFromFolderOverview: boolean; hideInSettings: boolean; + detached: boolean; + detachedFilePath?: string; constructor(pattern: string, position: number, id: string | undefined, plugin: FolderNotesPlugin) { this.type = 'pattern'; this.id = id || crypto.randomUUID(); diff --git a/src/ExcludeFolders/functions/folderFunctions.ts b/src/ExcludeFolders/functions/folderFunctions.ts index 7188d0b..295cf75 100644 --- a/src/ExcludeFolders/functions/folderFunctions.ts +++ b/src/ExcludeFolders/functions/folderFunctions.ts @@ -11,22 +11,27 @@ import { getWhitelistedFolder } from './whitelistFolderFunctions'; import { WhitelistedFolder } from '../WhitelistFolder'; import { WhitelistedPattern } from '../WhitelistPattern'; -export function getExcludedFolder(plugin: FolderNotesPlugin, path: string) { +export function getExcludedFolder(plugin: FolderNotesPlugin, path: string, includeDetached: boolean, pathOnly?: boolean, ignoreWhitelist?: boolean) { let excludedFolder = {} as ExcludedFolder | ExcludePattern | undefined; const whitelistedFolder = getWhitelistedFolder(plugin, path) as WhitelistedFolder | WhitelistedPattern | undefined; const folderName = getFolderNameFromPathString(path); - const matchedPatterns = getExcludedFoldersByPattern(plugin, folderName); + let matchedPatterns = getExcludedFoldersByPattern(plugin, folderName); const excludedFolders = getExcludedFoldersByPath(plugin, path); - const combinedExcludedFolders = [...matchedPatterns, ...excludedFolders]; - console.log('excludedFolders', excludedFolders) - console.log('combinedExcludedFolders', combinedExcludedFolders) + if (pathOnly) { matchedPatterns = []; } + let combinedExcludedFolders = [...matchedPatterns, ...excludedFolders]; + + if (!includeDetached) { + combinedExcludedFolders = combinedExcludedFolders.filter(f => !f.detached) + } const propertiesToCopy: (keyof ExcludedFolder)[] = [ 'disableAutoCreate', 'disableFolderNote', 'disableSync', 'enableCollapsing', - 'excludeFromFolderOverview' + 'excludeFromFolderOverview', + 'detached', + 'hideInSettings' ]; if (combinedExcludedFolders.length > 0) { @@ -39,16 +44,21 @@ export function getExcludedFolder(plugin: FolderNotesPlugin, path: string) { } }); } + } else { + excludedFolder = undefined; } - console.log('excludedFolder', excludedFolder) - if (whitelistedFolder && excludedFolder) { + if (excludedFolder?.detached) { ignoreWhitelist = true; } + + if (whitelistedFolder && excludedFolder && !ignoreWhitelist) { + console.log('whitelistedFolder', whitelistedFolder) excludedFolder.disableAutoCreate ? excludedFolder.disableAutoCreate = !whitelistedFolder.enableAutoCreate : ''; excludedFolder.disableFolderNote ? excludedFolder.disableFolderNote = !whitelistedFolder.enableFolderNote : ''; excludedFolder.disableSync ? excludedFolder.disableSync = !whitelistedFolder.enableSync : ''; excludedFolder.enableCollapsing = whitelistedFolder.enableCollapsing; excludedFolder.excludeFromFolderOverview ? excludedFolder.excludeFromFolderOverview = !whitelistedFolder.showInFolderOverview : ''; } else if (excludedFolder && Object.keys(excludedFolder).length === 0) { + console.log('Hello from the other side') excludedFolder = { type: 'folder', id: '', @@ -61,13 +71,19 @@ export function getExcludedFolder(plugin: FolderNotesPlugin, path: string) { enableCollapsing: false, position: 0, excludeFromFolderOverview: false, - hideInSettings: false + hideInSettings: false, + detached: false } } return excludedFolder; } +export function getDetachedFolder(plugin: FolderNotesPlugin, path: string) { + return plugin.settings.excludeFolders.find(f => f.path == path && f.detached); +} + + export function getExcludedFolderByPath(plugin: FolderNotesPlugin, path: string) { return plugin.settings.excludeFolders.find((excludedFolder) => { if (path.trim() === '' || !excludedFolder.path) { return false; } @@ -87,7 +103,6 @@ export function getExcludedFolderByPath(plugin: FolderNotesPlugin, path: string) export function getExcludedFoldersByPath(plugin: FolderNotesPlugin, path: string) { return plugin.settings.excludeFolders.filter((excludedFolder) => { - console.log('excludedFolder path', excludedFolder.path) if (path.trim() === '' || !excludedFolder.path) { return false; } if (excludedFolder.path === path) { return true; } if (!excludedFolder.subFolders) { return false; } diff --git a/src/events/handleClick.ts b/src/events/handleClick.ts index 2d9ace1..5ffc3b2 100644 --- a/src/events/handleClick.ts +++ b/src/events/handleClick.ts @@ -13,7 +13,7 @@ export async function handleViewHeaderClick(event: MouseEvent, plugin: FolderNot const folderPath = event.target.getAttribute('data-path'); if (!folderPath) { return; } - const excludedFolder = getExcludedFolder(plugin, folderPath); + const excludedFolder = getExcludedFolder(plugin, folderPath, true); if (excludedFolder?.disableFolderNote) { event.target.onclick = null; event.target.click(); @@ -51,11 +51,12 @@ export async function handleFolderClick(event: MouseEvent, plugin: FolderNotesPl if (!(event.target instanceof HTMLElement)) return; if (!event || !event.target) return; event.stopImmediatePropagation(); + console.log('handleFolderClick', event.target); const folderPath = event.target.parentElement?.getAttribute('data-path'); if (!folderPath) { return; } - const excludedFolder = getExcludedFolder(plugin, folderPath); + const excludedFolder = getExcludedFolder(plugin, folderPath, true); if (excludedFolder?.disableFolderNote) { event.target.onclick = null; event.target.click(); @@ -66,6 +67,7 @@ export async function handleFolderClick(event: MouseEvent, plugin: FolderNotesPl } const folderNote = getFolderNote(plugin, folderPath); + console.log('folderNote', folderNote); if (folderNote) { if (plugin.settings.openByClick) { diff --git a/src/events/handleCreate.ts b/src/events/handleCreate.ts index 7d515b0..f5bde1c 100644 --- a/src/events/handleCreate.ts +++ b/src/events/handleCreate.ts @@ -45,7 +45,7 @@ export function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugin) { openFile = false; } - const excludedFolder = getExcludedFolder(plugin, file.path); + const excludedFolder = getExcludedFolder(plugin, file.path, true); if (excludedFolder?.disableAutoCreate) return; const folderNote = getFolderNote(plugin, file.path); diff --git a/src/folderOverview/FolderOverview.ts b/src/folderOverview/FolderOverview.ts index 609d269..c9c3b5b 100644 --- a/src/folderOverview/FolderOverview.ts +++ b/src/folderOverview/FolderOverview.ts @@ -267,7 +267,7 @@ export class FolderOverview { if (child instanceof TFolder) { const folderNote = getFolderNote(this.plugin, child.path); if (folderNote) { this.pathBlacklist.push(folderNote.path); } - const excludedFolder = getExcludedFolder(this.plugin, child.path); + const excludedFolder = getExcludedFolder(this.plugin, child.path, true); if (excludedFolder?.excludeFromFolderOverview) { continue; } const svg = ''; const folderElement = childrenElement.createDiv({ @@ -412,7 +412,7 @@ export class FolderOverview { const folderPath = getFolderPathFromString(file.path); if (!folderPath.startsWith(sourceFolderPath) && sourceFolderPath !== '/') { return false; } if (file.path === this.sourceFilePath) { return false; } - const excludedFolder = getExcludedFolder(plugin, file.path); + const excludedFolder = getExcludedFolder(plugin, file.path, true); if (excludedFolder?.excludeFromFolderOverview) { return false; } if ((file.path.split('/').length - sourceFolderPath.split('/').length) - 1 < depth) { return true; diff --git a/src/functions/styleFunctions.ts b/src/functions/styleFunctions.ts index 16733f7..014fc71 100644 --- a/src/functions/styleFunctions.ts +++ b/src/functions/styleFunctions.ts @@ -16,7 +16,7 @@ export function loadFileClasses(forceReload = false, plugin: FolderNotesPlugin) return; } - const excludedFolder = getExcludedFolder(plugin, file.path); + const excludedFolder = getExcludedFolder(plugin, file.path, true); // cleanup after ourselves // Incase settings have changed if (excludedFolder?.disableFolderNote) { diff --git a/src/main.ts b/src/main.ts index a16500d..0159dfb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,6 +14,7 @@ import { TabManager } from './events/TabManager'; import './functions/ListComponent'; import { handleDelete } from './events/handleDelete'; import { getEl, loadFileClasses, removeCSSClassFromEL } from './functions/styleFunctions'; +import { getExcludedFolder } from './ExcludeFolders/functions/folderFunctions'; export default class FolderNotesPlugin extends Plugin { observer: MutationObserver; settings: FolderNotesSettings; @@ -105,6 +106,8 @@ export default class FolderNotesPlugin extends Plugin { const folder = getFolder(this, openFile); if (!folder) { return; } + const excludedFolder = getExcludedFolder(this, folder.path, true) + if (excludedFolder?.disableFolderNote) return; const folderNote = getFolderNote(this, folder.path); if (!folderNote) { return; } if (folderNote.path !== openFile.path) { return; } diff --git a/src/modals/ConfirmCreation.ts b/src/modals/ConfirmCreation.ts index 997768e..2f859b1 100644 --- a/src/modals/ConfirmCreation.ts +++ b/src/modals/ConfirmCreation.ts @@ -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 = getExcludedFolder(this.plugin, folder.path); + const excludedFolder = getExcludedFolder(this.plugin, folder.path, true); if (excludedFolder) continue; if (folder.path === templateFolderPath) continue; const folderNote = getFolderNote(this.plugin, folder.path);