TagSpaces is an offline, open source, document manager with tagging support
Tsn550 offer move or copy dialog on files drag and drop (#1651)
Stanimird057fb9d1c8d
diff --git a/app/components/TargetFileBox.tsx b/app/components/TargetFileBox.tsxindex b39ed92d9..25db4c377 100644--- a/app/components/TargetFileBox.tsx+++ b/app/components/TargetFileBox.tsx@@ -46,10 +46,10 @@ interface Props {classes?: any;children: ReactNode;accepts: Array<string>;- onDrop: (item, monitor) => void;+ onDrop: (item) => void;}-const TargetFileBox = (props: Props) => {+function TargetFileBox(props: Props) {const ref = useRef<HTMLDivElement>(null);const [collectedProps, drop] = useDrop({@@ -62,7 +62,7 @@ const TargetFileBox = (props: Props) => {};},drop(item, monitor) {- return props.onDrop(collectedProps, monitor);+ return props.onDrop(item); // collectedProps, monitor);}});@@ -81,6 +81,6 @@ const TargetFileBox = (props: Props) => {{children}</div>);-};+}export default withStyles(styles, { withTheme: true })(TargetFileBox);diff --git a/app/components/dialogs/MoveOrCopyFilesDialog.tsx b/app/components/dialogs/MoveOrCopyFilesDialog.tsxnew file mode 100644index 000000000..e9f6b5545--- /dev/null+++ b/app/components/dialogs/MoveOrCopyFilesDialog.tsx@@ -0,0 +1,96 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import React from 'react';+import Button from '@material-ui/core/Button';+import List from '@material-ui/core/List';+import ListItem from '@material-ui/core/ListItem';+import ListItemIcon from '@material-ui/core/ListItemIcon';+import FileIcon from '@material-ui/icons/InsertDriveFileOutlined';+import DialogActions from '@material-ui/core/DialogActions';+import DialogContent from '@material-ui/core/DialogContent';+import DialogTitle from '@material-ui/core/DialogTitle';+import Typography from '@material-ui/core/Typography';+import Dialog from '@material-ui/core/Dialog';+import i18n from '-/services/i18n';+import DialogCloseButton from '-/components/dialogs/DialogCloseButton';++interface Props {+ open: boolean;+ fullScreen: boolean;+ onClose: (clearSelection?: boolean) => void;+ selectedFiles: Array<File>;+ handleMoveFiles: (files: Array<File>) => void;+ handleCopyFiles: (files: Array<File>) => void;+}++function MoveCopyFilesDialog(props: Props) {+ const { open, onClose, fullScreen } = props;++ return (+ <Dialog+ open={open}+ onClose={onClose}+ keepMounted+ scroll="paper"+ fullScreen={fullScreen}+ >+ <DialogTitle>+ {i18n.t('core:copyMoveFilesTitle')}+ <DialogCloseButton onClose={() => onClose()} />+ </DialogTitle>+ <DialogContent>+ <List dense style={{ width: 550 }}>+ {props.selectedFiles &&+ props.selectedFiles.length > 0 &&+ props.selectedFiles.map((file: File) => (+ <ListItem title={file.path} key={file.path}>+ <ListItemIcon>+ <FileIcon />+ </ListItemIcon>+ <Typography variant="inherit" noWrap>+ {file.name}+ </Typography>+ </ListItem>+ ))}+ </List>+ </DialogContent>+ <DialogActions>+ <Button data-tid="closeMoveCopyDialog" onClick={() => props.onClose()}>+ {i18n.t('core:cancel')}+ </Button>+ <Button+ onClick={() => props.handleMoveFiles(props.selectedFiles)}+ data-tid="confirmMoveFiles"+ color="primary"+ >+ {i18n.t('core:moveFilesButton')}+ </Button>+ <Button+ onClick={() => props.handleCopyFiles(props.selectedFiles)}+ data-tid="confirmCopyFiles"+ color="primary"+ >+ {i18n.t('core:copyFilesButton')}+ </Button>+ </DialogActions>+ </Dialog>+ );+}++export default MoveCopyFilesDialog;diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsxindex 0939a2450..c0b8d8e02 100644--- a/app/containers/MainPage.tsx+++ b/app/containers/MainPage.tsx@@ -86,6 +86,8 @@ import { TS } from '-/tagspaces.namespace';import PageNotification from '-/containers/PageNotification';import listen from '-/containers/RendererListener';import { actions as LocationIndexActions } from '-/reducers/location-index';+import MoveCopyFilesDialog from '-/components/dialogs/MoveOrCopyFilesDialog';+import PlatformIO from '-/services/platform-facade';const drawerWidth = 320;const body = document.getElementsByTagName('body')[0];@@ -188,6 +190,7 @@ interface Props {autohide?: boolean) => void;reflectCreateEntries: (fsEntries: Array<TS.FileSystemEntry>) => void;+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;uploadFilesAPI: (files: Array<File>,destination: string,@@ -208,90 +211,106 @@ const CreateEditLocationDialog = React.lazy(() =>/* webpackChunkName: "CreateEditLocationDialog" */ '../components/dialogs/CreateEditLocationDialog'));-const CreateEditLocationDialogAsync = props => (- <React.Suspense fallback={<LoadingLazy />}>- <CreateEditLocationDialog {...props} />- </React.Suspense>-);+function CreateEditLocationDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <CreateEditLocationDialog {...props} />+ </React.Suspense>+ );+}const AboutDialog = React.lazy(() =>import(/* webpackChunkName: "AboutDialog" */ '../components/dialogs/AboutDialog'));-const AboutDialogAsync = props => (- <React.Suspense fallback={<LoadingLazy />}>- <AboutDialog {...props} />- </React.Suspense>-);+function AboutDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <AboutDialog {...props} />+ </React.Suspense>+ );+}const LicenseDialog = React.lazy(() =>import(/* webpackChunkName: "LicenseDialog" */ '../components/dialogs/LicenseDialog'));-const LicenseDialogAsync = props => (- <React.Suspense fallback={<LoadingLazy />}>- <LicenseDialog {...props} />- </React.Suspense>-);+function LicenseDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <LicenseDialog {...props} />+ </React.Suspense>+ );+}const KeyboardDialog = React.lazy(() =>import(/* webpackChunkName: "KeyboardDialog" */ '../components/dialogs/KeyboardDialog'));-const KeyboardDialogAsync = props => (- <React.Suspense fallback={<LoadingLazy />}>- <KeyboardDialog {...props} />- </React.Suspense>-);+function KeyboardDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <KeyboardDialog {...props} />+ </React.Suspense>+ );+}const ThirdPartyLibsDialog = React.lazy(() =>import(/* webpackChunkName: "ThirdPartyLibsDialog" */ '../components/dialogs/ThirdPartyLibsDialog'));-const ThirdPartyLibsDialogAsync = props => (- <React.Suspense fallback={<LoadingLazy />}>- <ThirdPartyLibsDialog {...props} />- </React.Suspense>-);+function ThirdPartyLibsDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <ThirdPartyLibsDialog {...props} />+ </React.Suspense>+ );+}const OnboardingDialog = React.lazy(() =>import(/* webpackChunkName: "OnboardingDialog" */ '../components/dialogs/OnboardingDialog'));-const OnboardingDialogAsync = props => (- <React.Suspense fallback={<LoadingLazy />}>- <OnboardingDialog {...props} />- </React.Suspense>-);+function OnboardingDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <OnboardingDialog {...props} />+ </React.Suspense>+ );+}const EditEntryTagDialog = React.lazy(() =>import(/* webpackChunkName: "EditEntryTagDialog" */ '../components/dialogs/EditEntryTagDialog'));-const EditEntryTagDialogAsync = props => (- <React.Suspense fallback={<LoadingLazy />}>- <EditEntryTagDialog {...props} />- </React.Suspense>-);+function EditEntryTagDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <EditEntryTagDialog {...props} />+ </React.Suspense>+ );+}const OpenLinkDialog = React.lazy(() =>import(/* webpackChunkName: "OpenLinkDialog" */ '../components/dialogs/OpenLinkDialog'));-const OpenLinkDialogAsync = props => (- <React.Suspense fallback={<LoadingLazy />}>- <OpenLinkDialog {...props} />- </React.Suspense>-);+function OpenLinkDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <OpenLinkDialog {...props} />+ </React.Suspense>+ );+}-const MainPage = (props: Props) => {+function MainPage(props: Props) {// const [percent, setPercent] = React.useState<number | undefined>(undefined);const percent = useRef<number | undefined>(undefined);const selectedDirectoryPath = useRef<string>('');@@ -314,6 +333,9 @@ const MainPage = (props: Props) => {});const [drawerOpened, setDrawerOpened] = useState<boolean>(true);+ const [moveCopyDialogOpened, setMoveCopyDialogOpened] = useState<any>(+ undefined+ );// const [rightPanelWidth, setRightPanelWidth] = useState<number>(0);useEffect(() => {@@ -365,17 +387,68 @@ const MainPage = (props: Props) => {setDrawerOpened(prevOpen => !prevOpen);};- const handleFileDrop = (item, monitor) => {+ const handleMoveCopyFiles = (files: Array<File>, move = false) => {+ const promises = [];+ for (const file of files) {+ if (move) {+ promises.push(+ PlatformIO.renameFilePromise(+ file.path,+ props.directoryPath + AppConfig.dirSeparator + file.name+ )+ .then(() => true)+ .catch(error => {+ console.log('renameFilePromise', error);+ })+ );+ } else {+ promises.push(+ PlatformIO.copyFilePromise(+ file.path,+ props.directoryPath + AppConfig.dirSeparator + file.name+ )+ .then(() => true)+ .catch(error => {+ console.log('copyFilePromise', error);+ })+ );+ }+ }+ Promise.all(promises)+ .then(() => props.loadDirectoryContent(props.directoryPath, true))+ .catch(error => {+ console.log('promises', error);+ });+ };+ /* const handleMoveFiles = (files: Array<File>) => {+ handleCopyFiles(files)+ .then(success => {+ if (AppConfig.isElectron && success) {+ for (const file of files) {+ PlatformIO.deleteFilePromise(file.path)+ .then(() => true)+ .catch(error => {+ console.log('deleteFilePromise', error);+ });+ }+ }+ return true;+ })+ .catch(error => {+ console.log('handleCopyFiles', error);+ });+ }; */++ const handleCopyFiles = files => {if (props.isReadOnlyMode) {props.showNotification(i18n.t('core:dndDisabledReadOnlyMode'),'error',true);- return;+ return Promise.reject(i18n.t('core:dndDisabledReadOnlyMode'));}- if (monitor) {- const { files } = monitor.getItem();+ if (files) {console.log('Dropped files: ' + JSON.stringify(files));if (!props.directoryPath) {props.showNotification(@@ -383,20 +456,25 @@ const MainPage = (props: Props) => {'error',true);- } else {- props.resetProgress();- props- .uploadFilesAPI(files, props.directoryPath, props.onUploadProgress)- .then(fsEntries => {- props.reflectCreateEntries(fsEntries);- return true;- })- .catch(error => {- console.log('uploadFiles', error);- });- props.toggleUploadDialog();+ return Promise.reject(+ new Error(+ 'Importing files failed, because no folder is opened in TagSpaces!'+ )+ );}+ props.resetProgress();+ return props+ .uploadFilesAPI(files, props.directoryPath, props.onUploadProgress)+ .then(fsEntries => {+ props.reflectCreateEntries(fsEntries);+ props.toggleUploadDialog();+ return true;+ })+ .catch(error => {+ console.log('uploadFiles', error);+ });}+ return Promise.reject(new Error('on files'));};const keyBindingHandlers = {@@ -476,13 +554,17 @@ const MainPage = (props: Props) => {percent.current = undefined;initialPrimarySize = '100%';minSecondarySize = '0%';- renderSplitter = () => null;+ renderSplitter = function() {+ return null;+ };}if (props.isEntryInFullWidth) {percent.current = undefined;initialPrimarySize = '0%';minPrimarySize = '0%';- renderSplitter = () => null;+ renderSplitter = function() {+ return null;+ };}return (<Split@@ -518,6 +600,22 @@ const MainPage = (props: Props) => {keyMap={keyMap}style={{ height: '100%' }}>+ <MoveCopyFilesDialog+ open={moveCopyDialogOpened !== undefined}+ onClose={() => {+ setMoveCopyDialogOpened(undefined);+ }}+ fullScreen={false}+ selectedFiles={moveCopyDialogOpened}+ handleMoveFiles={files => {+ handleMoveCopyFiles(files, true);+ setMoveCopyDialogOpened(undefined);+ }}+ handleCopyFiles={files => {+ handleMoveCopyFiles(files, false);+ setMoveCopyDialogOpened(undefined);+ }}+ />{props.isLocationDialogOpened && (<CreateEditLocationDialogAsyncopen={props.isLocationDialogOpened}@@ -662,7 +760,16 @@ const MainPage = (props: Props) => {`}</style>{props.isDesktopMode || (AppConfig.isAmplify && !props.user) ? (- <TargetFileBox accepts={[FILE]} onDrop={handleFileDrop}>+ <TargetFileBox+ accepts={[FILE]}+ onDrop={(item: any) => {+ if (AppConfig.isElectron) {+ setMoveCopyDialogOpened(item.files);+ } else {+ handleCopyFiles(item.files);+ }+ }}+ ><CustomDragLayer /><Drawer variant="persistent" anchor="left" open={drawerOpened}><MobileNavigation width={drawerWidth} />@@ -695,7 +802,7 @@ const MainPage = (props: Props) => {</div></HotKeys>);-};+}function mapStateToProps(state) {return {@@ -767,6 +874,7 @@ function mapDispatchToProps(dispatch) {setMainVerticalSplitSize: SettingsActions.setMainVerticalSplitSize,showNotification: AppActions.showNotification,reflectCreateEntries: AppActions.reflectCreateEntries,+ loadDirectoryContent: AppActions.loadDirectoryContent,openLocationManagerPanel: AppActions.openLocationManagerPanel,openTagLibraryPanel: AppActions.openTagLibraryPanel,// openSearchPanel: AppActions.openSearchPanel,