diff --git a/manifest.json b/manifest.json index aaf9b3b..511dd7a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "folder-notes", "name": "Folder notes", - "version": "1.6.8", + "version": "1.6.9", "minAppVersion": "0.15.0", "description": "Create notes within folders that can be accessed without collapsing the folder, similar to the functionality offered in Notion.", "author": "Lost Paul", diff --git a/src/main.ts b/src/main.ts index 95d6bd2..54b2c00 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { Plugin, TFile, TFolder, TAbstractFile, MarkdownPostProcessorContext, parseYaml, Notice } from 'obsidian'; +import { Plugin, TFile, TFolder, TAbstractFile, MarkdownPostProcessorContext, parseYaml, Notice, Platform } from 'obsidian'; import { DEFAULT_SETTINGS, FolderNotesSettings, SettingsTab } from './settings/SettingsTab'; import { Commands } from './Commands'; import { FileExplorerWorkspaceLeaf } from './globals'; @@ -45,6 +45,7 @@ export default class FolderNotesPlugin extends Plugin { (rec.target).querySelectorAll('div.nav-folder-title-content') .forEach((element: HTMLElement) => { if (element.onclick) return; + if (Platform.isMobile && this.settings.disableOpenFolderNoteOnClick) return; element.onclick = (event: MouseEvent) => handleFolderClick(event, this); }); if (!this.settings.openFolderNoteOnClickInPath) { return; } @@ -87,18 +88,17 @@ export default class FolderNotesPlugin extends Plugin { childList: true, subtree: true, }); + this.registerEvent(this.app.workspace.on('layout-change', () => { this.loadFileClasses(); })); + this.registerEvent(this.app.vault.on('delete', (file: TAbstractFile) => { if (!(file instanceof TFile)) { return; } - // parent is null here even if the parent exists - // not entirely sure why - const parentPath = this.getFolderPathFromString(file.path); - const parentName = this.getFileNameFromPathString(parentPath); - if (parentName !== file.basename) { return; } - this.removeCSSClassFromEL(parentPath, 'has-folder-note'); + const parentFolder = getFolder(this, file); + this.removeCSSClassFromEL(parentFolder?.path, 'has-folder-note'); })); + this.registerEvent(this.app.vault.on('create', (file: TAbstractFile) => { if (file instanceof TFile) { const folderName = extractFolderName(this.settings.folderNoteName, file.basename); @@ -145,6 +145,7 @@ export default class FolderNotesPlugin extends Plugin { return handleFileRename(file, oldPath, this); } })); + this.registerEvent(this.app.vault.on('delete', (file: TAbstractFile) => { if (file instanceof TFile) { const folder = getFolder(this, file); @@ -189,6 +190,18 @@ export default class FolderNotesPlugin extends Plugin { try { const folderOverview = new FolderOverview(this, ctx, source, el); folderOverview.create(this, parseYaml(source), el, ctx); + + // this.app.vault.on('delete', () => { + // folderOverview.create(this, parseYaml(source), el, ctx); + // }); + + // this.app.vault.on('rename', () => { + // folderOverview.create(this, parseYaml(source), el, ctx); + // }); + + // this.app.vault.on('create', () => { + // folderOverview.create(this, parseYaml(source), el, ctx); + // }); } catch (e) { new Notice('Error creating folder overview (folder notes plugin) - check console for more details'); console.error(e); diff --git a/src/settings/FileExplorerSettings.ts b/src/settings/FileExplorerSettings.ts index f000423..87c89eb 100644 --- a/src/settings/FileExplorerSettings.ts +++ b/src/settings/FileExplorerSettings.ts @@ -22,6 +22,21 @@ export async function renderFileExplorer(settingsTab: SettingsTab) { }) ); + const setting2 = new Setting(containerEl) + .setName('Don\'t open folder notes by clicking on the name (on mobile)') + .setDesc('Folder notes don\'t open when clicking on the name of the folder (on mobile)') + .addToggle((toggle) => + toggle + .setValue(settingsTab.plugin.settings.disableOpenFolderNoteOnClick) + .onChange(async (value) => { + settingsTab.plugin.settings.disableOpenFolderNoteOnClick = value; + await settingsTab.plugin.saveSettings(); + }) + ); + + setting2.infoEl.appendText('Requires a restart to take effect'); + setting2.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed'; + new Setting(containerEl) .setName('Only open folder notes through the name') .setDesc('Only open folder notes in the file explorer by clicking on the folder name') @@ -122,17 +137,17 @@ export async function renderFileExplorer(settingsTab: SettingsTab) { .setName('Cursive the name of folder notes') .setDesc('Make the folder name cursive in the file explorer') .addToggle((toggle) => - toggle - .setValue(settingsTab.plugin.settings.cursiveName) - .onChange(async (value) => { - settingsTab.plugin.settings.cursiveName = value; - if (value) { - document.body.classList.add('folder-note-cursive'); - } else { - document.body.classList.remove('folder-note-cursive'); - } - await settingsTab.plugin.saveSettings(); - }) - ); + toggle + .setValue(settingsTab.plugin.settings.cursiveName) + .onChange(async (value) => { + settingsTab.plugin.settings.cursiveName = value; + if (value) { + document.body.classList.add('folder-note-cursive'); + } else { + document.body.classList.remove('folder-note-cursive'); + } + await settingsTab.plugin.saveSettings(); + }) + ); } diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts index 4a0f69a..1aadef8 100644 --- a/src/settings/SettingsTab.ts +++ b/src/settings/SettingsTab.ts @@ -45,6 +45,7 @@ export interface FolderNotesSettings { boldNameInPath: boolean; cursiveName: boolean; cursiveNameInPath: boolean; + disableOpenFolderNoteOnClick: boolean; } export const DEFAULT_SETTINGS: FolderNotesSettings = { @@ -98,6 +99,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = { boldNameInPath: false, cursiveName: false, cursiveNameInPath: false, + disableOpenFolderNoteOnClick: false, }; export class SettingsTab extends PluginSettingTab {