From e4e1259e26ab978c2bd679f7d939860f4274949a Mon Sep 17 00:00:00 2001 From: Nicolas Ramz Date: Mon, 13 May 2024 14:49:27 +0200 Subject: [PATCH] Menus: added sort method + sort order items --- src/components/App.tsx | 2 + src/components/dialogs/ShortcutsDialog.tsx | 10 +++++ src/components/shortcuts/MenuAccelerators.tsx | 24 +++++++++++ src/electron/appMenus.ts | 43 +++++++++++++++++++ src/locale/lang/en.json | 13 +++++- src/locale/lang/fr.json | 11 ++++- src/types/index.ts | 3 ++ 7 files changed, 103 insertions(+), 3 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index a42f685..65ece28 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -79,6 +79,8 @@ const App = observer(() => { clipboardLength: appState.clipboard.files.length, activeViewId: activeView.viewId, viewMode: activeView.getVisibleCache().viewmode, + sortMethod: activeView.getVisibleCache().sortMethod, + sortOrder: activeView.getVisibleCache().sortOrder, // missing: about opened, tab: is it needed? } }, [appState]) diff --git a/src/components/dialogs/ShortcutsDialog.tsx b/src/components/dialogs/ShortcutsDialog.tsx index e2acf1e..4f13af3 100644 --- a/src/components/dialogs/ShortcutsDialog.tsx +++ b/src/components/dialogs/ShortcutsDialog.tsx @@ -41,6 +41,16 @@ export const buildShortcuts = async (t: TFunction<'translation', undefined>): Pr [t('SHORTCUT.GROUP.ACTIVE_VIEW')]: [ { combo: `mod + ${keyboardLayoutMap['Digit1']}`, label: t('SHORTCUT.ACTIVE_VIEW.ICON_MODE') }, { combo: `mod + ${keyboardLayoutMap['Digit2']}`, label: t('SHORTCUT.ACTIVE_VIEW.TABLE_MODE') }, + { combo: `mod + alt + ${keyboardLayoutMap['Digit1']}`, label: t('SHORTCUT.ACTIVE_VIEW.SORT_BY_NAME') }, + { combo: `mod + alt + ${keyboardLayoutMap['Digit2']}`, label: t('SHORTCUT.ACTIVE_VIEW.SORT_BY_SIZE') }, + { + combo: `mod + shift + alt + ${keyboardLayoutMap['Digit1']}`, + label: t('SHORTCUT.ACTIVE_VIEW.SORT_ORDER_DESCENDING'), + }, + { + combo: `mod + shift + alt + ${keyboardLayoutMap['Digit2']}`, + label: t('SHORTCUT.ACTIVE_VIEW.SORT_ORDER_ASCENDING'), + }, { combo: 'space', label: t('SHORTCUT.ACTIVE_VIEW.OPEN_PREVIEW') }, { combo: (isMac && 'mod + left') || 'alt + left', label: t('SHORTCUT.ACTIVE_VIEW.BACKWARD_HISTORY') }, { combo: (isMac && 'mod + right') || 'alt + right', label: t('SHORTCUT.ACTIVE_VIEW.FORWARD_HISTORY') }, diff --git a/src/components/shortcuts/MenuAccelerators.tsx b/src/components/shortcuts/MenuAccelerators.tsx index ce5cafd..b98ae9d 100644 --- a/src/components/shortcuts/MenuAccelerators.tsx +++ b/src/components/shortcuts/MenuAccelerators.tsx @@ -193,6 +193,26 @@ class MenuAcceleratorsClass extends React.Component { cache.viewmode !== 'details' && cache.setViewMode('details') } + onSortByName = (): void => { + const cache = this.getActiveFileCache() + cache.sortMethod !== 'name' && cache.setSort('name') + } + + onSortBySize = (): void => { + const cache = this.getActiveFileCache() + cache.sortMethod !== 'size' && cache.setSort('size') + } + + onSortOrderAsc = (): void => { + const cache = this.getActiveFileCache() + cache.sortOrder !== 'asc' && cache.setSort(cache.sortMethod, 'asc') + } + + onSortOrderDesc = (): void => { + const cache = this.getActiveFileCache() + cache.sortOrder !== 'desc' && cache.setSort(cache.sortMethod, 'desc') + } + renderMenuAccelerators(): React.ReactElement { return ( @@ -215,6 +235,10 @@ class MenuAcceleratorsClass extends React.Component { + + + + ) } diff --git a/src/electron/appMenus.ts b/src/electron/appMenus.ts index 9f5deb0..b3185f6 100644 --- a/src/electron/appMenus.ts +++ b/src/electron/appMenus.ts @@ -95,11 +95,15 @@ export class AppMenu { filesLength, status, viewMode, + sortMethod, + sortOrder, }: ReactiveProperties): MenuItemConstructorOptions[] { const menuStrings = this.menuStrings const explorerWithoutOverlay = !isOverlayOpen && isExplorer const explorerWithoutOverlayCanWrite = explorerWithoutOverlay && !isReadonly && status === 'ok' const isIconViewMode = viewMode === 'icons' + const isSortByName = sortMethod === 'name' + const isSortAscending = sortOrder === 'asc' let windowMenuIndex = 4 @@ -215,6 +219,45 @@ export class AppMenu { checked: !isIconViewMode, }, { type: 'separator' }, + { + label: menuStrings['SORT_BY'], + enabled: explorerWithoutOverlay, + submenu: [ + { + label: menuStrings['SORT_BY_NAME'], + type: 'radio', + accelerator: 'CmdOrCtrl+Alt+1', + click: this.sendComboEvent, + enabled: explorerWithoutOverlay, + checked: isSortByName, + }, + { + label: menuStrings['SORT_BY_SIZE'], + type: 'radio', + accelerator: 'CmdOrCtrl+Alt+2', + click: this.sendComboEvent, + enabled: explorerWithoutOverlay, + checked: !isSortByName, + }, + { type: 'separator' }, + { + label: menuStrings['SORT_ASCENDING'], + type: 'checkbox', + click: this.sendComboEvent, + accelerator: 'CmdOrCtrl+Shift+Alt+1', + enabled: explorerWithoutOverlay, + checked: isSortAscending, + }, + { + label: menuStrings['SORT_DESCENDING'], + type: 'checkbox', + click: this.sendComboEvent, + accelerator: 'CmdOrCtrl+Shift+Alt+2', + enabled: explorerWithoutOverlay, + checked: !isSortAscending, + }, + ], + }, { label: menuStrings['TOGGLE_SPLITVIEW'], accelerator: 'CmdOrCtrl+Shift+Alt+V', diff --git a/src/locale/lang/en.json b/src/locale/lang/en.json index bcc6ec6..4d51863 100644 --- a/src/locale/lang/en.json +++ b/src/locale/lang/en.json @@ -98,6 +98,10 @@ "ACTIVE_VIEW": { "TABLE_MODE": "Table view", "ICON_MODE": "Icons view", + "SORT_BY_NAME": "Sort by Name", + "SORT_BY_SIZE": "Sort by Size", + "SORT_ORDER_ASCENDING": "Ascending Order", + "SORT_ORDER_DESCENDING": "Descending Order", "COPY": "Copy selected items to clipboard", "PASTE": "Paste selected items into current folder", "VIEW_HISTORY": "Show nav history (debug)", @@ -136,7 +140,7 @@ "ICON_VIEW": "Icons", "DETAILS_VIEW": "Details", "CHANGE_VIEW": "Change display mode", - "CHANGE_SORT_METHOD": "Change files sort order" + "CHANGE_SORT_METHOD": "Change files sort method" }, "COMMON": { "SIZE": { @@ -270,7 +274,12 @@ "GO_FORWARD": "Forward", "TOGGLE_HIDDEN_FILES": "Show/Hide Hidden Files", "TOGGLE_ICONVIEW_MODE": "as Icons", - "TOGGLE_TABLEVIEW_MODE": "as List" + "TOGGLE_TABLEVIEW_MODE": "as List", + "SORT_BY": "Sort By", + "SORT_BY_NAME": "Name", + "SORT_BY_SIZE": "Size", + "SORT_ASCENDING": "Ascending", + "SORT_DESCENDING": "Descending" } } } \ No newline at end of file diff --git a/src/locale/lang/fr.json b/src/locale/lang/fr.json index 03cf7d6..f629109 100644 --- a/src/locale/lang/fr.json +++ b/src/locale/lang/fr.json @@ -98,6 +98,10 @@ "ACTIVE_VIEW": { "TABLE_MODE": "Vue liste", "ICON_MODE": "Vue icônes", + "SORT_BY_NAME": "Trier par Nom", + "SORT_BY_SIZE": "Trier par Taille", + "SORT_ORDER_ASCENDING": "Croissant", + "SORT_ORDER_DESCENDING": "Décroissant", "COPY": "Copier les éléments sélectionnés dans le presse-papier", "PASTE": "Coller les éléments sélectionnés dans le presse-papier", "VIEW_HISTORY": "Afficher l'historique de navigation (debug)", @@ -270,7 +274,12 @@ "GO_FORWARD": "Suivant", "TOGGLE_HIDDEN_FILES": "Voir/Cacher Fichiers Cachés", "TOGGLE_ICONVIEW_MODE": "Par icônes", - "TOGGLE_TABLEVIEW_MODE": "Par liste" + "TOGGLE_TABLEVIEW_MODE": "Par liste", + "SORT_BY": "Trier par", + "SORT_BY_NAME": "Nom", + "SORT_BY_SIZE": "Taille", + "SORT_ASCENDING": "Croissant", + "SORT_DESCENDING": "Décroissant" } } } \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index ee1656e..e97179d 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,5 +1,6 @@ import { ViewModeName } from '$src/hooks/useViewMode' import { FileDescriptor } from '$src/services/Fs' +import { TSORT_METHOD_NAME, TSORT_ORDER } from '$src/services/FsSort' import { FileState, TStatus } from '$src/state/fileState' import { IconName } from '@blueprintjs/icons' import { IpcRendererEvent } from 'electron/renderer' @@ -51,6 +52,8 @@ export interface ReactiveProperties { status: TStatus language: string viewMode: ViewModeName + sortMethod: TSORT_METHOD_NAME + sortOrder: TSORT_ORDER } export type KeyboardLayoutMap = Record