getDetachedFolder & includeDetached folder option

This commit is contained in:
Lost Paul 2024-06-15 17:55:47 +02:00
parent df3b30a422
commit f1b181e772
9 changed files with 41 additions and 17 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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; }

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 = 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) {

View file

@ -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);

View file

@ -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 = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon right-triangle"><path d="M3 8L12 17L21 8"></path></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;

View file

@ -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) {

View file

@ -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; }

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 = 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);