Skip to content

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

TSN548 - Kanban - various issues v3, changes in filename tagging (#1774)

Stanimir1d099785a7f1
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index d00ab0d25..6fa344ca1 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -233,13 +233,13 @@ function FolderContainer(props: Props) {
if (openedFile.perspective) {
props.setCurrentDirectoryPerspective(openedFile.perspective);
}
- } else {
+ } /*else {
const currentEntry = enhanceOpenedEntry(
openedFile,
props.settings.tagDelimiter
);
props.updateCurrentDirEntry(openedFile.path, currentEntry);
- }
+ }*/
}
}
havePrevOpenedFile.current = props.openedFiles.length > 0;
diff --git a/app/components/PathBreadcrumbs.tsx b/app/components/PathBreadcrumbs.tsx
index 8ecaddce7..cb7d653c9 100644
--- a/app/components/PathBreadcrumbs.tsx
+++ b/app/components/PathBreadcrumbs.tsx
@@ -212,7 +212,6 @@ function PathBreadcrumbs(props: Props) {
reflectCreateEntry={reflectCreateEntry}
openFsEntry={openFsEntry}
switchPerspective={switchPerspective}
- isReadOnlyMode={isReadOnlyMode}
/>
</>
);
diff --git a/app/components/dialogs/CreateDialog.tsx b/app/components/dialogs/CreateDialog.tsx
index 34eae831c..2f3972d98 100644
--- a/app/components/dialogs/CreateDialog.tsx
+++ b/app/components/dialogs/CreateDialog.tsx
@@ -37,7 +37,11 @@ import { formatDateTime4Tag } from '@tagspaces/tagspaces-platforms/misc';
import AppConfig from '@tagspaces/tagspaces-platforms/AppConfig';
import i18n from '-/services/i18n';
import { getKeyBindingObject } from '-/reducers/settings';
-import { actions as AppActions } from '-/reducers/app';
+import {
+ actions as AppActions,
+ getDirectoryPath,
+ getSelectedEntries
+} from '-/reducers/app';
import IOActions from '-/reducers/io-actions';
import { TS } from '-/tagspaces.namespace';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
@@ -61,8 +65,10 @@ const styles: any = () => ({
interface Props {
open: boolean;
classes: any;
- selectedDirectoryPath: string;
- chooseDirectoryPath: (path: string) => void;
+ selectedEntries: Array<TS.FileSystemEntry>;
+ currentDirectoryPath: string | null;
+ // selectedDirectoryPath: string;
+ // chooseDirectoryPath: (path: string) => void;
showNotification: (message: string, type: string, autohide: boolean) => void;
reflectCreateEntries: (fsEntries: Array<TS.FileSystemEntry>) => void;
createFileAdvanced: (
@@ -83,8 +89,7 @@ interface Props {
}
function CreateDialog(props: Props) {
- const { classes, selectedDirectoryPath, open, onClose } = props;
-
+ const { classes, open, onClose } = props;
const fileName = useRef<string>(
'note' +
AppConfig.beginTagContainer +
@@ -96,6 +101,14 @@ function CreateDialog(props: Props) {
let fileInput: HTMLInputElement;
const fileContent = '';
+ const selectedDirectoryPath =
+ props.selectedEntries && props.selectedEntries.length === 1
+ ? props.selectedEntries[0].path
+ : props.currentDirectoryPath;
+ if (!selectedDirectoryPath) {
+ return null;
+ }
+
// function handleKeyPress(event: any) {
// if (event.key === 'n') {
// event.stopPropagation();
@@ -373,7 +386,9 @@ function CreateDialog(props: Props) {
function mapStateToProps(state) {
return {
- keyBindings: getKeyBindingObject(state)
+ keyBindings: getKeyBindingObject(state),
+ selectedEntries: getSelectedEntries(state),
+ currentDirectoryPath: getDirectoryPath(state)
};
}
diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsx
index 4c501386d..a918f1760 100644
--- a/app/components/menus/DirectoryMenu.tsx
+++ b/app/components/menus/DirectoryMenu.tsx
@@ -19,25 +19,8 @@
import React, { useRef, useState } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
-import ListItemIcon from '@mui/material/ListItemIcon';
-import ListItemText from '@mui/material/ListItemText';
-import Tooltip from '-/components/Tooltip';
import Menu from '@mui/material/Menu';
-import MenuItem from '@mui/material/MenuItem';
-import Divider from '@mui/material/Divider';
-import OpenFolderIcon from '@mui/icons-material/SubdirectoryArrowLeft';
-import AddExistingFileIcon from '@mui/icons-material/ExitToApp';
-import ImportTagsIcon from '@mui/icons-material/FindInPage';
-import OpenFolderNativelyIcon from '@mui/icons-material/Launch';
-import AutoRenew from '@mui/icons-material/Autorenew';
-import NewFileIcon from '@mui/icons-material/InsertDriveFile';
-import ShareIcon from '@mui/icons-material/Link';
-import RenameFolderIcon from '@mui/icons-material/FormatTextdirectionLToR';
-import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
-import NewFolderIcon from '@mui/icons-material/CreateNewFolder';
-import PropertiesIcon from '@mui/icons-material/Info';
import { Progress } from 'aws-sdk/clients/s3';
-import ImageIcon from '@mui/icons-material/Image';
import { formatDateTime4Tag } from '@tagspaces/tagspaces-platforms/misc';
import AppConfig from '@tagspaces/tagspaces-platforms/AppConfig';
import {
@@ -49,10 +32,15 @@ import {
} from '@tagspaces/tagspaces-platforms/paths';
import { Pro } from '../../pro';
import CreateDirectoryDialog from '../dialogs/CreateDirectoryDialog';
-// import RenameDirectoryDialog from '../dialogs/RenameDirectoryDialog';
import i18n from '-/services/i18n';
import PlatformIO from '-/services/platform-facade';
-import { actions as AppActions, getSelectedEntries } from '-/reducers/app';
+import {
+ actions as AppActions,
+ getDirectoryPath,
+ getLastSelectedEntryPath,
+ getSelectedEntries,
+ isReadOnlyMode
+} from '-/reducers/app';
import IOActions from '-/reducers/io-actions';
import TaggingActions from '-/reducers/tagging-actions';
import { getAllPropertiesPromise } from '-/services/utils-io';
@@ -60,10 +48,10 @@ import FileUploadContainer, {
FileUploadContainerRef
} from '-/components/FileUploadContainer';
import { TS } from '-/tagspaces.namespace';
-import { ProLabel, BetaLabel } from '-/components/HelperComponents';
import Links from '-/links';
-import { PerspectiveIDs, AvailablePerspectives } from '-/perspectives';
+import { PerspectiveIDs } from '-/perspectives';
import PlatformFacade from '-/services/platform-facade';
+import { getDirectoryMenuItems } from '-/perspectives/common/DirectoryMenuItems';
interface Props {
open: boolean;
@@ -95,7 +83,6 @@ interface Props {
notificationType?: string,
autohide?: boolean
) => void;
- isReadOnlyMode?: boolean;
toggleUploadDialog: () => void;
toggleProgressDialog: () => void;
resetProgress: () => void;
@@ -106,8 +93,11 @@ interface Props {
) => void;
toggleDeleteMultipleEntriesDialog: () => void;
openRenameDirectoryDialog: () => void;
- selectedEntries: Array<any>;
- setSelectedEntries: (selectedEntries: Array<Object>) => void;
+ selectedEntries: Array<TS.FileSystemEntry>;
+ currentDirectoryPath: string;
+ lastSelectedEntryPath: string;
+ isReadOnlyMode: boolean;
+ setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;
mouseX?: number;
mouseY?: number;
openURLExternally?: (url: string, skipConfirmation: boolean) => void;
@@ -120,19 +110,16 @@ function DirectoryMenu(props: Props) {
const {
selectedEntries,
- isReadOnlyMode,
currentLocation,
locations,
showNotification,
- onClose
} = props;
function copySharingLink() {
- onClose();
if (selectedEntries.length === 1) {
- const entryFromIndex = selectedEntries[0].locationID;
+ const entryFromIndex = selectedEntries[0]['locationID'];
const locationID = entryFromIndex
- ? selectedEntries[0].locationID
+ ? selectedEntries[0]['locationID']
: currentLocation.uuid;
let relativePath = selectedEntries[0].path;
const tmpLoc = locations.find(location => location.uuid === locationID);
@@ -168,17 +155,14 @@ function DirectoryMenu(props: Props) {
] = useState(false);
function reloadDirectory() {
- onClose();
props.loadDirectoryContent(props.directoryPath, true, true);
}
function openDirectory() {
- onClose();
props.loadDirectoryContent(props.directoryPath, true, true);
}
function showProperties() {
- onClose();
getAllPropertiesPromise(props.directoryPath)
.then((fsEntry: TS.FileSystemEntry) => {
props.openFsEntry(fsEntry);
@@ -195,7 +179,6 @@ function DirectoryMenu(props: Props) {
}
function switchPerspective(perspectiveId) {
- onClose();
if (
Pro ||
perspectiveId === PerspectiveIDs.GRID ||
@@ -242,40 +225,40 @@ function DirectoryMenu(props: Props) {
}
function showDeleteDirectoryDialog() {
- onClose();
props.setSelectedEntries([
- { isFile: false, name: props.directoryPath, path: props.directoryPath }
+ {
+ isFile: false,
+ name: props.directoryPath,
+ path: props.directoryPath,
+ tags: [],
+ size: 0,
+ lmdt: 0
+ }
]);
props.toggleDeleteMultipleEntriesDialog();
}
function showRenameDirectoryDialog() {
- onClose();
props.openRenameDirectoryDialog();
}
function showCreateDirectoryDialog() {
- onClose();
setIsCreateDirectoryDialogOpened(true);
}
function createNewFile() {
- onClose();
props.toggleCreateFileDialog();
}
function showInFileManager() {
- onClose();
props.openDirectory(props.directoryPath);
}
function addExistingFile() {
- onClose();
fileUploadContainerRef.current.onFileUpload();
}
function importMacTags() {
- onClose();
if (Pro && Pro.MacTagsImport && Pro.MacTagsImport.importTags) {
if (
!confirm(`Experimental feature\n
@@ -383,7 +366,6 @@ Do you want to continue?`)
// }
function cameraTakePicture() {
- onClose();
// @ts-ignore
navigator.camera.getPicture(onCameraSuccess, onFail, {
// quality: 50,
@@ -396,7 +378,6 @@ Do you want to continue?`)
}
function setFolderThumbnail() {
- onClose();
const parentDirectoryPath = extractContainingDirectoryPath(
props.directoryPath,
PlatformIO.getDirSeparator()
@@ -435,247 +416,26 @@ Do you want to continue?`)
});
}
- const menuItems = [];
-
- if (selectedEntries.length < 2) {
- if (props.perspectiveMode) {
- menuItems.push(
- <MenuItem
- key="openDirectory"
- data-tid="openDirectory"
- onClick={openDirectory}
- >
- <ListItemIcon>
- <OpenFolderIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:openDirectory')} />
- </MenuItem>
- );
- } else {
- menuItems.push(
- <MenuItem
- key="reloadDirectory"
- data-tid="reloadDirectory"
- onClick={reloadDirectory}
- >
- <ListItemIcon>
- <AutoRenew />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:reloadDirectory')} />
- </MenuItem>
- );
- }
- if (!isReadOnlyMode) {
- menuItems.push(
- <MenuItem
- key="renameDirectory"
- data-tid="renameDirectory"
- onClick={showRenameDirectoryDialog}
- >
- <ListItemIcon>
- <RenameFolderIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:renameDirectory')} />
- </MenuItem>
- );
- }
- }
-
- if (!isReadOnlyMode) {
- menuItems.push(
- <MenuItem
- key="deleteDirectory"
- data-tid="deleteDirectory"
- onClick={showDeleteDirectoryDialog}
- >
- <ListItemIcon>
- <DeleteForeverIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:deleteDirectory')} />
- </MenuItem>
- );
- }
-
- if (
- selectedEntries.length < 2 &&
- !(
- PlatformIO.haveObjectStoreSupport() ||
- PlatformIO.haveWebDavSupport() ||
- AppConfig.isWeb
- )
- ) {
- menuItems.push(
- <MenuItem
- key="showInFileManager"
- data-tid="showInFileManager"
- onClick={showInFileManager}
- >
- <ListItemIcon>
- <OpenFolderNativelyIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:showInFileManager')} />
- </MenuItem>
- );
- }
- if (!props.perspectiveMode) {
- menuItems.push(<Divider key="divider1" />);
- }
- if (!isReadOnlyMode && !props.perspectiveMode) {
- menuItems.push(
- <MenuItem
- key="createNewFile"
- data-tid="createNewFile"
- onClick={createNewFile}
- >
- <ListItemIcon>
- <NewFileIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:newFileNote')} />
- </MenuItem>
- );
- menuItems.push(
- <MenuItem
- key="newSubDirectory"
- data-tid="newSubDirectory"
- onClick={showCreateDirectoryDialog}
- >
- <ListItemIcon>
- <NewFolderIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:newSubdirectory')} />
- </MenuItem>
- );
- menuItems.push(
- <MenuItem
- key="addExistingFile"
- data-tid="addExistingFile"
- onClick={addExistingFile}
- >
- <ListItemIcon>
- <AddExistingFileIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:addFiles')} />
- </MenuItem>
- );
- }
- if (Pro && props.perspectiveMode && selectedEntries.length < 2) {
- menuItems.push(
- <MenuItem
- key="setAsThumb"
- data-tid="setAsThumbTID"
- onClick={setFolderThumbnail}
- >
- <ListItemIcon>
- <ImageIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:setAsParentFolderThumbnail')} />
- </MenuItem>
- );
- }
- if (selectedEntries.length === 1) {
- menuItems.push(
- <MenuItem
- key="copySharingLink"
- data-tid="copyDirectorySharingLink"
- onClick={copySharingLink}
- >
- <ListItemIcon>
- <ShareIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:copySharingLink')} />
- </MenuItem>
- );
- }
-
- if (
- selectedEntries.length < 2 &&
- AppConfig.isElectron &&
- AppConfig.isMacLike
- ) {
- menuItems.push(
- <MenuItem
- key="importMacTags"
- data-tid="importMacTags"
- onClick={importMacTags}
- >
- <ListItemIcon>
- <ImportTagsIcon />
- </ListItemIcon>
- <ListItemText
- primary={
- <>
- {i18n.t('core:importMacTags')}
- {Pro ? <BetaLabel /> : <ProLabel />}
- </>
- }
- />
- </MenuItem>
- );
- }
-
- if (AppConfig.isCordova) {
- // .isCordovaAndroid) {
- menuItems.push(
- <MenuItem
- key="takePicture"
- data-tid="takePicture"
- onClick={cameraTakePicture}
- >
- <ListItemIcon>
- <AddExistingFileIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:cameraTakePicture')} />
- </MenuItem>
- );
- }
- if (!props.perspectiveMode) {
- menuItems.push(<Divider key="divider2" />);
- AvailablePerspectives.forEach(perspective => {
- let badge = <></>;
- if (!Pro && perspective.pro) {
- badge = <ProLabel />;
- }
- if (!Pro && perspective.beta) {
- badge = <BetaLabel />;
- }
- if (Pro && perspective.beta) {
- badge = <BetaLabel />;
- }
- menuItems.push(
- <MenuItem
- key={perspective.key}
- data-tid={perspective.key}
- onClick={() => switchPerspective(perspective.id)}
- >
- <ListItemIcon>{perspective.icon}</ListItemIcon>
- <ListItemText
- primary={
- <>
- {perspective.title}
- {badge}
- </>
- }
- />
- </MenuItem>
- );
- });
- }
-
- if (selectedEntries.length < 2) {
- menuItems.push(<Divider key="divider3" />);
- menuItems.push(
- <MenuItem
- key="showProperties"
- data-tid="showProperties"
- onClick={showProperties}
- >
- <ListItemIcon>
- <PropertiesIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:directoryPropertiesTitle')} />
- </MenuItem>
- );
- }
+ const menuItems = getDirectoryMenuItems(
+ props.selectedEntries.length,
+ props.lastSelectedEntryPath !== props.currentDirectoryPath,
+ props.isReadOnlyMode,
+ props.onClose,
+ openDirectory,
+ reloadDirectory,
+ showRenameDirectoryDialog,
+ showDeleteDirectoryDialog,
+ showInFileManager,
+ createNewFile,
+ showCreateDirectoryDialog,
+ addExistingFile,
+ setFolderThumbnail,
+ copySharingLink,
+ importMacTags,
+ switchPerspective,
+ showProperties,
+ cameraTakePicture
+ );
return (
<div style={{ overflowY: 'hidden' }}>
@@ -718,7 +478,10 @@ Do you want to continue?`)
function mapStateToProps(state) {
return {
- selectedEntries: getSelectedEntries(state)
+ selectedEntries: getSelectedEntries(state),
+ currentDirectoryPath: getDirectoryPath(state),
+ lastSelectedEntryPath: getLastSelectedEntryPath(state),
+ isReadOnlyMode: isReadOnlyMode(state)
};
}
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index 99ec5e1b3..a928a1c7e 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -323,10 +323,10 @@ function OpenLinkDialogAsync(props) {
function MainPage(props: Props) {
// const [percent, setPercent] = React.useState<number | undefined>(undefined);
const percent = useRef<number | undefined>(undefined);
- const selectedDirectoryPath = useRef<string>('');
- const setSelectedDirectoryPath = (path: string) => {
+ // const selectedDirectoryPath = useRef<string>('');
+ /*const setSelectedDirectoryPath = (path: string) => {
selectedDirectoryPath.current = path;
- };
+ };*/
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
const width =
@@ -703,11 +703,11 @@ function MainPage(props: Props) {
{props.isCreateFileDialogOpened && (
<CreateFileDialog
open={props.isCreateFileDialogOpened}
- selectedDirectoryPath={selectedDirectoryPath.current || directoryPath}
- chooseDirectoryPath={currentPath =>
- setSelectedDirectoryPath(currentPath)
- }
onClose={toggleCreateFileDialog}
+ // selectedDirectoryPath={selectedDirectoryPath.current || directoryPath}
+ /*chooseDirectoryPath={currentPath =>
+ setSelectedDirectoryPath(currentPath)
+ }*/
/>
)}
{props.isSettingsDialogOpened && (
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index cb30cb7df..c32441851 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -517,6 +517,7 @@
"sharingLink": "Link for internal sharing",
"folderLimit": "Max. folders to be displayed",
"filesLimit": "Max. files to be displayed in a folder",
+ "scrollFilesLimit": "Files to be loaded on scroll down",
"goback": "Go Back",
"goforward": "Go Forward",
"switchSimpleMode": "Simple Mode",
diff --git a/app/perspectives/common/DirectoryMenuItems.tsx b/app/perspectives/common/DirectoryMenuItems.tsx
new file mode 100644
index 000000000..e3d63bcf6
--- /dev/null
+++ b/app/perspectives/common/DirectoryMenuItems.tsx
@@ -0,0 +1,343 @@
+import MenuItem from '@mui/material/MenuItem';
+import ListItemIcon from '@mui/material/ListItemIcon';
+import OpenFolderIcon from '@mui/icons-material/SubdirectoryArrowLeft';
+import ListItemText from '@mui/material/ListItemText';
+import i18n from '-/services/i18n';
+import AutoRenew from '@mui/icons-material/Autorenew';
+import RenameFolderIcon from '@mui/icons-material/FormatTextdirectionLToR';
+import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
+import PlatformIO from '-/services/platform-facade';
+import AppConfig from '@tagspaces/tagspaces-platforms/AppConfig';
+import OpenFolderNativelyIcon from '@mui/icons-material/Launch';
+import Divider from '@mui/material/Divider';
+import NewFileIcon from '@mui/icons-material/InsertDriveFile';
+import NewFolderIcon from '@mui/icons-material/CreateNewFolder';
+import AddExistingFileIcon from '@mui/icons-material/ExitToApp';
+import { Pro } from '-/pro';
+import ImageIcon from '@mui/icons-material/Image';
+import ShareIcon from '@mui/icons-material/Link';
+import ImportTagsIcon from '@mui/icons-material/FindInPage';
+import { BetaLabel, ProLabel } from '-/components/HelperComponents';
+import { AvailablePerspectives } from '-/perspectives';
+import PropertiesIcon from '@mui/icons-material/Info';
+import React from 'react';
+
+export function getDirectoryMenuItems(
+ selectedEntriesLength: number,
+ perspectiveMode: boolean,
+ isReadOnlyMode: boolean,
+ onClose: () => void,
+ openDirectory?: () => void,
+ reloadDirectory?: () => void,
+ showRenameDirectoryDialog?: () => void,
+ showDeleteDirectoryDialog?: () => void,
+ showInFileManager?: () => void,
+ createNewFile?: () => void,
+ showCreateDirectoryDialog?: () => void,
+ addExistingFile?: () => void,
+ setFolderThumbnail?: () => void,
+ copySharingLink?: () => void,
+ importMacTags?: () => void,
+ switchPerspective?: (perspectiveId: string) => void,
+ showProperties?: () => void,
+ cameraTakePicture?: () => void
+) {
+ const menuItems = [];
+ if (selectedEntriesLength < 2) {
+ if (perspectiveMode) {
+ if (openDirectory) {
+ menuItems.push(
+ <MenuItem
+ key="openDirectory"
+ data-tid="openDirectory"
+ onClick={() => {
+ onClose();
+ openDirectory();
+ }}
+ >
+ <ListItemIcon>
+ <OpenFolderIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:openDirectory')} />
+ </MenuItem>
+ );
+ }
+ } else if (reloadDirectory) {
+ menuItems.push(
+ <MenuItem
+ key="reloadDirectory"
+ data-tid="reloadDirectory"
+ onClick={() => {
+ onClose();
+ reloadDirectory();
+ }}
+ >
+ <ListItemIcon>
+ <AutoRenew />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:reloadDirectory')} />
+ </MenuItem>
+ );
+ }
+ if (!isReadOnlyMode && showRenameDirectoryDialog) {
+ menuItems.push(
+ <MenuItem
+ key="renameDirectory"
+ data-tid="renameDirectory"
+ onClick={() => {
+ onClose();
+ showRenameDirectoryDialog();
+ }}
+ >
+ <ListItemIcon>
+ <RenameFolderIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:renameDirectory')} />
+ </MenuItem>
+ );
+ }
+ }
+
+ if (!isReadOnlyMode && showDeleteDirectoryDialog) {
+ menuItems.push(
+ <MenuItem
+ key="deleteDirectory"
+ data-tid="deleteDirectory"
+ onClick={() => {
+ onClose();
+ showDeleteDirectoryDialog();
+ }}
+ >
+ <ListItemIcon>
+ <DeleteForeverIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:deleteDirectory')} />
+ </MenuItem>
+ );
+ }
+
+ if (
+ selectedEntriesLength < 2 &&
+ !(
+ PlatformIO.haveObjectStoreSupport() ||
+ PlatformIO.haveWebDavSupport() ||
+ AppConfig.isWeb
+ ) &&
+ showInFileManager
+ ) {
+ menuItems.push(
+ <MenuItem
+ key="showInFileManager"
+ data-tid="showInFileManager"
+ onClick={() => {
+ onClose();
+ showInFileManager();
+ }}
+ >
+ <ListItemIcon>
+ <OpenFolderNativelyIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:showInFileManager')} />
+ </MenuItem>
+ );
+ }
+ if (!perspectiveMode) {
+ menuItems.push(<Divider key="divider1" />);
+ }
+ if (!isReadOnlyMode && !perspectiveMode) {
+ if (createNewFile) {
+ menuItems.push(
+ <MenuItem
+ key="createNewFile"
+ data-tid="createNewFile"
+ onClick={() => {
+ onClose();
+ createNewFile();
+ }}
+ >
+ <ListItemIcon>
+ <NewFileIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:newFileNote')} />
+ </MenuItem>
+ );
+ }
+ if (showCreateDirectoryDialog) {
+ menuItems.push(
+ <MenuItem
+ key="newSubDirectory"
+ data-tid="newSubDirectory"
+ onClick={() => {
+ onClose();
+ showCreateDirectoryDialog();
+ }}
+ >
+ <ListItemIcon>
+ <NewFolderIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:newSubdirectory')} />
+ </MenuItem>
+ );
+ }
+ if (addExistingFile) {
+ menuItems.push(
+ <MenuItem
+ key="addExistingFile"
+ data-tid="addExistingFile"
+ onClick={() => {
+ onClose();
+ addExistingFile();
+ }}
+ >
+ <ListItemIcon>
+ <AddExistingFileIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:addFiles')} />
+ </MenuItem>
+ );
+ }
+ }
+ if (
+ Pro &&
+ perspectiveMode &&
+ selectedEntriesLength < 2 &&
+ setFolderThumbnail
+ ) {
+ menuItems.push(
+ <MenuItem
+ key="setAsThumb"
+ data-tid="setAsThumbTID"
+ onClick={() => {
+ onClose();
+ setFolderThumbnail();
+ }}
+ >
+ <ListItemIcon>
+ <ImageIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:setAsParentFolderThumbnail')} />
+ </MenuItem>
+ );
+ }
+ if (selectedEntriesLength === 1 && copySharingLink) {
+ menuItems.push(
+ <MenuItem
+ key="copySharingLink"
+ data-tid="copyDirectorySharingLink"
+ onClick={() => {
+ onClose();
+ copySharingLink();
+ }}
+ >
+ <ListItemIcon>
+ <ShareIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:copySharingLink')} />
+ </MenuItem>
+ );
+ }
+
+ if (
+ selectedEntriesLength < 2 &&
+ AppConfig.isElectron &&
+ AppConfig.isMacLike &&
+ importMacTags
+ ) {
+ menuItems.push(
+ <MenuItem
+ key="importMacTags"
+ data-tid="importMacTags"
+ onClick={() => {
+ onClose();
+ importMacTags();
+ }}
+ >
+ <ListItemIcon>
+ <ImportTagsIcon />
+ </ListItemIcon>
+ <ListItemText
+ primary={
+ <>
+ {i18n.t('core:importMacTags')}
+ {Pro ? <BetaLabel /> : <ProLabel />}
+ </>
+ }
+ />
+ </MenuItem>
+ );
+ }
+
+ if (AppConfig.isCordova && cameraTakePicture) {
+ // .isCordovaAndroid) {
+ menuItems.push(
+ <MenuItem
+ key="takePicture"
+ data-tid="takePicture"
+ onClick={() => {
+ onClose();
+ cameraTakePicture();
+ }}
+ >
+ <ListItemIcon>
+ <AddExistingFileIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:cameraTakePicture')} />
+ </MenuItem>
+ );
+ }
+ if (!perspectiveMode && switchPerspective) {
+ menuItems.push(<Divider key="divider2" />);
+ AvailablePerspectives.forEach(perspective => {
+ let badge = <></>;
+ if (!Pro && perspective.pro) {
+ badge = <ProLabel />;
+ }
+ if (!Pro && perspective.beta) {
+ badge = <BetaLabel />;
+ }
+ if (Pro && perspective.beta) {
+ badge = <BetaLabel />;
+ }
+ menuItems.push(
+ <MenuItem
+ key={perspective.key}
+ data-tid={perspective.key}
+ onClick={() => {
+ onClose();
+ switchPerspective(perspective.id);
+ }}
+ >
+ <ListItemIcon>{perspective.icon}</ListItemIcon>
+ <ListItemText
+ primary={
+ <>
+ {perspective.title}
+ {badge}
+ </>
+ }
+ />
+ </MenuItem>
+ );
+ });
+ }
+
+ if (selectedEntriesLength < 2 && showProperties) {
+ menuItems.push(<Divider key="divider3" />);
+ menuItems.push(
+ <MenuItem
+ key="showProperties"
+ data-tid="showProperties"
+ onClick={() => {
+ onClose();
+ showProperties();
+ }}
+ >
+ <ListItemIcon>
+ <PropertiesIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:directoryPropertiesTitle')} />
+ </MenuItem>
+ );
+ }
+ return menuItems;
+}
diff --git a/app/perspectives/common/main-container.tsx b/app/perspectives/common/main-container.tsx
index 7160e9449..e26bef957 100644
--- a/app/perspectives/common/main-container.tsx
+++ b/app/perspectives/common/main-container.tsx
@@ -34,6 +34,7 @@ export const renderCell = (
index: number,
cellContent: (
fsEntry: TS.FileSystemEntry,
+ selectedEntries: Array<TS.FileSystemEntry>,
index: number,
handleGridContextMenu,
handleGridCellClick,
@@ -49,7 +50,7 @@ export const renderCell = (
currentLocation,
selectedEntries,
setSelectedEntries,
- lastSelectedEntry,
+ lastSelectedEntryPath,
directoryContent,
openFsEntry,
openFileNatively,
@@ -120,7 +121,9 @@ export const renderCell = (
} else {
setSelectedEntries([fsEntry]);
}
- setDirContextMenuAnchorEl(event.currentTarget);
+ if (setDirContextMenuAnchorEl) {
+ setDirContextMenuAnchorEl(event.currentTarget);
+ }
}
};
@@ -165,9 +168,9 @@ export const renderCell = (
const selectHelperKey = AppConfig.isMacLike ? event.metaKey : event.ctrlKey;
if (event.shiftKey) {
let lastSelectedIndex;
- if (lastSelectedEntry) {
+ if (lastSelectedEntryPath) {
lastSelectedIndex = directoryContent.findIndex(
- entry => entry.path === lastSelectedEntry.path
+ entry => entry.path === lastSelectedEntryPath
);
}
const currentSelectedIndex = directoryContent.findIndex(
@@ -264,6 +267,7 @@ export const renderCell = (
<FileSourceDnd key={key}>
{cellContent(
fsEntry,
+ selectedEntries,
index,
handleGridContextMenu,
handleGridCellClick,
@@ -288,6 +292,7 @@ export const renderCell = (
>
{cellContent(
fsEntry,
+ selectedEntries,
index,
handleGridContextMenu,
handleGridCellClick,
diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsx
index f4deec47d..7ef773f82 100644
--- a/app/perspectives/grid-perspective/components/GridPagination.tsx
+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx
@@ -44,7 +44,8 @@ import {
isLoading,
getCurrentDirectoryDescription,
getLastBackgroundImageChange,
- getLastThumbnailImageChange
+ getLastThumbnailImageChange,
+ getLastSelectedEntryPath
} from '-/reducers/app';
import EntryIcon from '-/components/EntryIcon';
import TagsPreview from '-/components/TagsPreview';
@@ -82,6 +83,7 @@ interface Props {
// pageEntries: Array<TS.FileSystemEntry>;
getCellContent: (
fsEntry: TS.FileSystemEntry,
+ selectedEntries: Array<TS.FileSystemEntry>,
index: number,
handleGridContextMenu,
handleGridCellClick,
@@ -110,7 +112,7 @@ interface Props {
setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;
singleClickAction: string;
currentLocation: TS.Location;
- lastSelectedEntry: any;
+ lastSelectedEntryPath: string;
directoryContent: Array<TS.FileSystemEntry>;
supportedFileTypes: Array<any>;
openFsEntry: (fsEntry?: TS.FileSystemEntry) => void;
@@ -563,7 +565,7 @@ function GridPagination(props: Props) {
props.currentLocation,
props.selectedEntries,
props.setSelectedEntries,
- props.lastSelectedEntry,
+ props.lastSelectedEntryPath,
props.directoryContent,
props.openFsEntry,
props.openFileNatively,
@@ -589,7 +591,7 @@ function GridPagination(props: Props) {
props.currentLocation,
props.selectedEntries,
props.setSelectedEntries,
- props.lastSelectedEntry,
+ props.lastSelectedEntryPath,
props.directoryContent,
props.openFsEntry,
props.openFileNatively,
@@ -685,7 +687,8 @@ function mapStateToProps(state) {
isMetaLoaded: getIsMetaLoaded(state),
currentDirectoryDescription: getCurrentDirectoryDescription(state),
lastBackgroundImageChange: getLastBackgroundImageChange(state),
- lastThumbnailImageChange: getLastThumbnailImageChange(state)
+ lastThumbnailImageChange: getLastThumbnailImageChange(state),
+ lastSelectedEntryPath: getLastSelectedEntryPath(state)
};
}
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index b71a81a0f..68522913b 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -50,11 +50,11 @@ import IOActions from '-/reducers/io-actions';
import {
actions as AppActions,
getDirectoryMeta,
- getLastSelectedEntry,
+ getLastSelectedEntry, getLastSelectedEntryPath,
getSelectedEntries,
isDeleteMultipleEntriesDialogOpened,
isReadOnlyMode
-} from '-/reducers/app';
+} from "-/reducers/app";
import TaggingActions from '-/reducers/tagging-actions';
import CellContent from './CellContent';
import MainToolbar from './MainToolbar';
@@ -78,7 +78,8 @@ interface Props {
desktopMode: boolean;
currentDirectoryPath: string;
lastSelectedEntry: any;
- selectedEntries: Array<any>;
+ selectedEntries: Array<TS.FileSystemEntry>;
+ lastSelectedEntryPath: string;
supportedFileTypes: Array<any>;
isReadOnlyMode: boolean;
openFsEntry: (fsEntry?: TS.FileSystemEntry) => void;
@@ -513,13 +514,6 @@ function GridPerspective(props: Props) {
}
};
- const getSelEntryPath = () => {
- if (props.lastSelectedEntry) {
- return props.lastSelectedEntry.path;
- }
- return currentDirectoryPath;
- };
-
const keyBindingHandlers = {
nextDocument: () => props.openNextFile(),
prevDocument: () => props.openPrevFile(),
@@ -530,7 +524,7 @@ function GridPerspective(props: Props) {
}
},
addRemoveTags: () => {
- if (getSelEntryPath()) {
+ if (props.lastSelectedEntryPath) {
openAddRemoveTagsDialog();
}
},
@@ -569,6 +563,7 @@ function GridPerspective(props: Props) {
const getCellContent = (
fsEntry: TS.FileSystemEntry,
+ selectedEntries: Array<TS.FileSystemEntry>,
index: number,
handleGridContextMenu,
handleGridCellClick,
@@ -693,7 +688,6 @@ function GridPerspective(props: Props) {
setSelectedEntries={props.setSelectedEntries}
singleClickAction={singleClickAction.current}
currentLocation={props.currentLocation}
- lastSelectedEntry={props.lastSelectedEntry}
directoryContent={props.directoryContent}
supportedFileTypes={props.supportedFileTypes}
openFsEntry={props.openFsEntry}
@@ -787,7 +781,7 @@ function GridPerspective(props: Props) {
showInFileManager={props.showInFileManager}
showNotification={props.showNotification}
isReadOnlyMode={props.isReadOnlyMode}
- selectedFilePath={getSelEntryPath()}
+ selectedFilePath={props.lastSelectedEntryPath}
selectedEntries={props.selectedEntries}
currentLocation={props.currentLocation}
locations={props.locations}
@@ -800,13 +794,12 @@ function GridPerspective(props: Props) {
anchorEl={dirContextMenuAnchorEl}
mouseX={mouseX}
mouseY={mouseY}
- directoryPath={getSelEntryPath()}
+ directoryPath={props.lastSelectedEntryPath}
loadDirectoryContent={props.loadDirectoryContent}
openRenameDirectoryDialog={props.openRenameEntryDialog}
openDirectory={props.openDirectory}
openFsEntry={props.openFsEntry}
- isReadOnlyMode={props.isReadOnlyMode}
- perspectiveMode={getSelEntryPath() !== props.currentDirectoryPath}
+ perspectiveMode={props.lastSelectedEntryPath !== props.currentDirectoryPath}
currentLocation={props.currentLocation}
locations={props.locations}
/>
@@ -882,6 +875,7 @@ function mapStateToProps(state) {
lastSelectedEntry: getLastSelectedEntry(state),
desktopMode: getDesktopMode(state),
selectedEntries: getSelectedEntries(state),
+ lastSelectedEntryPath: getLastSelectedEntryPath(state),
keyBindings: getKeyBindingObject(state),
currentLocation: getLocation(state, state.app.currentLocationId),
locations: getLocations(state),
diff --git a/app/perspectives/list/components/MainContainer.tsx b/app/perspectives/list/components/MainContainer.tsx
index a5e39171d..8e7aa2f71 100644
--- a/app/perspectives/list/components/MainContainer.tsx
+++ b/app/perspectives/list/components/MainContainer.tsx
@@ -571,6 +571,7 @@ function GridPerspective(props: Props) {
const getCellContent = (
fsEntry: TS.FileSystemEntry,
+ selectedEntries: Array<TS.FileSystemEntry>,
index: number,
handleGridContextMenu,
handleGridCellClick,
@@ -692,7 +693,7 @@ function GridPerspective(props: Props) {
setSelectedEntries={props.setSelectedEntries}
singleClickAction={singleClickAction.current}
currentLocation={props.currentLocation}
- lastSelectedEntry={props.lastSelectedEntry}
+ // lastSelectedEntry={props.lastSelectedEntry}
directoryContent={props.directoryContent}
supportedFileTypes={props.supportedFileTypes}
openFsEntry={props.openFsEntry}
@@ -804,7 +805,6 @@ function GridPerspective(props: Props) {
openRenameDirectoryDialog={props.openRenameEntryDialog}
openDirectory={props.openDirectory}
openFsEntry={props.openFsEntry}
- isReadOnlyMode={props.isReadOnlyMode}
perspectiveMode={getSelEntryPath() !== props.currentDirectoryPath}
currentLocation={props.currentLocation}
locations={props.locations}
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 7797917a3..7a2a8758e 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -132,6 +132,7 @@ export const types = {
// REFLECT_UPDATE_SIDECARMETA: 'APP/REFLECT_UPDATE_SIDECARMETA',
UPDATE_CURRENTDIR_ENTRY: 'APP/UPDATE_CURRENTDIR_ENTRY',
UPDATE_CURRENTDIR_ENTRIES: 'APP/UPDATE_CURRENTDIR_ENTRIES',
+ REFLECT_EDITED_ENTRY_PATHS: 'APP/REFLECT_EDITED_ENTRY_PATHS',
SET_ISLOADING: 'APP/SET_ISLOADING'
};
@@ -655,7 +656,7 @@ export default (state: any = initialState, action: any) => {
PlatformIO.getDirSeparator()
),
tags: [
- ...entry.tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags
+ ...entry.tags.filter(tag => tag.type !== 'plain'), //'sidecar'), // add only sidecar tags
...fileNameTags
]
};
@@ -670,7 +671,7 @@ export default (state: any = initialState, action: any) => {
...entry,
path: action.newPath, // TODO handle change extension case
tags: [
- ...entry.tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags
+ ...entry.tags.filter(tag => tag.type !== 'plain'), //'sidecar'), // add only sidecar tags
...fileNameTags
]
// shouldReload: true
@@ -736,9 +737,17 @@ export default (state: any = initialState, action: any) => {
currentDirectoryEntries: action.dirEntries
};
}
+ case types.REFLECT_EDITED_ENTRY_PATHS: {
+ return {
+ ...state,
+ editedEntryPaths: action.paths
+ };
+ }
case types.UPDATE_CURRENTDIR_ENTRY: {
return {
...state,
+ // to reload cell in KanBan if add/remove sidecar tags
+ // editedEntryPaths: [{ [action.path]: action.entry.tags }],
currentDirectoryEntries: state.currentDirectoryEntries.map(entry => {
if (entry.path !== action.path) {
return entry;
@@ -1884,6 +1893,19 @@ export const actions = {
});
}
},
+ openEntry: (path: string) => (
+ dispatch: (action) => void
+ ) => {
+ return getAllPropertiesPromise(path)
+ .then((fsEntry: TS.FileSystemEntry) =>
+ dispatch(actions.openFsEntry(fsEntry))
+ )
+ .catch(error =>
+ console.warn(
+ 'Error getting properties for entry: ' + path + ' - ' + error
+ )
+ );
+ },
openFsEntry: (fsEntry?: TS.FileSystemEntry) => (
dispatch: (action) => void,
getState: () => any
@@ -2105,6 +2127,10 @@ export const actions = {
type: types.UPDATE_CURRENTDIR_ENTRIES,
dirEntries
}),
+ reflectEditedEntryPaths: (paths: Array<any>) => ({
+ type: types.REFLECT_EDITED_ENTRY_PATHS,
+ paths
+ }),
/**
* @param path
* @param tags
@@ -2116,16 +2142,18 @@ export const actions = {
updateIndex = true
) => (dispatch: (action) => void, getState: () => any) => {
const { openedFiles, selectedEntries } = getState().app;
+ // to reload cell in KanBan if add/remove sidecar tags
+ dispatch(actions.reflectEditedEntryPaths([{ [path]: tags }]));
/**
* if its have openedFiles updateCurrentDirEntry is called from FolderContainer (useEffect -> ... if (openedFile.changed)
*/
- if (
+ /*if (
openedFiles.length === 0 ||
!openedFiles.some(obj => obj.path === path) ||
selectedEntries.length > 1
- ) {
- dispatch(actions.updateCurrentDirEntry(path, { tags }));
- }
+ ) {*/
+ dispatch(actions.updateCurrentDirEntry(path, { tags }));
+ // }
if (updateIndex) {
dispatch(LocationIndexActions.reflectUpdateSidecarTags(path, tags));
}
@@ -2191,9 +2219,8 @@ export const actions = {
true
)
);
- dispatch(actions.reflectRenameEntry(filePath, newFilePathFromPromise));
// Update sidecar file and thumb
- renameFilesPromise([
+ return renameFilesPromise([
[
getMetaFileLocationForFile(filePath, PlatformIO.getDirSeparator()),
getMetaFileLocationForFile(
@@ -2215,6 +2242,9 @@ export const actions = {
]
])
.then(() => {
+ dispatch(
+ actions.reflectRenameEntry(filePath, newFilePathFromPromise)
+ );
console.info(
'Renaming meta file and thumb successful from ' +
filePath +
@@ -2224,17 +2254,18 @@ export const actions = {
return true;
})
.catch(err => {
+ dispatch(
+ actions.reflectRenameEntry(filePath, newFilePathFromPromise)
+ );
console.warn(
'Renaming meta file and thumb failed from ' +
filePath +
' to:' +
- newFilePath +
- ' with ' +
- err
+ newFilePath,
+ err
);
return false;
});
- return true;
})
.catch(error => {
console.warn('Error while renaming file: ' + error);
@@ -2518,9 +2549,18 @@ export const getLastSelectedEntry = (state: any) => {
}
return undefined;
};
+export const getLastSelectedEntryPath = (state: any) => {
+ const { selectedEntries, currentDirectoryPath } = state.app;
+ if (selectedEntries && selectedEntries.length > 0) {
+ return selectedEntries[selectedEntries.length - 1].path;
+ }
+ return currentDirectoryPath;
+};
export const getSelectedTag = (state: any) => state.app.tag;
export const getSelectedEntries = (state: any) =>
state.app.selectedEntries ? state.app.selectedEntries : [];
+export const getSelectedEntriesLength = (state: any) =>
+ state.app.selectedEntries ? state.app.selectedEntries.length : 0;
export const getDirectoryMeta = (state: any) => state.app.directoryMeta;
export const isGeneratingThumbs = (state: any) => state.app.isGeneratingThumbs;
export const isReadOnlyMode = (state: any) => state.app.isReadOnlyMode;
diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.ts
index 31ef2d4c7..749f7d22a 100644
--- a/app/reducers/tagging-actions.ts
+++ b/app/reducers/tagging-actions.ts
@@ -546,49 +546,47 @@ const actions = {
const tagTitlesForRemoving = tags.map(tag => tag.title);
loadMetaDataPromise(path)
.then((fsEntryMeta: TS.FileSystemEntryMeta) => {
- const newTags = [];
- fsEntryMeta.tags.map(sidecarTag => {
- if (!tagTitlesForRemoving.includes(sidecarTag.title)) {
- newTags.push(sidecarTag); // adds only tags which are not in the tags for removing array
+ const newTags = fsEntryMeta.tags.filter(
+ sidecarTag => !tagTitlesForRemoving.includes(sidecarTag.title)
+ );
+
+ removeTagsFromFilename(fsEntryMeta.isFile).then(newFilePath => {
+ // no file rename - only sidecar tags removed
+ if (newFilePath === path) {
+ const updatedFsEntryMeta = {
+ ...fsEntryMeta,
+ tags: newTags
+ };
+ saveMetaDataPromise(path, updatedFsEntryMeta)
+ .then(() => {
+ dispatch(
+ AppActions.reflectUpdateSidecarTags(newFilePath, newTags)
+ );
+ return true;
+ })
+ .catch(err => {
+ console.warn(
+ 'Removing sidecar tags failed ' + path + ' with ' + err
+ );
+ dispatch(
+ AppActions.showNotification(
+ i18n.t('core:removingSidecarTagsFailed'),
+ 'error',
+ true
+ )
+ );
+ });
}
- return true;
- });
- const updatedFsEntryMeta = {
- ...fsEntryMeta,
- tags: newTags
- };
- saveMetaDataPromise(path, updatedFsEntryMeta)
- .then(() => {
- // TODO rethink this updateCurrentDirEntry and not need for KanBan
- dispatch(AppActions.reflectUpdateSidecarTags(path, newTags));
- const { openedFiles } = getState().app;
- if (openedFiles.find(obj => obj.path === path)) {
- dispatch(
- AppActions.updateOpenedFile(path, {
- tags: newTags
- })
- );
- }
- if (fsEntryMeta.isFile) {
- removeTagsFromFilename();
- }
- return true;
- })
- .catch(err => {
- console.warn(
- 'Removing sidecar tags failed ' + path + ' with ' + err
- );
+ // dispatch(AppActions.reflectEditedEntryPaths([newFilePath]));
+ const { openedFiles } = getState().app;
+ if (openedFiles.find(obj => obj.path === path)) {
dispatch(
- AppActions.showNotification(
- i18n.t('core:removingSidecarTagsFailed'),
- 'error',
- true
- )
+ AppActions.updateOpenedFile(path, {
+ tags: newTags
+ })
);
- if (fsEntryMeta.isFile) {
- removeTagsFromFilename();
- }
- });
+ }
+ });
return true;
})
.catch(error => {
@@ -597,37 +595,48 @@ const actions = {
removeTagsFromFilename();
});
- function removeTagsFromFilename() {
- const extractedTags = extractTags(
- path,
- settings.tagDelimiter,
- PlatformIO.getDirSeparator()
- );
- if (extractedTags.length > 0) {
- const fileName = extractFileName(path, PlatformIO.getDirSeparator());
- const containingDirectoryPath = extractContainingDirectoryPath(
+ /**
+ * return new file path
+ * @param isFile
+ */
+ function removeTagsFromFilename(isFile: boolean = true): Promise<string> {
+ if (!isFile) {
+ return Promise.resolve(path);
+ }
+ return new Promise(async resolve => {
+ const extractedTags = extractTags(
path,
+ settings.tagDelimiter,
PlatformIO.getDirSeparator()
);
- for (let i = 0; i < tagTitlesForRemoving.length; i += 1) {
- const tagLoc = extractedTags.indexOf(tagTitlesForRemoving[i]);
- if (tagLoc < 0) {
- console.log(
- 'The tag cannot be removed because it is not part of the file name.'
- );
- } else {
- extractedTags.splice(tagLoc, 1);
+ if (extractedTags.length > 0) {
+ const fileName = extractFileName(path, PlatformIO.getDirSeparator());
+ const containingDirectoryPath = extractContainingDirectoryPath(
+ path,
+ PlatformIO.getDirSeparator()
+ );
+ for (let i = 0; i < tagTitlesForRemoving.length; i += 1) {
+ const tagLoc = extractedTags.indexOf(tagTitlesForRemoving[i]);
+ if (tagLoc < 0) {
+ console.log(
+ 'The tag cannot be removed because it is not part of the file name.'
+ );
+ } else {
+ extractedTags.splice(tagLoc, 1);
+ }
}
+ const newFilePath =
+ (containingDirectoryPath
+ ? containingDirectoryPath + PlatformIO.getDirSeparator()
+ : '') +
+ generateFileName(fileName, extractedTags, settings.tagDelimiter);
+ if (path !== newFilePath) {
+ await dispatch(AppActions.renameFile(path, newFilePath));
+ }
+ resolve(newFilePath);
}
- const newFilePath =
- (containingDirectoryPath
- ? containingDirectoryPath + PlatformIO.getDirSeparator()
- : '') +
- generateFileName(fileName, extractedTags, settings.tagDelimiter);
- if (path !== newFilePath) {
- dispatch(AppActions.renameFile(path, newFilePath));
- }
- }
+ resolve(path);
+ });
}
},
removeAllTags: (paths: Array<string>) => async (
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 96594f935..0121cd4e5 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -64,6 +64,8 @@ import {
} from '-/services/thumbsgenerator';
import { defaultSettings } from '-/perspectives/grid-perspective';
import { base64ToArrayBuffer } from '-/utils/dom';
+import { Simulate } from 'react-dom/test-utils';
+import error = Simulate.error;
const supportedImgsWS = [
'jpg',
@@ -629,17 +631,15 @@ export function deleteFilesPromise(filePathList: Array<string>) {
export function renameFilesPromise(renameJobs: Array<Array<string>>) {
return Promise.all(
- renameJobs.map(renameJob =>
- PlatformIO.renameFilePromise(renameJob[0], renameJob[1])
- )
+ renameJobs.map(async renameJob => {
+ try {
+ return await PlatformIO.renameFilePromise(renameJob[0], renameJob[1]);
+ } catch (err) {
+ console.warn('Error rename file:', err);
+ return false;
+ }
+ })
);
- /* const fileRenamePromises = [];
- renameJobs.forEach(renameJob => {
- fileRenamePromises.push(
- PlatformIO.renameFilePromise(renameJob[0], renameJob[1])
- );
- });
- return Promise.all(fileRenamePromises); */
}
export function copyFilesPromise(copyJobs: Array<Array<string>>) {