TagSpaces is an offline, open source, document manager with tagging support
TSN695 Duplicate File (#1467)
Stanimir07de1c14ca7e
diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsxindex 49c86ffc1..5567d3f0e 100644--- a/app/components/menus/FileMenu.tsx+++ b/app/components/menus/FileMenu.tsx@@ -39,9 +39,13 @@ import {setFolderThumbnailPromise} from '-/services/utils-io';import { Pro } from '-/pro';-import { extractParentDirectoryPath } from '-/utils/paths';+import {+ extractContainingDirectoryPath,+ extractFileName,+ extractParentDirectoryPath+} from '-/utils/paths';import { TS } from '-/tagspaces.namespace';-import AddIcon from '@material-ui/icons/Add';+// import AddIcon from '@material-ui/icons/Add';interface Props {anchorEl: Element;@@ -126,6 +130,42 @@ const FileMenu = (props: Props) => {}}+ function duplicateFile() {+ props.onClose();+ if (props.selectedFilePath) {+ const dirPath = extractContainingDirectoryPath(+ props.selectedFilePath,+ PlatformIO.getDirSeparator()+ );+ const fileName = extractFileName(+ props.selectedFilePath,+ PlatformIO.getDirSeparator()+ );+ const lastIndexDot = fileName.lastIndexOf('.');+ if (lastIndexDot !== -1) {+ const newFileName =+ dirPath ++ PlatformIO.getDirSeparator() ++ fileName.substring(0, lastIndexDot) ++ '-copy' ++ fileName.substr(lastIndexDot);+ PlatformIO.copyFilePromise(props.selectedFilePath, newFileName)+ .then(() => {+ props.loadDirectoryContent(dirPath);+ /* props.showNotification(+ 'Creating duplicate successfully: ' + newFileName+ ); */+ return true;+ })+ .catch(error => {+ props.showNotification(+ 'Error creating duplicate: ' + error.message+ );+ });+ }+ }+ }+function openFileNatively() {props.onClose();if (props.selectedFilePath) {@@ -221,6 +261,19 @@ const FileMenu = (props: Props) => {menuItems.push(<Divider key="fmDivider" />);}+ menuItems.push(+ <MenuItem+ key="fileMenuDuplicateFile"+ data-tid="fileMenuDuplicateFileTID"+ onClick={duplicateFile}+ >+ <ListItemIcon>+ <OpenFolderInternally />+ </ListItemIcon>+ <ListItemText primary={i18n.t('core:duplicateFile')} />+ </MenuItem>+ );+if (!props.isReadOnlyMode) {menuItems.push(<MenuItem