Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file order plugin support #185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/FileView/FileComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 6 additions & 2 deletions src/components/FolderView/NestedFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<React.Fragment>
{Array.isArray(props.folderTree.children) &&
Expand All @@ -227,7 +231,7 @@ export function NestedFolders(props: NestedFoldersProps) {
{(child.folder as TFolder).children.some((child) => child instanceof TFolder) ? (
<Tree
plugin={plugin}
content={child.folder.name}
content={getFolderName(child.folder)}
open={openFolders.contains(child.folder.path)}
onClick={() => handleFolderNameClick(child.folder.path)}
onDoubleClick={() => handleFolderNameDoubleClick(child.folder)}
Expand All @@ -243,7 +247,7 @@ export function NestedFolders(props: NestedFoldersProps) {
) : (
<Tree
plugin={plugin}
content={child.folder.name}
content={getFolderName(child.folder)}
onClick={() => handleFolderNameClick(child.folder.path)}
onDoubleClick={() => handleFolderNameDoubleClick(child.folder)}
onContextMenu={(e: MouseEvent) =>
Expand Down
12 changes: 12 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface FileTreeAlternativePluginSettings {
folderNote: boolean;
deleteFileOption: DeleteFileOption;
showFileNameAsFullPath: boolean;
hideFileOrderNumber: boolean;
}

export const DEFAULT_SETTINGS: FileTreeAlternativePluginSettings = {
Expand Down Expand Up @@ -63,6 +64,7 @@ export const DEFAULT_SETTINGS: FileTreeAlternativePluginSettings = {
folderNote: false,
deleteFileOption: 'trash',
showFileNameAsFullPath: false,
hideFileOrderNumber: false,
};

export class FileTreeAlternativePluginSettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -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.'
Expand Down