From 1b45d613a2dd12a02590c948494b58b53b1173d0 Mon Sep 17 00:00:00 2001 From: Houcheng Lin Date: Sun, 17 Dec 2023 18:37:36 +0800 Subject: [PATCH] Add file order plugin support --- src/components/FileView/FileComponent.tsx | 3 ++- src/components/FolderView/NestedFolders.tsx | 8 ++++++-- src/settings.ts | 12 ++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/components/FileView/FileComponent.tsx b/src/components/FileView/FileComponent.tsx index 467dc82..5d57902 100644 --- a/src/components/FileView/FileComponent.tsx +++ b/src/components/FileView/FileComponent.tsx @@ -573,7 +573,8 @@ const NavFile = (props: { file: TFile; plugin: FileTreeAlternativePlugin }) => { const fileDisplayName = useMemo(() => { let displayName = plugin.settings.showFileNameAsFullPath ? file.path : file.name; - return Util.getFileNameAndExtension(displayName).fileName; + let displayFileName = Util.getFileNameAndExtension(displayName).fileName; + return plugin.settings.hideFileOrderNumber ? displayFileName.replace(/^\d{1,4}[- ]/, '') : displayFileName; }, [plugin.settings.showFileNameAsFullPath, file.path]); return ( diff --git a/src/components/FolderView/NestedFolders.tsx b/src/components/FolderView/NestedFolders.tsx index 6609be4..dd88cec 100644 --- a/src/components/FolderView/NestedFolders.tsx +++ b/src/components/FolderView/NestedFolders.tsx @@ -218,6 +218,10 @@ export function NestedFolders(props: NestedFoldersProps) { [props.folderTree.children, excludedFolders, plugin.settings.sortFoldersBy] ); + let getFolderName = (folder: TFolder) => { + return plugin.settings.hideFileOrderNumber ? folder.name.replace(/^\d{1,4}[- ]/, '') : folder.name; + } + return ( {Array.isArray(props.folderTree.children) && @@ -227,7 +231,7 @@ export function NestedFolders(props: NestedFoldersProps) { {(child.folder as TFolder).children.some((child) => child instanceof TFolder) ? ( handleFolderNameClick(child.folder.path)} onDoubleClick={() => handleFolderNameDoubleClick(child.folder)} @@ -243,7 +247,7 @@ export function NestedFolders(props: NestedFoldersProps) { ) : ( handleFolderNameClick(child.folder.path)} onDoubleClick={() => handleFolderNameDoubleClick(child.folder)} onContextMenu={(e: MouseEvent) => diff --git a/src/settings.ts b/src/settings.ts index 6eaa081..66cd1b1 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -35,6 +35,7 @@ export interface FileTreeAlternativePluginSettings { folderNote: boolean; deleteFileOption: DeleteFileOption; showFileNameAsFullPath: boolean; + hideFileOrderNumber: boolean; } export const DEFAULT_SETTINGS: FileTreeAlternativePluginSettings = { @@ -63,6 +64,7 @@ export const DEFAULT_SETTINGS: FileTreeAlternativePluginSettings = { folderNote: false, deleteFileOption: 'trash', showFileNameAsFullPath: false, + hideFileOrderNumber: false, }; export class FileTreeAlternativePluginSettingsTab extends PluginSettingTab { @@ -393,6 +395,16 @@ export class FileTreeAlternativePluginSettingsTab extends PluginSettingTab { }) ); + new Setting(containerEl) + .setName('Hide File Order Number') + .setDesc('Turn on if you want to hide numbers of file order plugin.') + .addToggle((toggle) => + toggle.setValue(this.plugin.settings.hideFileOrderNumber).onChange((value) => { + this.plugin.settings.hideFileOrderNumber = value; + this.plugin.saveSettings(); + }) + ); + new Setting(containerEl) .setDesc( 'Use this button to reload the file tree. Reloading the file tree is required for some of the settings. You can also restart your vault to have same effect.'