mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Underline folder names that have folder notes
This commit is contained in:
parent
98b283f5c1
commit
b54082cf84
4 changed files with 58 additions and 19 deletions
|
|
@ -14,7 +14,7 @@ export class Commands {
|
|||
if (this.plugin.settings.excludeFolders.find((folder) => folder.path === file.path)) {
|
||||
menu.addItem((item) => {
|
||||
item.setTitle('Remove folder from excluded folders')
|
||||
.setIcon('x')
|
||||
.setIcon('trash')
|
||||
.onClick(() => {
|
||||
this.plugin.settings.excludeFolders = this.plugin.settings.excludeFolders.filter(
|
||||
(folder) => folder.path !== file.path);
|
||||
|
|
@ -26,7 +26,7 @@ export class Commands {
|
|||
}
|
||||
menu.addItem((item) => {
|
||||
item.setTitle('Exclude folder from folder notes')
|
||||
.setIcon('x')
|
||||
.setIcon('x-circle')
|
||||
.onClick(() => {
|
||||
const excludedFolder = new ExcludedFolder(file.path, this.plugin.settings.excludeFolders.length);
|
||||
this.plugin.settings.excludeFolders.push(excludedFolder);
|
||||
|
|
@ -47,7 +47,7 @@ export class Commands {
|
|||
} else {
|
||||
menu.addItem((item) => {
|
||||
item.setTitle('Create folder note')
|
||||
.setIcon('plus')
|
||||
.setIcon('edit')
|
||||
.onClick(() => {
|
||||
this.plugin.createFolderNote(file.path, true);
|
||||
});
|
||||
|
|
|
|||
43
src/main.ts
43
src/main.ts
|
|
@ -20,7 +20,33 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
} else {
|
||||
document.body.classList.remove('hide-folder-note');
|
||||
}
|
||||
if (this.settings.underlineFolder) {
|
||||
document.body.classList.add('folder-note-underline');
|
||||
} else {
|
||||
document.body.classList.remove('folder-note-underline');
|
||||
}
|
||||
new Commands(this.app, this).registerCommands();
|
||||
this.observer = new MutationObserver((mutations: MutationRecord[]) => {
|
||||
mutations.forEach((rec) => {
|
||||
if (rec.type === 'childList') {
|
||||
(<Element>rec.target).querySelectorAll('div.nav-folder-title-content')
|
||||
.forEach((element: HTMLElement) => {
|
||||
if (element.onclick) return;
|
||||
element.onclick = (event: MouseEvent) => this.handleFolderClick(event);
|
||||
if (!this.settings.underlineFolder) return;
|
||||
const folder = this.app.vault.getAbstractFileByPath(element.parentElement?.getAttribute('data-path') as string);
|
||||
if (!folder) return;
|
||||
if (this.app.vault.getAbstractFileByPath(folder.path + '/' + folder.name + '.md')) {
|
||||
element.classList.add('has-folder-note');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
this.observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
this.registerEvent(this.app.vault.on('create', (folder: TAbstractFile) => {
|
||||
if (!this.app.workspace.layoutReady) return;
|
||||
if (!this.settings.autoCreate) return;
|
||||
|
|
@ -106,22 +132,6 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
}));
|
||||
|
||||
this.observer = new MutationObserver((mutations: MutationRecord[]) => {
|
||||
mutations.forEach((rec) => {
|
||||
if (rec.type === 'childList') {
|
||||
(<Element>rec.target).querySelectorAll('div.nav-folder-title-content')
|
||||
.forEach((element: HTMLElement) => {
|
||||
if (element.onclick) return;
|
||||
element.onclick = (event: MouseEvent) => this.handleFolderClick(event);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
this.observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
}
|
||||
|
||||
async handleFolderClick(event: MouseEvent) {
|
||||
|
|
@ -155,6 +165,7 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
const path = folder + '/' + event.target.innerText + '.md';
|
||||
|
||||
if (this.app.vault.getAbstractFileByPath(path)) {
|
||||
event.target.classList.add('has-folder-note');
|
||||
this.openFolderNote(path);
|
||||
if (!this.settings.hideFolderNote) return;
|
||||
event.target.parentElement?.parentElement?.getElementsByClassName('nav-folder-children').item(0)?.querySelectorAll('div.nav-file')
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export interface FolderNotesSettings {
|
|||
enableCollapsing: boolean;
|
||||
excludeFolders: ExcludedFolder[];
|
||||
showDeleteConfirmation: boolean;
|
||||
underlineFolder: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
||||
|
|
@ -26,6 +27,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
enableCollapsing: false,
|
||||
excludeFolders: [],
|
||||
showDeleteConfirmation: true,
|
||||
underlineFolder: true
|
||||
};
|
||||
export class SettingsTab extends PluginSettingTab {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
|
@ -111,6 +113,25 @@ export class SettingsTab extends PluginSettingTab {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Add underline to folders with folder notes')
|
||||
.setDesc('Add an underline to folders that have a folder note')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.underlineFolder)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.underlineFolder = value;
|
||||
if (value) {
|
||||
document.body.classList.add('folder-note-underline');
|
||||
} else {
|
||||
document.body.classList.remove('folder-note-underline');
|
||||
}
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Template path')
|
||||
.setDesc('The path to the template file')
|
||||
|
|
|
|||
|
|
@ -4,6 +4,13 @@
|
|||
padding-top: 4px;
|
||||
}
|
||||
|
||||
.folder-note-underline .has-folder-note.nav-folder-title-content {
|
||||
text-decoration-line: underline;
|
||||
text-decoration-color: var(--text-faint);
|
||||
text-decoration-thickness: 2px;
|
||||
text-underline-offset: 1px;
|
||||
}
|
||||
|
||||
.nav-folder-title {
|
||||
padding-bottom: 0;
|
||||
padding-top: 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue