Skip to content

TagSpaces is an offline, open source, document manager with tagging support

set thumbnails for folder, adding copy with overwrite (#1341)

Stanimirfbaa5557f2ae
diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsx
index 38e88387e..a9dc21ca5 100644
--- a/app/components/menus/FileMenu.tsx
+++ b/app/components/menus/FileMenu.tsx
@@ -27,12 +27,18 @@ import OpenFileNatively from '@material-ui/icons/Launch';
import OpenContainingFolder from '@material-ui/icons/FolderOpen';
import AddRemoveTags from '@material-ui/icons/Loyalty';
import MoveCopy from '@material-ui/icons/FileCopy';
+import ImageIcon from '@material-ui/icons/Image';
import RenameFile from '@material-ui/icons/FormatTextdirectionLToR';
import DeleteForever from '@material-ui/icons/DeleteForever';
import i18n from '-/services/i18n';
import AppConfig from '-/config';
import PlatformIO from '-/services/platform-io';
-import { FileSystemEntry, getAllPropertiesPromise } from '-/services/utils-io';
+import {
+ FileSystemEntry,
+ getAllPropertiesPromise,
+ setFolderThumbnailPromise
+} from '-/services/utils-io';
+import { Pro } from '-/pro';
interface Props {
anchorEl: Element;
@@ -45,6 +51,11 @@ interface Props {
openFsEntry: (fsEntry: FileSystemEntry) => void;
openFileNatively: (path: string) => void;
showInFileManager: (path: string) => void;
+ showNotification: (
+ text: string,
+ notificationType?: string,
+ autohide?: boolean
+ ) => void;
selectedFilePath?: string;
isReadOnlyMode: boolean;
}
@@ -65,6 +76,37 @@ const FileMenu = (props: Props) => {
props.openMoveCopyFilesDialog();
}
+ function setFolderThumbnail() {
+ props.onClose();
+ setFolderThumbnailPromise(props.selectedFilePath)
+ .then(
+ (directoryPath: string) => {
+ props.showNotification('Thumbnail created for: ' + directoryPath);
+ return true;
+ }
+
+ // getAllPropertiesPromise(directoryPath)
+ // .then((fsEntry: FileSystemEntry) => {
+ // props.openFsEntry(fsEntry);
+ // return true;
+ // })
+ // .catch(error =>
+ // console.warn(
+ // 'Error getAllPropertiesPromise for: ' + directoryPath,
+ // error
+ // )
+ // )
+ )
+ .catch(error => {
+ props.showNotification('Thumbnail creation failed.');
+ console.warn(
+ 'Error setting Thumb for entry: ' + props.selectedFilePath,
+ error
+ );
+ return true;
+ });
+ }
+
function showAddRemoveTagsDialog() {
props.onClose();
props.openAddRemoveTagsDialog();
@@ -164,6 +206,14 @@ const FileMenu = (props: Props) => {
</ListItemIcon>
<ListItemText primary={i18n.t('core:moveCopyFile')} />
</MenuItem>
+ {Pro && (
+ <MenuItem data-tid="setAsThumbTID" onClick={setFolderThumbnail}>
+ <ListItemIcon>
+ <ImageIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:setAsThumbnail')} />
+ </MenuItem>
+ )}
<MenuItem
data-tid="fileMenuDeleteFile"
onClick={showDeleteFileDialog}
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index f4f7c630b..567e317d0 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -263,6 +263,7 @@
"warning": "Warning",
"info": "Info",
"signOut": "Sign Out",
+ "setAsThumbnail": "Use Thumbnail for this Folder",
"fileExtension": "File Ext.",
"fileTitle": "Title",
"fileTags": "Tags",
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index f6295db55..3fdd9122f 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -918,6 +918,7 @@ class GridPerspective extends React.Component<Props, State> {
openFsEntry={this.props.openFsEntry}
openFileNatively={this.props.openFileNatively}
showInFileManager={this.props.showInFileManager}
+ showNotification={this.props.showNotification}
isReadOnlyMode={this.props.isReadOnlyMode}
selectedFilePath={this.state.selectedEntryPath}
/>
diff --git a/app/services/electron-io.ts b/app/services/electron-io.ts
index e33031b10..3d4078ad3 100644
--- a/app/services/electron-io.ts
+++ b/app/services/electron-io.ts
@@ -24,8 +24,8 @@ import {
extractFileName,
extractParentDirectoryPath,
getMetaDirectoryPath
-} from '../utils/paths';
-import { arrayBufferToBuffer } from '../utils/misc';
+} from '-/utils/paths';
+import { arrayBufferToBuffer } from '-/utils/misc';
import AppConfig from '../config';
import PlatformIO from './platform-io';
import TrayIcon from '../assets/icons/trayIcon.png';
@@ -530,8 +530,8 @@ export default class ElectronIO {
);
} else if (this.fs.lstatSync(sourceFilePath).isDirectory()) {
reject('Trying to copy a file: ' + sourceFilePath + '. Copying failed');
- } else if (this.fs.existsSync(targetFilePath)) {
- reject('File "' + targetFilePath + '" exists. Copying failed.');
+ /* } else if (this.fs.existsSync(targetFilePath)) {
+ reject('File "' + targetFilePath + '" exists. Copying failed.'); */
} else {
this.fs.copy(sourceFilePath, targetFilePath, error => {
if (error) {
diff --git a/app/services/platform-io.ts b/app/services/platform-io.ts
index ff4d1820e..dcea55324 100644
--- a/app/services/platform-io.ts
+++ b/app/services/platform-io.ts
@@ -163,7 +163,36 @@ export default class PlatformIO {
return nativeAPI.createDirectoryPromise(dirPath);
};
- static copyFilePromise = (
+ static copyFilePromise = async (
+ sourceFilePath: string,
+ targetFilePath: string,
+ confirmMessage: string = 'File ' +
+ targetFilePath +
+ ' exist do you want to override it?'
+ ): Promise<any> => {
+ const isTargetExist = await PlatformIO.getPropertiesPromise(targetFilePath); // TODO rethink to create PlatformIO.isExistSync function
+ if (isTargetExist) {
+ // eslint-disable-next-line no-alert
+ const confirmOverwrite = window.confirm(confirmMessage);
+ if (confirmOverwrite === true) {
+ return PlatformIO.copyFilePromiseOverwrite(
+ sourceFilePath,
+ targetFilePath
+ );
+ }
+ // eslint-disable-next-line prefer-promise-reject-errors
+ return Promise.reject(
+ 'File "' + targetFilePath + '" exists. Copying failed.'
+ );
+ }
+ return PlatformIO.copyFilePromiseOverwrite(sourceFilePath, targetFilePath);
+ };
+
+ /**
+ * @param sourceFilePath
+ * @param targetFilePath - if exist overwrite it
+ */
+ static copyFilePromiseOverwrite = (
sourceFilePath: string,
targetFilePath: string
): Promise<any> => {
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 57c26d286..ed990870e 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -27,7 +27,9 @@ import {
getMetaDirectoryPath,
getMetaFileLocationForFile,
getMetaFileLocationForDir,
- extractContainingDirectoryPath
+ extractContainingDirectoryPath,
+ getThumbFileLocationForFile,
+ getThumbFileLocationForDirectory
} from '-/utils/paths';
import i18n from '../services/i18n';
import versionMeta from '../version.json';
@@ -862,6 +864,25 @@ export async function saveMetaDataPromise(
);
}
+/**
+ * @param filePath
+ * return Promise<directoryPath> of directory in order to open Folder properties next
+ */
+export function setFolderThumbnailPromise(filePath: string): Promise<string> {
+ const directoryPath = extractContainingDirectoryPath(
+ filePath,
+ PlatformIO.getDirSeparator()
+ );
+ return PlatformIO.copyFilePromise(
+ getThumbFileLocationForFile(filePath, PlatformIO.getDirSeparator()),
+ getThumbFileLocationForDirectory(
+ directoryPath,
+ PlatformIO.getDirSeparator()
+ ),
+ 'Thumbnail for ' + directoryPath + ' exist do you want to override it?'
+ ).then(() => directoryPath);
+}
+
export function findColorForFileEntry(
fileExtension: string,
isFile: boolean,