mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Save progress
This commit is contained in:
parent
1c794c18ea
commit
e4f6419687
4 changed files with 48 additions and 20 deletions
|
|
@ -3,18 +3,19 @@ import { Platform, Keymap } from 'obsidian';
|
|||
import { getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { handleFolderClick, handleViewHeaderClick } from './handleClick';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { applyCSSClassesToFolder } from 'src/functions/styleFunctions';
|
||||
import { applyCSSClassesToFolder, applyCSSClassesToFolderNote } from 'src/functions/styleFunctions';
|
||||
|
||||
export async function addObserver(plugin: FolderNotesPlugin) {
|
||||
plugin.observer = new MutationObserver((mutations: MutationRecord[]) => {
|
||||
mutations.forEach((rec) => {
|
||||
if (rec.type === 'childList') {
|
||||
(<Element>rec.target).querySelectorAll('div.nav-folder-title-content')
|
||||
.forEach((element: HTMLElement) => {
|
||||
.forEach(async (element: HTMLElement) => {
|
||||
if (element.onclick) return;
|
||||
if (Platform.isMobile && plugin.settings.disableOpenFolderNoteOnClick) return;
|
||||
const folderPath = element.parentElement?.getAttribute('data-path') || '';
|
||||
const apply = applyCSSClassesToFolder(folderPath, plugin);
|
||||
// console.log('folderPath', folderPath);
|
||||
const apply = await applyCSSClassesToFolder(folderPath, plugin);
|
||||
// handle middle click
|
||||
element.addEventListener('auxclick', (event: MouseEvent) => {
|
||||
if (event.button == 1) {
|
||||
|
|
@ -51,6 +52,11 @@ export async function addObserver(plugin: FolderNotesPlugin) {
|
|||
});
|
||||
});
|
||||
if (!plugin.settings.openFolderNoteOnClickInPath) { return; }
|
||||
(<Element>rec.target).querySelectorAll('div.nav-file-title-content')
|
||||
.forEach(async (element: HTMLElement) => {
|
||||
const filePath = element.parentElement?.getAttribute('data-path') || '';
|
||||
applyCSSClassesToFolderNote(filePath, plugin);
|
||||
});
|
||||
(<Element>rec.target).querySelectorAll('span.view-header-breadcrumb')
|
||||
.forEach((element: HTMLElement) => {
|
||||
const breadcrumbs = element.parentElement?.querySelectorAll('span.view-header-breadcrumb');
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export async function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugi
|
|||
const folder = file.parent;
|
||||
if (folder instanceof TFolder) {
|
||||
if (plugin.isEmptyFolderNoteFolder(folder)) {
|
||||
addCSSClassToTitleEL(plugin, folder.path, 'only-has-folder-note');
|
||||
addCSSClassToTitleEL(folder.path, 'only-has-folder-note');
|
||||
} else {
|
||||
removeCSSClassFromEL(folder.path, 'only-has-folder-note');
|
||||
}
|
||||
|
|
@ -31,8 +31,8 @@ async function handleFileCreation(file: TFile, plugin: FolderNotesPlugin) {
|
|||
const folderNote = getFolderNote(plugin, folder.path);
|
||||
|
||||
if (folderNote && folderNote.path === file.path) {
|
||||
addCSSClassToTitleEL(plugin, folder.path, 'has-folder-note');
|
||||
addCSSClassToTitleEL(plugin, file.path, 'is-folder-note');
|
||||
addCSSClassToTitleEL(folder.path, 'has-folder-note');
|
||||
addCSSClassToTitleEL(file.path, 'is-folder-note');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -57,5 +57,5 @@ async function handleFolderCreation(folder: TFolder, plugin: FolderNotesPlugin)
|
|||
if (folderNote) return;
|
||||
|
||||
createFolderNote(plugin, folder.path, openFile, undefined, true);
|
||||
addCSSClassToTitleEL(plugin, folder.path, 'has-folder-note');
|
||||
addCSSClassToTitleEL(folder.path, 'has-folder-note');
|
||||
}
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
import { TFile, TFolder } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getFolder, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getFileExplorer } from './utils';
|
||||
|
||||
export function loadFileClasses(forceReload = false, plugin: FolderNotesPlugin) {
|
||||
if (plugin.activeFileExplorer === getFileExplorer() && !forceReload) { return; }
|
||||
return;
|
||||
plugin.activeFileExplorer = getFileExplorer();
|
||||
plugin.app.vault.getAllLoadedFiles().forEach(async (file) => {
|
||||
if (!(file instanceof TFolder)) { return; }
|
||||
|
|
@ -36,9 +37,17 @@ export function loadFileClasses(forceReload = false, plugin: FolderNotesPlugin)
|
|||
|
||||
export async function applyCSSClassesToFolder(folderPath: string, plugin: FolderNotesPlugin) {
|
||||
const folder = plugin.app.vault.getAbstractFileByPath(folderPath);
|
||||
// console.log('folder', folder);
|
||||
// console.log('folderPath folder instanceof TFolder', folder instanceof TFolder);
|
||||
if (!folder || !(folder instanceof TFolder)) { return; }
|
||||
if ((folder.name === 'Untitled 2' && folder.parent?.name === 'Untitled 1')) {
|
||||
console.log('folder', folder);
|
||||
}
|
||||
|
||||
const folderNote = getFolderNote(plugin, folder.path);
|
||||
if ((folder.name === 'Untitled 2')) {
|
||||
console.log('folderNote', folderNote);
|
||||
}
|
||||
if (!folderNote) {
|
||||
removeCSSClassFromEL(folder?.path, 'has-folder-note');
|
||||
removeCSSClassFromEL(folder?.path, 'only-has-folder-note');
|
||||
|
|
@ -66,6 +75,17 @@ export async function applyCSSClassesToFolder(folderPath: string, plugin: Folder
|
|||
addCSSClassesToBothFolderAndNote(folderNote, folder, plugin);
|
||||
}
|
||||
|
||||
export async function applyCSSClassesToFolderNote(filePath: string, plugin: FolderNotesPlugin) {
|
||||
const file = plugin.app.vault.getAbstractFileByPath(filePath);
|
||||
if (!file || !(file instanceof TFile)) { return; }
|
||||
|
||||
const folder = getFolder(plugin, file);
|
||||
if (!folder || !(folder instanceof TFolder)) { return; }
|
||||
|
||||
applyCSSClassesToFolder(folder.path, plugin);
|
||||
|
||||
}
|
||||
|
||||
export function addCSSClassesToBothFolderAndNote(file: TFile, folder: TFolder, plugin: FolderNotesPlugin) {
|
||||
addCSSClassToFolderNote(file);
|
||||
addCSSClassesToFolder(folder, plugin);
|
||||
|
|
|
|||
26
src/main.ts
26
src/main.ts
|
|
@ -123,23 +123,24 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
});
|
||||
|
||||
if (this.app.workspace.layoutReady) {
|
||||
loadFileClasses(undefined, this);
|
||||
this.registerEvent(this.app.workspace.on('layout-change', () => {
|
||||
loadFileClasses(undefined, this);
|
||||
this.tabManager?.updateTabs();
|
||||
}));
|
||||
// loadFileClasses(undefined, this);
|
||||
// // this.registerEvent(this.app.workspace.on('layout-change', () => {
|
||||
// // loadFileClasses(undefined, this);
|
||||
// // this.tabManager?.updateTabs();
|
||||
// // }));
|
||||
} else {
|
||||
this.app.workspace.onLayoutReady(async () => {
|
||||
loadFileClasses(undefined, this)
|
||||
this.registerEvent(this.app.workspace.on('layout-change', () => {
|
||||
loadFileClasses(undefined, this);
|
||||
this.tabManager?.updateTabs();
|
||||
}));
|
||||
// loadFileClasses(undefined, this)
|
||||
// // this.registerEvent(this.app.workspace.on('layout-change', () => {
|
||||
// // loadFileClasses(undefined, this);
|
||||
// // this.tabManager?.updateTabs();
|
||||
// // }));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onLayoutReady() {
|
||||
// console.log('layout ready');
|
||||
if (this.settings.frontMatterTitle.enabled) {
|
||||
this.fmtpHandler = new FrontMatterTitlePluginHandler(this);
|
||||
}
|
||||
|
|
@ -153,6 +154,9 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
|
||||
// @ts-ignore
|
||||
const editMode = view.editMode ?? view.sourceMode ?? this.app.workspace.activeEditor?.editMode;
|
||||
if (!editMode) { return; }
|
||||
|
||||
// console.log('editMode', editMode);
|
||||
const plugin = this;
|
||||
|
||||
// @ts-ignore
|
||||
|
|
@ -263,8 +267,6 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
return;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
// For some reason it gives an error even though it works
|
||||
fileExplorerItem = fileExplorerItem?.querySelector('div.nav-folder-title-content')
|
||||
if (!fileExplorerItem) { return; }
|
||||
if (this.settings.frontMatterTitle.explorer && this.settings.frontMatterTitle.enabled) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue