TagSpaces is an offline, open source, document manager with tagging support
chore: added some new key bindings, refactoring
Ilian Sapundshiev313908e70c16
diff --git a/src/renderer/components/dialogs/KeyboardDialog.tsx b/src/renderer/components/dialogs/KeyboardDialog.tsxindex 2319f86a2..952a154d9 100644--- a/src/renderer/components/dialogs/KeyboardDialog.tsx+++ b/src/renderer/components/dialogs/KeyboardDialog.tsx@@ -40,6 +40,7 @@ export function adjustKeyBinding(keyBinding: string) {adjKB = adjKB.replaceAll('+', ' ').replaceAll('command', '⌘')+ .replaceAll('option', '⌥').replaceAll('shift', '⇧').replaceAll('backspace', '⌫').toUpperCase();diff --git a/src/renderer/components/dialogs/settings/SettingsKeyBindings.tsx b/src/renderer/components/dialogs/settings/SettingsKeyBindings.tsxindex 5cd9107d3..9bdc33cf9 100644--- a/src/renderer/components/dialogs/settings/SettingsKeyBindings.tsx+++ b/src/renderer/components/dialogs/settings/SettingsKeyBindings.tsx@@ -33,6 +33,7 @@ import {import DefaultSettings from '-/reducers/settings-default';import { AppDispatch } from '-/reducers/app';import { useTranslation } from 'react-i18next';+import Typography from '@mui/material/Typography';const PREFIX = 'SettingsKeyBindings';@@ -64,6 +65,13 @@ function SettingsKeyBindings() {return (<Root className={classes.keyBinding} noValidate autoComplete="off">+ <Typography variant="body2">+ The following key names can be used for defining key bindings:{' '}+ <Typography variant="overline">+ ctrl, command, alt, option, shift, space+ </Typography>{' '}+ plus letters and digits from your keyboard.+ </Typography><ListItem style={{ paddingLeft: 0, paddingRight: 0 }}><ListItemText primary={t('core:enableGlobalKeyboardShortcuts')} /><Switchdiff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsxindex 3f6a59bd5..a2563c5db 100644--- a/src/renderer/components/menus/FileMenu.tsx+++ b/src/renderer/components/menus/FileMenu.tsx@@ -71,6 +71,7 @@ import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';import { usePlatformFacadeContext } from '-/hooks/usePlatformFacadeContext';+import { useFsActionsContext } from '-/hooks/useFsActionsContext';import MenuKeyBinding from '-/components/menus/MenuKeyBinding';interface Props {@@ -119,6 +120,7 @@ function FileMenu(props: Props) {usePlatformFacadeContext();const { currentLocation, readOnlyMode } = useCurrentLocationContext();//const locations: Array<TS.Location> = useSelector(getLocations);+ const { openFileNatively, duplicateFile } = useFsActionsContext();const prefixTagContainer = useSelector(getPrefixTagContainer);const warningOpeningFilesExternally = useSelector(getWarningOpeningFilesExternally,@@ -231,49 +233,9 @@ function FileMenu(props: Props) {openAddRemoveTagsDialog();}- function duplicateFile() {+ function duplicateFileHandler() {onClose();- if (selectedFilePath) {- const dirPath = extractContainingDirectoryPath(- selectedFilePath,- PlatformIO.getDirSeparator(),- );-- const fileName = extractFileName(- selectedFilePath,- PlatformIO.getDirSeparator(),- );-- const extractedTags = extractTags(- selectedFilePath,- AppConfig.tagDelimiter,- PlatformIO.getDirSeparator(),- );- extractedTags.push('copy');- extractedTags.push(formatDateTime4Tag(new Date(), true));-- const newFilePath =- (dirPath ? dirPath + PlatformIO.getDirSeparator() : '') +- generateFileName(- fileName,- extractedTags,- AppConfig.tagDelimiter,- prefixTagContainer,- );-- copyFilePromise(selectedFilePath, newFilePath)- .then(() => {- if (onDuplicateFile) {- onDuplicateFile(dirPath);- } else {- return openDirectory(dirPath);- }- return true;- })- .catch((error) => {- showNotification('Error creating duplicate: ', error);- });- }+ duplicateFile(selectedFilePath);}function openParentFolderInternally() {@@ -304,6 +266,13 @@ function FileMenu(props: Props) {}}+ function openFileNativelyHandler() {+ onClose();+ if (selectedFilePath) {+ openFileNatively(selectedFilePath);+ }+ }+const menuItems = [];const pathLowerCase = selectedFilePath.toLowerCase();@@ -322,6 +291,7 @@ function FileMenu(props: Props) {<OpenFile /></ListItemIcon><ListItemText primary={t('core:openFile')} />+ <MenuKeyBinding keyBinding={keyBindings['openEntry']} /></MenuItem>,);menuItems.push(@@ -361,21 +331,13 @@ function FileMenu(props: Props) {<MenuItemkey="fileMenuOpenFileNatively"data-tid="fileMenuOpenFileNatively"- onClick={() => {- onClose();- if (selectedFilePath) {- PlatformIO.openFile(- selectedFilePath,- warningOpeningFilesExternally,- );- // openFileNatively(selectedFilePath);- }- }}+ onClick={openFileNativelyHandler}><ListItemIcon><OpenFileNatively /></ListItemIcon><ListItemText primary={t('core:openFileNatively')} />+ <MenuKeyBinding keyBinding={keyBindings['openFileExternally']} /></MenuItem>,);menuItems.push(@@ -464,12 +426,13 @@ function FileMenu(props: Props) {<MenuItemkey="fileMenuDuplicateFile"data-tid="fileMenuDuplicateFileTID"- onClick={duplicateFile}+ onClick={duplicateFileHandler}><ListItemIcon><DuplicateFile /></ListItemIcon><ListItemText primary={t('core:duplicateFile')} />+ <MenuKeyBinding keyBinding={keyBindings['duplicateFile']} /></MenuItem>,);}@@ -498,6 +461,7 @@ function FileMenu(props: Props) {<MoveCopy /></ListItemIcon><ListItemText primary={t('core:moveCopyFile')} />+ <MenuKeyBinding keyBinding={keyBindings['copyMoveSelectedEntries']} /></MenuItem>,);menuItems.push(@@ -571,6 +535,7 @@ function FileMenu(props: Props) {<PropertiesIcon /></ListItemIcon><ListItemText primary={t('core:filePropertiesTitle')} />+ <MenuKeyBinding keyBinding={keyBindings['openEntryDetails']} /></MenuItem>,);}diff --git a/src/renderer/hooks/FsActionsContextProvider.tsx b/src/renderer/hooks/FsActionsContextProvider.tsxindex 22e749226..a8f94cdcd 100644--- a/src/renderer/hooks/FsActionsContextProvider.tsx+++ b/src/renderer/hooks/FsActionsContextProvider.tsx@@ -23,10 +23,19 @@ import { useTranslation } from 'react-i18next';import PlatformIO from '-/services/platform-facade';import {extractDirectoryName,+ extractContainingDirectoryPath,getMetaFileLocationForFile,getThumbFileLocationForFile,+ extractFileName,+ extractTags,} from '@tagspaces/tagspaces-common/paths';-import { getWarningOpeningFilesExternally } from '-/reducers/settings';+import { formatDateTime4Tag } from '@tagspaces/tagspaces-common/misc';+import { generateFileName } from '-/services/utils-io';+import AppConfig from '-/AppConfig';+import {+ getPrefixTagContainer,+ getWarningOpeningFilesExternally,+} from '-/reducers/settings';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { useNotificationContext } from '-/hooks/useNotificationContext';import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';@@ -45,12 +54,14 @@ type FsActionsContextData = {reflect?: boolean,) => Promise<boolean>;openFileNatively: (selectedFile?: string) => void;+ duplicateFile: (selectedFilePath: string) => void;};export const FsActionsContext = createContext<FsActionsContextData>({renameDirectory: () => Promise.resolve(''),renameFile: () => Promise.resolve(false),openFileNatively: undefined,+ duplicateFile: undefined,});export type FsActionsContextProviderProps = {@@ -67,12 +78,17 @@ export const FsActionsContextProvider = ({const { reflectRenameEntry } = useLocationIndexContext();const { showNotification } = useNotificationContext();//const { watcher } = useFSWatcherContext();- const { renameFilePromise, renameFilesPromise, renameDirectoryPromise } =- usePlatformFacadeContext();+ const {+ copyFilePromise,+ renameFilePromise,+ renameFilesPromise,+ renameDirectoryPromise,+ } = usePlatformFacadeContext();const dispatch: AppDispatch = useDispatch();const warningOpeningFilesExternally = useSelector(getWarningOpeningFilesExternally,);+ const prefixTagContainer = useSelector(getPrefixTagContainer);const renameDirectory = useMemo(() => {return (directoryPath: string, newDirectoryName: string): Promise<string> =>@@ -228,11 +244,57 @@ export const FsActionsContextProvider = ({}}+ function duplicateFile(selectedFilePath: string) {+ if (selectedFilePath) {+ const dirPath = extractContainingDirectoryPath(+ selectedFilePath,+ PlatformIO.getDirSeparator(),+ );++ const fileName = extractFileName(+ selectedFilePath,+ PlatformIO.getDirSeparator(),+ );++ const extractedTags = extractTags(+ selectedFilePath,+ AppConfig.tagDelimiter,+ PlatformIO.getDirSeparator(),+ );+ extractedTags.push('copy');+ extractedTags.push(formatDateTime4Tag(new Date(), true));++ const newFilePath =+ (dirPath ? dirPath + PlatformIO.getDirSeparator() : '') ++ generateFileName(+ fileName,+ extractedTags,+ AppConfig.tagDelimiter,+ prefixTagContainer,+ );++ copyFilePromise(selectedFilePath, newFilePath)+ .then(() => {+ // if (onDuplicateFile) {+ // onDuplicateFile(dirPath);+ // } else {+ return openDirectory(dirPath);+ // }+ // return true;+ })+ .catch((error) => {+ showNotification('Error creating duplicate: ', error);+ });+ }+ showNotification('Unanble to duplicate, no file selected');+ }+const context = useMemo(() => {return {renameDirectory,renameFile,openFileNatively,+ duplicateFile,};}, [renameDirectory, renameFile]); //, watcherdiff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.jsonindex 50aa1ec25..10baa0ddb 100644--- a/src/renderer/locales/en/core.json+++ b/src/renderer/locales/en/core.json@@ -44,6 +44,7 @@"filePropertiesDescription": "Description","directoryPropertiesTitle": "Folder Details","filePropertiesTitle": "File Details",+ "openEntryDetails": "Open Entry Details","createLocationTitle": "Connect a Location","createLocation": "New location","exportLocationTitle": "Export Location Configuration",diff --git a/src/renderer/perspectives/common/DirectoryMenuItems.tsx b/src/renderer/perspectives/common/DirectoryMenuItems.tsxindex 10e203b34..b9cbc6646 100644--- a/src/renderer/perspectives/common/DirectoryMenuItems.tsx+++ b/src/renderer/perspectives/common/DirectoryMenuItems.tsx@@ -75,6 +75,7 @@ export function getDirectoryMenuItems(<OpenFolderIcon /></ListItemIcon><ListItemText primary={t('core:openDirectory')} />+ <MenuKeyBinding keyBinding={keyBindings['openEntry']} /></MenuItem>,);}@@ -151,6 +152,7 @@ export function getDirectoryMenuItems(<MoveCopy /></ListItemIcon><ListItemText primary={t('core:moveCopyDirectory')} />+ <MenuKeyBinding keyBinding={keyBindings['copyMoveSelectedEntries']} /></MenuItem>,);}@@ -196,6 +198,7 @@ export function getDirectoryMenuItems(<OpenFolderNativelyIcon /></ListItemIcon><ListItemText primary={t('core:showInFileManager')} />+ <MenuKeyBinding keyBinding={keyBindings['openFileExternally']} /></MenuItem>,);}@@ -437,6 +440,7 @@ export function getDirectoryMenuItems(<PropertiesIcon /></ListItemIcon><ListItemText primary={t('core:directoryPropertiesTitle')} />+ <MenuKeyBinding keyBinding={keyBindings['openEntryDetails']} /></MenuItem>,);}diff --git a/src/renderer/perspectives/grid-perspective/components/MainContainer.tsx b/src/renderer/perspectives/grid-perspective/components/MainContainer.tsxindex 1c2121026..53793151b 100644--- a/src/renderer/perspectives/grid-perspective/components/MainContainer.tsx+++ b/src/renderer/perspectives/grid-perspective/components/MainContainer.tsx@@ -73,9 +73,13 @@ function GridPerspective(props: Props) {const { openRenameEntryDialog } = props;const { openEntry, openPrevFile, openNextFile } = useOpenedEntryContext();- const { directoryMeta, currentDirectoryPath, setDirectoryMeta } =- useDirectoryContentContext();- const { openFileNatively } = useFsActionsContext();+ const {+ directoryMeta,+ openDirectory,+ currentDirectoryPath,+ setDirectoryMeta,+ } = useDirectoryContentContext();+ const { openFileNatively, duplicateFile } = useFsActionsContext();const dispatch: AppDispatch = useDispatch();const { sortedDirContent, sortBy, orderBy, setSortBy, setOrderBy } =@@ -476,7 +480,10 @@ function GridPerspective(props: Props) {deleteDocument: keyBindings.deleteDocument,addRemoveTags: keyBindings.addRemoveTags,renameFile: keyBindings.renameFile,+ duplicateFile: keyBindings.duplicateFile,+ copyMoveSelectedEntries: keyBindings.copyMoveSelectedEntries,openEntry: keyBindings.openEntry,+ openEntryProperties: keyBindings.openEntryProperties,openFileExternally: keyBindings.openFileExternally,};@@ -513,14 +520,48 @@ function GridPerspective(props: Props) {}},renameFile: () => {- openRenameEntryDialog();+ if (selectedEntries && selectedEntries.length === 1) {+ openRenameEntryDialog();+ }+ },+ copyMoveSelectedEntries: () => {+ if (selectedEntries && selectedEntries.length > 0) {+ openMoveCopyFilesDialog();+ }},openEntry: (e) => {- e.preventDefault();- openEntry();+ // e.preventDefault();+ if (selectedEntries && selectedEntries.length === 1) {+ const entry = selectedEntries[0];+ if (entry.isFile) {+ openEntry(entry.path, false);+ } else {+ openDirectory(entry.path);+ }+ }},openFileExternally: () => {- openFileNatively();+ if (selectedEntries && selectedEntries.length === 1) {+ const entry = selectedEntries[0];+ openFileNatively(entry.path);+ }+ // if (lastSelectedEntryPath) {+ // openFileNatively(lastSelectedEntryPath);+ // } else if (currentDirectoryPath) {+ // openFileNatively(currentDirectoryPath);+ // }+ },+ openEntryDetails: () => {+ if (selectedEntries && selectedEntries.length === 1) {+ const entry = selectedEntries[0];+ openEntry(entry.path, true);+ }+ },+ duplicateFile: () => {+ if (selectedEntries && selectedEntries.length === 1) {+ const entry = selectedEntries[0];+ duplicateFile(entry.path);+ }},};diff --git a/src/renderer/perspectives/grid-perspective/components/MainToolbar.tsx b/src/renderer/perspectives/grid-perspective/components/MainToolbar.tsxindex f871edd67..3ea7cdc35 100644--- a/src/renderer/perspectives/grid-perspective/components/MainToolbar.tsx+++ b/src/renderer/perspectives/grid-perspective/components/MainToolbar.tsx@@ -165,7 +165,14 @@ function MainToolbar(props: Props) {</Tooltip>)}{!readOnlyMode && (- <Tooltip title={t('core:copyMoveSelectedEntries')}>+ <Tooltip+ title={+ t('core:copyMoveSelectedEntries') ++ ' (' ++ adjustKeyBinding(keyBindings['copyMoveSelectedEntries']) ++ ')'+ }+ ><span><IconButtonaria-label={t('core:copyMoveSelectedEntries')}diff --git a/src/renderer/perspectives/list/components/MainContainer.tsx b/src/renderer/perspectives/list/components/MainContainer.tsxindex aaa296e95..4541b3d68 100644--- a/src/renderer/perspectives/list/components/MainContainer.tsx+++ b/src/renderer/perspectives/list/components/MainContainer.tsx@@ -73,9 +73,13 @@ function ListPerspective(props: Props) {const { openRenameEntryDialog } = props;const { openEntry, openPrevFile, openNextFile } = useOpenedEntryContext();- const { directoryMeta, currentDirectoryPath, setDirectoryMeta } =- useDirectoryContentContext();- const { openFileNatively } = useFsActionsContext();+ const {+ directoryMeta,+ openDirectory,+ currentDirectoryPath,+ setDirectoryMeta,+ } = useDirectoryContentContext();+ const { openFileNatively, duplicateFile } = useFsActionsContext();const dispatch: AppDispatch = useDispatch();const { sortedDirContent, sortBy, orderBy, setSortBy, setOrderBy } =@@ -469,6 +473,7 @@ function ListPerspective(props: Props) {deleteDocument: keyBindings.deleteDocument,addRemoveTags: keyBindings.addRemoveTags,renameFile: keyBindings.renameFile,+ copyMoveSelectedEntries: keyBindings.copyMoveSelectedEntries,openEntry: keyBindings.openEntry,openFileExternally: keyBindings.openFileExternally,};@@ -506,14 +511,48 @@ function ListPerspective(props: Props) {}},renameFile: () => {- openRenameEntryDialog();+ if (selectedEntries && selectedEntries.length === 1) {+ openRenameEntryDialog();+ }+ },+ copyMoveSelectedEntries: () => {+ if (selectedEntries && selectedEntries.length > 0) {+ openMoveCopyFilesDialog();+ }},openEntry: (e) => {- e.preventDefault();- openEntry();+ // e.preventDefault();+ if (selectedEntries && selectedEntries.length === 1) {+ const entry = selectedEntries[0];+ if (entry.isFile) {+ openEntry(entry.path, false);+ } else {+ openDirectory(entry.path);+ }+ }},openFileExternally: () => {- openFileNatively();+ if (selectedEntries && selectedEntries.length === 1) {+ const entry = selectedEntries[0];+ openFileNatively(entry.path);+ }+ // if (lastSelectedEntryPath) {+ // openFileNatively(lastSelectedEntryPath);+ // } else if (currentDirectoryPath) {+ // openFileNatively(currentDirectoryPath);+ // }+ },+ openEntryDetails: () => {+ if (selectedEntries && selectedEntries.length === 1) {+ const entry = selectedEntries[0];+ openEntry(entry.path, true);+ }+ },+ duplicateFile: () => {+ if (selectedEntries && selectedEntries.length === 1) {+ const entry = selectedEntries[0];+ duplicateFile(entry.path);+ }},};diff --git a/src/renderer/reducers/keybindings-default.ts b/src/renderer/reducers/keybindings-default.tsindex d157684f3..327409f74 100644--- a/src/renderer/reducers/keybindings-default.ts+++ b/src/renderer/reducers/keybindings-default.ts@@ -22,7 +22,11 @@ export default function keyBindings(isMacLike) {},{name: 'deleteDocument',- command: 'del',+ command: isMacLike ? 'f8' : 'del',+ },+ {+ name: 'copyMoveSelectedEntries',+ command: 'f6',},{name: 'showLocationManager',@@ -58,7 +62,7 @@ export default function keyBindings(isMacLike) {},{name: 'Escape',- command: 'Escape',+ command: 'escape',},{name: 'showHelp',@@ -84,18 +88,26 @@ export default function keyBindings(isMacLike) {name: 'renameFile',command: 'f2',},+ {+ name: 'duplicateFile',+ command: (isMacLike ? 'option' : 'alt') + '+d',+ },{name: 'openEntry',- command: 'alt+enter',+ command: 'enter',},{- name: 'openParentDirectory',- command: 'backspace',+ name: 'openEntryDetails',+ command: (isMacLike ? 'command' : 'ctrl') + '+o',},{name: 'openFileExternally',command: (isMacLike ? 'command' : 'ctrl') + '+enter',},+ {+ name: 'openParentDirectory',+ command: 'backspace',+ },{name: 'zoomIn',command: (isMacLike ? 'command' : 'ctrl') + '+shift+',