This commit is contained in:
Lost Paul 2025-06-20 17:35:28 +02:00
parent ed4018de09
commit 192ecd3cd7
3 changed files with 49 additions and 13 deletions

View file

@ -8,6 +8,7 @@ import NewFolderNameModal from '../../modals/NewFolderName';
import { CustomEventEmitter } from './utils/EventEmitter';
import FolderOverviewPlugin from './main';
import FolderNotesPlugin from '../../main';
import { getFolder } from '../../functions/folderNoteFunctions';
export type includeTypes = 'folder' | 'markdown' | 'canvas' | 'other' | 'pdf' | 'image' | 'audio' | 'video' | 'all';
@ -59,10 +60,34 @@ export class FolderOverview {
this.source = source;
this.el = el;
this.sourceFilePath = this.ctx.sourcePath;
const sourceFolder = this.plugin.app.vault.getAbstractFileByPath(getFolderPathFromString(ctx.sourcePath));
if (sourceFolder instanceof TFolder) {
this.sourceFolder = sourceFolder;
switch (yaml?.folderPath.trim()) {
case 'Files parent folder path':
yaml.folderPath = getFolderPathFromString(ctx.sourcePath);
break;
case 'Path of folder linked to the file': {
const sourceFile = this.plugin.app.vault.getAbstractFileByPath(ctx.sourcePath);
if (plugin instanceof FolderNotesPlugin && sourceFile instanceof TFile) {
const folderNoteFolder = getFolder(plugin, sourceFile);
if (folderNoteFolder instanceof TFolder) {
this.sourceFolder = folderNoteFolder;
yaml.folderPath = folderNoteFolder.path;
} else {
yaml.folderPath = '';
}
}
break;
}
default: {
const sourceFolder = this.plugin.app.vault.getAbstractFileByPath(getFolderPathFromString(ctx.sourcePath));
if (sourceFolder instanceof TFolder) {
yaml.folderPath = sourceFolder.path;
this.sourceFolder = sourceFolder;
}
break;
}
}
this.defaultSettings = defaultSettings;
this.yaml = {
id: yaml?.id ?? crypto.randomUUID(),
@ -85,7 +110,6 @@ export class FolderOverview {
allowDragAndDrop: yaml?.allowDragAndDrop ?? defaultSettings.allowDragAndDrop,
};
const customChild = new CustomMarkdownRenderChild(el, this);
ctx.addChild(customChild);
}

View file

@ -142,10 +142,13 @@ export async function createOverviewSettings(contentEl: HTMLElement, yaml: overv
.setPlaceholder('Folder path')
.setValue(yaml?.folderPath || '')
.onChange(async (value) => {
if (value.trim() !== '') {
const whiteList = ['Files parent folder path', 'Path of folder linked to the file'];
if (value.trim() !== '' && !whiteList.includes(value.trim())) {
value = normalizePath(value);
}
if (!(plugin.app.vault.getAbstractFileByPath(value) instanceof TFolder) && value !== '') return;
if (!whiteList.includes(value.trim())) {
if (!(plugin.app.vault.getAbstractFileByPath(value) instanceof TFolder) && value !== '') return;
}
yaml.folderPath = value;
updateSettings(contentEl, yaml, plugin, defaultSettings, el, ctx, file);
});

View file

@ -4,15 +4,15 @@ import { TAbstractFile, TFolder, AbstractInputSuggest } from 'obsidian';
import FolderOverviewPlugin from '../main';
import FolderNotesPlugin from '../../../main';
export enum FileSuggestMode {
TemplateFiles,
ScriptFiles,
TemplateFiles,
ScriptFiles,
}
export class FolderSuggest extends AbstractInputSuggest<TFolder> {
plugin: FolderOverviewPlugin | FolderNotesPlugin;
constructor(
public inputEl: HTMLInputElement,
plugin: FolderOverviewPlugin | FolderNotesPlugin,
public inputEl: HTMLInputElement,
plugin: FolderOverviewPlugin | FolderNotesPlugin,
private whitelistSuggester: boolean,
public folder?: TFolder,
) {
@ -27,13 +27,22 @@ export class FolderSuggest extends AbstractInputSuggest<TFolder> {
if (this.folder) {
files = this.folder.children;
} else {
files = this.plugin.app.vault.getAllLoadedFiles().slice(0,100);
files = this.plugin.app.vault.getAllLoadedFiles().slice(0, 100);
}
// @ts-ignore
folders.push({ path: 'Files parent folder path' });
if (this.plugin instanceof FolderNotesPlugin) {
// @ts-ignore
folders.push({ path: 'Path of folder linked to the file' });
}
files.forEach((folder: TAbstractFile) => {
if (
folder instanceof TFolder &&
folder.path.toLowerCase().contains(lower_input_str) &&
(this.plugin instanceof FolderNotesPlugin ? (!this.plugin.settings.excludeFolders.find((f: any) => f.path === folder.path) || this.whitelistSuggester) : true)
folder.path.toLowerCase().contains(lower_input_str) &&
(this.plugin instanceof FolderNotesPlugin ? (!this.plugin.settings.excludeFolders.find((f: any) => f.path === folder.path) || this.whitelistSuggester) : true)
) {
folders.push(folder);
}