TagSpaces is an offline, open source, document manager with tagging support
chore: added functionality for copying relative path of files and folders
Ilian Sapundshiev861e5afd8277
diff --git a/src/renderer/components/menus/DirectoryMenu.tsx b/src/renderer/components/menus/DirectoryMenu.tsxindex abf826ad2..082ce0dc4 100644--- a/src/renderer/components/menus/DirectoryMenu.tsx+++ b/src/renderer/components/menus/DirectoryMenu.tsx@@ -164,6 +164,22 @@ function DirectoryMenu(props: Props) {});}+ function copyRelativePath() {+ onClose();+ const entryPath =+ selectedEntries?.length > 0+ ? selectedEntries[0].path+ : currentDirectoryPath;+ const locationID = selectedEntries?.[0]?.locationID;+ const tmpLoc = findLocation(locationID);+ getLocationPath(tmpLoc).then((locationPath) => {+ const relativePath = getRelativeEntryPath(locationPath, entryPath);+ navigator.clipboard.writeText(relativePath).then(() => {+ showNotification(t('core:pathCopied'));+ });+ });+ }+function copySharingLink() {generateFolderLink().then((sharingLink) => {const clibboardItem = generateClipboardLink(@@ -425,6 +441,7 @@ function DirectoryMenu(props: Props) {addExistingFile,setFolderThumbnail,copySharingLink,+ copyRelativePath,importMacTags,switchPerspectives ? perspectiveSwitch : undefined,showProperties,diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsxindex f2df9b664..a0b3dd85b 100644--- a/src/renderer/components/menus/FileMenu.tsx+++ b/src/renderer/components/menus/FileMenu.tsx@@ -147,6 +147,25 @@ function FileMenu(props: Props) {}}+ function copyRelativePath() {+ onClose();+ if (selectedEntries?.length === 1) {+ const relativePath = getRelativeEntryPath(+ currentLocationPath,+ selectedEntries[0].path,+ );+ navigator.clipboard+ .writeText(relativePath)+ .then(() => {+ showNotification(t('core:pathCopied'));+ return true;+ })+ .catch((e) => {+ console.log('Error copying to clipboard ' + e);+ });+ }+ }+function copySharingLink() {onClose();if (selectedEntries && selectedEntries.length === 1) {@@ -564,6 +583,18 @@ function FileMenu(props: Props) {}if (selectedEntries.length === 1) {+ menuItems.push(+ <MenuItem+ key="copyRelativePath"+ data-tid="copyRelativePathTID"+ onClick={copyRelativePath}+ >+ <ListItemIcon>+ <LinkIcon />+ </ListItemIcon>+ <ListItemText primary={t('core:copyRelativePath')} />+ </MenuItem>,+ );menuItems.push(<MenuItemkey="copySharingLink"diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.jsonindex 2db2db069..81ace03a1 100644--- a/src/renderer/locales/en/core.json+++ b/src/renderer/locales/en/core.json@@ -685,6 +685,8 @@"warningOpeningFilesExternally": "Show warning on opening files externally","geoTaggingFormat": "Geo Tagging Format","searchDisabledWhileIndexing": "Search disabled while indexing",+ "copyRelativePath": "Copy Relative Path",+ "pathCopied": "Path copied to clipboard","copySharingLink": "Copy Sharing Link","sharingLinkCopied": "Link for sharing copied to the clipboard","sharingLinkFailed": "Copying the link to clipboard failed",diff --git a/src/renderer/perspectives/common/DirectoryMenuItems.tsx b/src/renderer/perspectives/common/DirectoryMenuItems.tsxindex f5b99165b..612c48264 100644--- a/src/renderer/perspectives/common/DirectoryMenuItems.tsx+++ b/src/renderer/perspectives/common/DirectoryMenuItems.tsx@@ -56,6 +56,7 @@ export function getDirectoryMenuItems(addExistingFile?: () => void,setFolderThumbnail?: () => void,copySharingLink?: () => void,+ copyRelativePath?: () => void,importMacTags?: () => void,switchPerspective?: (perspectiveId: string) => void,showProperties?: () => void,@@ -446,6 +447,23 @@ export function getDirectoryMenuItems();}}+ if (selectedEntries.length === 1 && copyRelativePath) {+ menuItems.push(+ <MenuItem+ key="copyRelativePath"+ data-tid="copyRelativePathTID"+ onClick={() => {+ onClose();+ copyRelativePath();+ }}+ >+ <ListItemIcon>+ <LinkIcon />+ </ListItemIcon>+ <ListItemText primary={t('core:copyRelativePath')} />+ </MenuItem>,+ );+ }if (selectedEntries.length === 1 && copySharingLink) {menuItems.push(<MenuItem