TagSpaces is an offline, open source, document manager with tagging support
add DirectoryMenuContextProvider (#2282)
Stanimir8f9cb7e1ab7d
diff --git a/package-lock.json b/package-lock.jsonindex 709606a23..4559be462 100644--- a/package-lock.json+++ b/package-lock.json@@ -206,7 +206,7 @@"yarn": "please-use-npm"},"optionalDependencies": {- "@tagspacespro/tagspacespro": "5.0.136"+ "@tagspacespro/tagspacespro": "5.0.145-alpha.0"}},"node_modules/@adobe/css-tools": {@@ -19925,9 +19925,9 @@}},"node_modules/@tagspacespro/tagspacespro": {- "version": "5.0.136",- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.136/4386a9469937e17f664c811a4db5f31272996886",- "integrity": "sha512-uOL2SS/WSbS4NLLmcRh6AuxcB4dN4hSdomCDhcMiG5PvSAsWsVt/Vh/6fKQ8rFXpSHW+ek2Ec29Dhhu+0748xw==",+ "version": "5.0.145-alpha.0",+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.145-alpha.0/77f7cb586e85c04957934e01692565a642a90e19",+ "integrity": "sha512-99sGzHuXsybNgIjn62u0oZ5s7+xhucc5LMmtGJ6iX3D9ZYOdcp/Fzqtx2O83lIFo4Fr/oornEwGWXWnp1qHyEg==","license": "Proprietary","optional": true},diff --git a/package.json b/package.jsonindex a25bbea00..e95224a32 100644--- a/package.json+++ b/package.json@@ -245,7 +245,7 @@"zod-to-json-schema": "^3.24.1"},"optionalDependencies": {- "@tagspacespro/tagspacespro": "5.0.144"+ "@tagspacespro/tagspacespro": "5.0.145-alpha.0"},"devDependencies": {"@electron/notarize": "^2.5.0",diff --git a/src/renderer/components/DirectoryListView.tsx b/src/renderer/components/DirectoryListView.tsxindex f0a357c70..9430b1015 100644--- a/src/renderer/components/DirectoryListView.tsx+++ b/src/renderer/components/DirectoryListView.tsx@@ -67,7 +67,7 @@ function DirectoryListView(props: Props) {function getDirLocations() {const chosenLocation = findLocation(chosenLocationId.current);- if (chosenLocation.type !== locationType.TYPE_LOCAL) {+ if (!chosenLocation || chosenLocation.type !== locationType.TYPE_LOCAL) {return null;}return (diff --git a/src/renderer/components/EntryProperties.tsx b/src/renderer/components/EntryProperties.tsxindex 389c459d4..706bd218c 100644--- a/src/renderer/components/EntryProperties.tsx+++ b/src/renderer/components/EntryProperties.tsx@@ -104,6 +104,7 @@ import {} from 'react-leaflet';import { useSelector } from 'react-redux';import { Pro } from '../pro';+import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';const ThumbnailTextField = styled(TsTextField)(({ theme }) => ({[`& .${inputBaseClasses.root}`]: {@@ -160,9 +161,10 @@ const defaultBackgrounds = [function EntryProperties(props: Props) {const { t } = useTranslation();const theme = useTheme();- const desktopMode = useSelector(isDesktopMode);+ //const desktopMode = useSelector(isDesktopMode);const { openedEntry, sharingLink, getOpenedDirProps } =useOpenedEntryContext();+ const { openMoveCopyFilesDialog } = useMenuContext();const { isEditMode } = useFilePropertiesContext();const {renameDirectory,@@ -199,8 +201,6 @@ function EntryProperties(props: Props) {: '';const [editName, setEditName] = useState<string>(undefined);- const [isMoveCopyFilesDialogOpened, setMoveCopyFilesDialogOpened] =- useState<boolean>(false);const [isConfirmResetColorDialogOpened, setConfirmResetColorDialogOpened] =useState<boolean>(false);/* const [isFileThumbChooseDialogOpened, setFileThumbChooseDialogOpened] =@@ -334,7 +334,15 @@ function EntryProperties(props: Props) {};const toggleMoveCopyFilesDialog = () => {- setMoveCopyFilesDialogOpened(!isMoveCopyFilesDialogOpened);+ openMoveCopyFilesDialog([+ {+ ...openedEntry,+ isFile: openedEntry.isFile,+ name: entryName,+ tags: [],+ },+ ]);+ //setMoveCopyFilesDialogOpened(!isMoveCopyFilesDialogOpened);};const openThumbFilesDialog = () => {@@ -1159,7 +1167,7 @@ function EntryProperties(props: Props) {confirmDialogContentTID="confirmResetColorDialogContent"/>)}- {isMoveCopyFilesDialogOpened && (+ {/*{isMoveCopyFilesDialogOpened && (<MoveCopyFilesDialogkey={getUuid()}open={isMoveCopyFilesDialogOpened}@@ -1173,7 +1181,7 @@ function EntryProperties(props: Props) {},]}/>- )}+ )}*/}{/*{ThumbnailChooserDialog && (<ThumbnailChooserDialogopen={isFileThumbChooseDialogOpened}diff --git a/src/renderer/components/FolderContainer.tsx b/src/renderer/components/FolderContainer.tsxindex af795e4a2..c86dfac2f 100644--- a/src/renderer/components/FolderContainer.tsx+++ b/src/renderer/components/FolderContainer.tsx@@ -85,20 +85,12 @@ function FolderContainer(props: Props) {isSearchMode,} = useDirectoryContentContext();- const [isRenameEntryDialogOpened, setRenameEntryDialogOpened] =- useState<boolean>(false);-const isDesktopMode = useSelector(getDesktopMode);const progress = useSelector(getProgress);const showWelcomePanel =!currentDirectoryPath && currentDirectoryEntries.length < 1;- const openRenameEntryDialog = useCallback(- () => setRenameEntryDialogOpened(true),- [],- );-function CircularProgressWithLabel(prop) {return (<Box position="relative" display="inline-flex">@@ -325,7 +317,6 @@ function FolderContainer(props: Props) {<PathBreadcrumbsswitchPerspective={switchPerspective}isDesktopMode={isDesktopMode}- openRenameDirectoryDialog={() => setRenameEntryDialogOpened(true)}/></>)}@@ -334,13 +325,7 @@ function FolderContainer(props: Props) {{/*<LoadingAnimation />*/}{/* eslint-disable-next-line jsx-a11y/anchor-has-content,jsx-a11y/anchor-is-valid */}<a href="#" id="downloadFile" />- <RenderPerspective openRenameEntryDialog={openRenameEntryDialog} />- {isRenameEntryDialogOpened && (- <RenameEntryDialog- open={isRenameEntryDialogOpened}- onClose={() => setRenameEntryDialogOpened(false)}- />- )}+ <RenderPerspective /></div>{isDesktopMode && (<ToggleButtonGroupdiff --git a/src/renderer/components/PathBreadcrumbs.tsx b/src/renderer/components/PathBreadcrumbs.tsxindex ceb2038d4..a40aca537 100644--- a/src/renderer/components/PathBreadcrumbs.tsx+++ b/src/renderer/components/PathBreadcrumbs.tsx@@ -16,6 +16,7 @@**/+import React from 'react';import AppConfig from '-/AppConfig';import {CloudLocationIcon,@@ -34,9 +35,8 @@ import {extractShortDirectoryName,normalizePath,} from '@tagspaces/tagspaces-common/paths';-import React, { useState } from 'react';import { useTranslation } from 'react-i18next';-import DirectoryMenu from './menus/DirectoryMenu';+import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';const StyledBreadcrumb = styled(Chip)(({ theme }) => {const backgroundColor =@@ -76,32 +76,24 @@ const StyledBreadcrumbs = styled(Breadcrumbs)(({ theme }) => {interface Props {switchPerspective: (perspectiveId: string) => void;- openRenameDirectoryDialog: () => void;isDesktopMode: boolean;}function PathBreadcrumbs(props: Props) {const { t } = useTranslation();+ const { openDirectoryMenu } = useMenuContext();const { openDirectory, currentDirectoryPath } = useDirectoryContentContext();const { findLocation } = useCurrentLocationContext();const { setSelectedEntries } = useSelectedEntriesContext();const currentLocation = findLocation();let pathParts: Array<string> = [];- const [directoryContextMenuAnchorEl, setDirectoryContextMenuAnchorEl] =- useState<null | HTMLElement>(null);+ const { isDesktopMode } = props;- const { openRenameDirectoryDialog, isDesktopMode } = props;-- const openDirectoryMenu = (event: React.MouseEvent<Element, MouseEvent>) => {+ const openDirMenu = (event: React.MouseEvent<Element, MouseEvent>) => {event.preventDefault();setSelectedEntries([]);- // @ts-ignore- setDirectoryContextMenuAnchorEl(event.currentTarget);- };-- const closeDirectoryMenu = () => {- setDirectoryContextMenuAnchorEl(null);+ openDirectoryMenu(event, currentDirectoryPath, false, true);};const normalizedCurrentDirPath = currentDirectoryPath@@ -199,9 +191,9 @@ function PathBreadcrumbs(props: Props) {label={currentFolderName}icon={currentFolderChipIcon}deleteIcon={<MoreMenuIcon />}- onDelete={openDirectoryMenu}- onClick={openDirectoryMenu}- onContextMenu={openDirectoryMenu}+ onDelete={openDirMenu}+ onClick={openDirMenu}+ onContextMenu={openDirMenu}style={{ marginRight: 2 }}/></Tooltip>@@ -237,7 +229,7 @@ function PathBreadcrumbs(props: Props) {>{getBreadcrumbs()}</StyledBreadcrumbs>- <DirectoryMenu+ {/*<DirectoryMenuopen={Boolean(directoryContextMenuAnchorEl)}onClose={closeDirectoryMenu}anchorEl={directoryContextMenuAnchorEl}@@ -245,7 +237,7 @@ function PathBreadcrumbs(props: Props) {switchPerspectives={true}directoryPath={currentDirectoryPath}openRenameDirectoryDialog={openRenameDirectoryDialog}- />+ />*/}</>);}diff --git a/src/renderer/components/RenderPerspective.tsx b/src/renderer/components/RenderPerspective.tsxindex 3d1f9791a..e4748ac04 100644--- a/src/renderer/components/RenderPerspective.tsx+++ b/src/renderer/components/RenderPerspective.tsx@@ -150,12 +150,9 @@ function WelcomePanelAsync(props) {);}-interface Props {- openRenameEntryDialog: () => void;-}+interface Props {}function RenderPerspective(props: Props) {- const { openRenameEntryDialog } = props;const { currentLocationId } = useCurrentLocationContext();const { getPerspective } = useDirectoryContentContext();const { metaActions } = useEditedEntryMetaContext();@@ -182,9 +179,7 @@ function RenderPerspective(props: Props) {function getPerspectiveComponent() {const perspective = getPerspective();if (perspective === PerspectiveIDs.LIST) {- return (- <ListPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />- );+ return <ListPerspectiveAsync />;}if (Pro && perspective === PerspectiveIDs.GALLERY) {return <GalleryPerspectiveAsync />;@@ -193,17 +188,13 @@ function RenderPerspective(props: Props) {return <MapiquePerspectiveAsync />;}if (Pro && perspective === PerspectiveIDs.KANBAN) {- return (- <KanBanPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />- );+ return <KanBanPerspectiveAsync />;}if (Pro && perspective === PerspectiveIDs.FOLDERVIZ) {return <FolderVizPerspectiveAsync />;}- return (- <GridPerspectiveAsync openRenameEntryDialog={openRenameEntryDialog} />- );+ return <GridPerspectiveAsync />;}const { FILE } = NativeTypes;return (diff --git a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsxindex 923647a01..47b43c5ec 100644--- a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx+++ b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx@@ -21,7 +21,6 @@ import TsButton from '-/components/TsButton';import TsDialogActions from '-/components/dialogs/components/TsDialogActions';import TsDialogTitle from '-/components/dialogs/components/TsDialogTitle';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';-import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';import { TS } from '-/tagspaces.namespace';import FolderIcon from '@mui/icons-material/FolderOpen';@@ -46,13 +45,12 @@ import TagsSelect from '../TagsSelect';interface Props {open: boolean;onClose: (clearSelection?: boolean) => void;- selected?: TS.FileSystemEntry[];+ selected: TS.FileSystemEntry[];}function AddRemoveTagsDialog(props: Props) {const { t } = useTranslation();- const { selectedEntries } = useSelectedEntriesContext();- const selected = props.selected ? props.selected : selectedEntries;+ const { open, selected } = props;const { findLocation } = useCurrentLocationContext();const { addTagsToFsEntries, removeTags } = useTaggingActionsContext();@@ -127,7 +125,6 @@ function AddRemoveTagsDialog(props: Props) {onCloseDialog(true);};- const { open } = props;const disabledButtons =(!newlyAddedTags && !inputTags.current) ||(newlyAddedTags.length < 1 && inputTags.current.length < 1) ||diff --git a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsxindex c22d717c6..1c6c4608d 100644--- a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx+++ b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx@@ -10,7 +10,6 @@ import { useFileUploadDialogContext } from '-/components/dialogs/hooks/useFileUpimport { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';import { useIOActionsContext } from '-/hooks/useIOActionsContext';-import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';import { actions as AppActions, AppDispatch } from '-/reducers/app';import { getDirProperties } from '-/services/utils-io';import { TS } from '-/tagspaces.namespace';@@ -33,7 +32,7 @@ interface Props {open: boolean;onClose: (clearSelection?: boolean) => void;// force to move/copy different entries from selected- entries?: Array<TS.FileSystemEntry>;+ entries: TS.FileSystemEntry[];}function MoveCopyFilesDialog(props: Props) {@@ -44,7 +43,6 @@ function MoveCopyFilesDialog(props: Props) {const { handleEntryExist, openEntryExistDialog } =useEntryExistDialogContext();const { copyFiles, copyDirs, moveFiles, moveDirs } = useIOActionsContext();- const { selectedEntries } = useSelectedEntriesContext();const { openFileUploadDialog } = useFileUploadDialogContext();const [targetPath, setTargetPath] = useState(@@ -55,26 +53,19 @@ function MoveCopyFilesDialog(props: Props) {const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);const { open, entries, onClose } = props;- const allEntries = useRef<TS.FileSystemEntry[]>(- entries && entries.length > 0 ? entries : selectedEntries,- );const currentLocation = findLocation();- const selectedFiles = allEntries.current- ? allEntries.current- .filter((fsEntry) => fsEntry.isFile)- .map((fsentry) => fsentry.path)+ const selectedFiles = entries+ ? entries.filter((fsEntry) => fsEntry.isFile).map((fsentry) => fsentry.path): [];- const selectedDirs = allEntries.current- ? allEntries.current+ const selectedDirs = entries+ ? entries.filter((fsEntry) => !fsEntry.isFile).map((fsentry) => fsentry.path): [];useEffect(() => {- allEntries.current =- entries && entries.length > 0 ? entries : selectedEntries;// getDirProperties have Electron impl onlyif (selectedDirs.length > 0 &&@@ -161,7 +152,7 @@ function MoveCopyFilesDialog(props: Props) {}function copyMove(copy: boolean) {- handleEntryExist(allEntries.current, targetPath).then((exist) => {+ handleEntryExist(entries, targetPath).then((exist) => {if (exist) {openEntryExistDialog(exist, () => {if (copy) {@@ -209,8 +200,8 @@ function MoveCopyFilesDialog(props: Props) {maxHeight: 200,}}>- {allEntries.current.length > 0 &&- allEntries.current.map((entry) => (+ {entries.length > 0 &&+ entries.map((entry) => (<ListItem title={entry.path} key={entry.path}><ListItemIcon>{entry.isFile ? <FileIcon /> : <FolderIcon />}diff --git a/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsxnew file mode 100644index 000000000..65429125d--- /dev/null+++ b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx@@ -0,0 +1,328 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces GmbH+ *+ * 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, {+ createContext,+ useMemo,+ useReducer,+ useRef,+ useState,+} from 'react';+import { extractContainingDirectoryPath } from '@tagspaces/tagspaces-common/paths';+import LoadingLazy from '-/components/LoadingLazy';+import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';+import { TS } from '-/tagspaces.namespace';+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';++type MenuContextData = {+ openMenu: (+ event: MouseEvent | React.MouseEvent<Element, MouseEvent>,+ entry: TS.FileSystemEntry,+ ) => void;+ openDirectoryMenu: (+ event: MouseEvent | React.MouseEvent<Element, MouseEvent>,+ dirPath: string,+ mode?: boolean,+ perspectives?: boolean,+ items?: React.ReactNode,+ ) => void;+ openFileMenu: (+ event: MouseEvent | React.MouseEvent<Element, MouseEvent>,+ dirPath: string,+ openShareFiles?: () => void,+ ) => void;+ // setMousePosition: (x: number, y: number) => void;+ closeDirectoryMenu: () => void;+ openRenameEntryDialog: () => void;+ closeRenameEntryDialog: () => void;+ openMoveCopyFilesDialog: (entries?: TS.FileSystemEntry[]) => void;+ closeMoveCopyFilesDialog: () => void;+ openAddRemoveTagsDialog: (entries?: TS.FileSystemEntry[]) => void;+ closeAddRemoveTagsDialog: () => void;+};++export const MenuContext = createContext<MenuContextData>({+ openMenu: undefined,+ openDirectoryMenu: undefined,+ openFileMenu: undefined,+ closeDirectoryMenu: undefined,+ openRenameEntryDialog: undefined,+ closeRenameEntryDialog: undefined,+ openMoveCopyFilesDialog: undefined,+ closeMoveCopyFilesDialog: undefined,+ openAddRemoveTagsDialog: undefined,+ closeAddRemoveTagsDialog: undefined,+});++export type MenuContextProviderProps = {+ children: React.ReactNode;+};++const DirectoryMenu = React.lazy(+ () =>+ import(/* webpackChunkName: "DirectoryMenu" */ '../../menus/DirectoryMenu'),+);+const FileMenu = React.lazy(+ () => import(/* webpackChunkName: "FileMenu" */ '../../menus/FileMenu'),+);+const RenameEntryDialog = React.lazy(+ () =>+ import(+ /* webpackChunkName: "RenameEntryDialog" */ '../../dialogs/RenameEntryDialog'+ ),+);+const MoveCopyFilesDialog = React.lazy(+ () =>+ import(+ /* webpackChunkName: "MoveCopyFilesDialog" */ '../../dialogs/MoveCopyFilesDialog'+ ),+);+const AddRemoveTagsDialog = React.lazy(+ () =>+ import(+ /* webpackChunkName: "AddRemoveTagsDialog" */ '../../dialogs/AddRemoveTagsDialog'+ ),+);++export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {+ const { findLocation } = useCurrentLocationContext();+ const { setSelectedEntries, selectedEntries } = useSelectedEntriesContext();+ const [directoryContextMenuAnchorEl, setDirectoryContextMenuAnchorEl] =+ useState<null | HTMLElement>(null);+ const [fileContextMenuAnchorEl, setFileContextMenuAnchorEl] =+ useState<null | HTMLElement>(null);+ const currentEntries = useRef<TS.FileSystemEntry[]>(undefined);+ const openRenameEntry = useRef<boolean>(false);+ const openMoveCopyFiles = useRef<boolean>(false);+ const openAddRemoveTags = useRef<boolean>(false);+ const perspectiveMode = useRef<boolean>(false);+ const switchPerspectives = useRef<boolean>(false);+ const directoryPath = useRef<string>(undefined);+ const mouseX = useRef<number>(undefined);+ const mouseY = useRef<number>(undefined);+ const openShareFilesDialog = useRef<() => void>(undefined);+ const reorderTop = useRef<() => void>(undefined);+ const reorderBottom = useRef<() => void>(undefined);+ const menuItems = useRef<React.ReactNode>(undefined);++ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);++ const openMenu = (+ event: MouseEvent | React.MouseEvent<Element, MouseEvent>,+ entry: TS.FileSystemEntry,+ ) => {+ if (entry) {+ if (entry.isFile) {+ const currentLocation = findLocation(entry.locationID);+ const dirPath = extractContainingDirectoryPath(+ entry.path,+ currentLocation?.getDirSeparator(),+ );+ openFileMenu(event, dirPath);+ } else {+ openDirectoryMenu(event, entry.path, true);+ }+ }+ };++ const openDirectoryMenu = (+ event: MouseEvent | React.MouseEvent<Element, MouseEvent>,+ dirPath: string,+ mode?: boolean,+ perspectives?: boolean,+ items?: React.ReactNode,+ ) => {+ event.preventDefault();+ directoryPath.current = dirPath;+ mouseX.current = event.clientX;+ mouseY.current = event.clientY;+ perspectiveMode.current = mode;+ switchPerspectives.current = perspectives;+ menuItems.current = items;+ // @ts-ignore+ setDirectoryContextMenuAnchorEl(event.currentTarget);+ };++ const closeDirectoryMenu = () => {+ directoryPath.current = undefined;+ mouseX.current = undefined;+ mouseY.current = undefined;+ perspectiveMode.current = false;+ switchPerspectives.current = false;+ menuItems.current = undefined;+ setDirectoryContextMenuAnchorEl(null);+ };++ const openFileMenu = (+ event: MouseEvent | React.MouseEvent<Element, MouseEvent>,+ dirPath: string,+ openShareFiles?: () => void,+ orderTop?: () => void,+ orderBottom?: () => void,+ ) => {+ event.preventDefault();+ directoryPath.current = dirPath;+ mouseX.current = event.clientX;+ mouseY.current = event.clientY;+ openShareFilesDialog.current = openShareFiles;+ reorderTop.current = orderTop;+ reorderBottom.current = orderBottom;+ // @ts-ignore+ setFileContextMenuAnchorEl(event.currentTarget);+ };++ const closeFileMenu = () => {+ directoryPath.current = undefined;+ mouseX.current = undefined;+ mouseY.current = undefined;+ setFileContextMenuAnchorEl(null);+ };++ /* const setMousePosition = (x: number, y: number) => {+ mouseX.current = x;+ mouseY.current = y;+ };*/+ const openRenameEntryDialog = () => {+ openRenameEntry.current = true;+ forceUpdate();+ };++ const openMoveCopyFilesDialog = (entries?: TS.FileSystemEntry[]) => {+ openMoveCopyFiles.current = true;+ currentEntries.current = entries;+ forceUpdate();+ };++ const openAddRemoveTagsDialog = (entries?: TS.FileSystemEntry[]) => {+ openAddRemoveTags.current = true;+ currentEntries.current = entries;+ forceUpdate();+ };++ const closeRenameEntryDialog = () => {+ openRenameEntry.current = false;+ forceUpdate();+ };+ const closeMoveCopyFilesDialog = () => {+ openMoveCopyFiles.current = false;+ forceUpdate();+ };+ const closeAddRemoveTagsDialog = () => {+ openAddRemoveTags.current = false;+ forceUpdate();+ };++ function DirectoryMenuAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <DirectoryMenu {...props} />+ </React.Suspense>+ );+ }+ function FileMenuAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <FileMenu {...props} />+ </React.Suspense>+ );+ }+ function RenameEntryDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <RenameEntryDialog {...props} />+ </React.Suspense>+ );+ }+ function MoveCopyFilesDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <MoveCopyFilesDialog {...props} />+ </React.Suspense>+ );+ }+ function AddRemoveTagsDialogAsync(props) {+ return (+ <React.Suspense fallback={<LoadingLazy />}>+ <AddRemoveTagsDialog {...props} />+ </React.Suspense>+ );+ }++ const context = useMemo(() => {+ return {+ openMenu,+ openDirectoryMenu,+ closeDirectoryMenu,+ openFileMenu,+ closeFileMenu,+ //setMousePosition,+ openRenameEntryDialog,+ closeRenameEntryDialog,+ openMoveCopyFilesDialog,+ closeMoveCopyFilesDialog,+ openAddRemoveTagsDialog,+ closeAddRemoveTagsDialog,+ };+ }, []);++ return (+ <MenuContext.Provider value={context}>+ <RenameEntryDialogAsync+ open={openRenameEntry.current}+ onClose={closeRenameEntryDialog}+ />+ <MoveCopyFilesDialogAsync+ open={openMoveCopyFiles.current}+ onClose={closeMoveCopyFilesDialog}+ entries={+ currentEntries.current ? currentEntries.current : selectedEntries+ }+ />+ <AddRemoveTagsDialogAsync+ open={openAddRemoveTags.current}+ onClose={closeAddRemoveTagsDialog}+ selected={+ currentEntries.current ? currentEntries.current : selectedEntries+ }+ />+ <DirectoryMenuAsync+ open={Boolean(directoryContextMenuAnchorEl)}+ onClose={() => closeDirectoryMenu()}+ anchorEl={directoryContextMenuAnchorEl}+ perspectiveMode={perspectiveMode.current}+ switchPerspectives={switchPerspectives.current}+ directoryPath={directoryPath.current}+ mouseX={mouseX.current}+ mouseY={mouseY.current}+ openRenameDirectoryDialog={openRenameEntryDialog}+ />+ <FileMenuAsync+ open={Boolean(fileContextMenuAnchorEl)}+ onClose={() => closeFileMenu()}+ anchorEl={fileContextMenuAnchorEl}+ selectedFilePath={directoryPath.current}+ mouseX={mouseX.current}+ mouseY={mouseY.current}+ openShareFilesDialog={openShareFilesDialog}+ reorderTop={reorderTop.current}+ reorderBottom={reorderBottom.current}+ />+ {children}+ </MenuContext.Provider>+ );+};diff --git a/src/renderer/components/dialogs/hooks/useMenuContext.tsx b/src/renderer/components/dialogs/hooks/useMenuContext.tsxnew file mode 100644index 000000000..adb6150eb--- /dev/null+++ b/src/renderer/components/dialogs/hooks/useMenuContext.tsx@@ -0,0 +1,5 @@+import { useContext } from 'react';++import { MenuContext } from '-/components/dialogs/hooks/MenuContextProvider';++export const useMenuContext = () => useContext(MenuContext);diff --git a/src/renderer/components/menus/DirectoryMenu.tsx b/src/renderer/components/menus/DirectoryMenu.tsxindex cdac06cd6..ce43255c9 100644--- a/src/renderer/components/menus/DirectoryMenu.tsx+++ b/src/renderer/components/menus/DirectoryMenu.tsx@@ -58,6 +58,7 @@ import { useProTeaserDialogContext } from '-/components/dialogs/hooks/useProTeasimport { useDeleteMultipleEntriesDialogContext } from '-/components/dialogs/hooks/useDeleteMultipleEntriesDialogContext';import { useFileUploadContext } from '-/hooks/useFileUploadContext';import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';+import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';interface Props {open: boolean;@@ -65,19 +66,21 @@ interface Props {onClose: (param?: any) => void;anchorEl?: Element;items?: React.ReactNode;- directoryPath: string;- openAddRemoveTagsDialog?: () => void;+ directoryPath?: string;switchPerspective?: (perspectiveId: string) => void;perspectiveMode?: boolean;switchPerspectives?: boolean;- openRenameDirectoryDialog?: () => void;- openMoveCopyFilesDialog?: () => void;mouseX?: number;mouseY?: number;}function DirectoryMenu(props: Props) {const { t } = useTranslation();+ const {+ openAddRemoveTagsDialog,+ openMoveCopyFilesDialog,+ openRenameEntryDialog,+ } = useMenuContext();const { openEntry } = useOpenedEntryContext();const { selectedEntries, setSelectedEntries } = useSelectedEntriesContext();const { addTags } = useTaggingActionsContext();@@ -123,9 +126,6 @@ function DirectoryMenu(props: Props) {mouseX,mouseY,items,- openAddRemoveTagsDialog,- openMoveCopyFilesDialog,- openRenameDirectoryDialog,switchPerspective,perspectiveMode,switchPerspectives,@@ -146,19 +146,17 @@ function DirectoryMenu(props: Props) {return getLocationPath(tmpLoc).then((locationPath) => {const relativePath = getRelativeEntryPath(locationPath, entryPath);const folderName = extractDirectoryName(- selectedEntries[0].name,+ selectedEntries[0] ? selectedEntries[0].name : currentDirectoryPath,currentLocation?.getDirSeparator(),);- return getMetadataID(- selectedEntries[0].path,- selectedEntries[0].uuid,- tmpLoc,- ).then((id) => {- return {- url: generateSharingLink(locationID, undefined, relativePath, id),- name: folderName,- };- });+ return getMetadataID(entryPath, selectedEntries[0]?.uuid, tmpLoc).then(+ (id) => {+ return {+ url: generateSharingLink(locationID, undefined, relativePath, id),+ name: folderName,+ };+ },+ );});}@@ -454,14 +452,14 @@ Do you want to continue?`)? items: getDirectoryMenuItems(currentLocation,- selectedEntries.length,+ selectedEntries,perspectiveMode, // lastSelectedEntryPath !== currentDirectoryPath,readOnlyMode,onClose,t,openDir,reloadDirectory,- openRenameDirectoryDialog,+ openRenameEntryDialog,openMoveCopyFilesDialog,showDeleteDirectoryDialog,showInFileManager,diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsxindex 252d78447..5c027a55b 100644--- a/src/renderer/components/menus/FileMenu.tsx+++ b/src/renderer/components/menus/FileMenu.tsx@@ -70,6 +70,7 @@ import {import { useEffect, useReducer, useRef } from 'react';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';+import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';interface Props {anchorEl: Element;@@ -77,14 +78,11 @@ interface Props {mouseY?: number;open: boolean;onClose: () => void;- openRenameFileDialog: () => void;- openMoveCopyFilesDialog: () => void;openShareFilesDialog?: () => void;- openAddRemoveTagsDialog: () => void;/*** @deprecated use selectedEntries instead*/- selectedFilePath?: string;+ // selectedFilePath?: string;reorderTop?: () => void;reorderBottom?: () => void;onDuplicateFile?: (fileDirPath: string) => void;@@ -92,10 +90,7 @@ interface Props {function FileMenu(props: Props) {const {- openRenameFileDialog,- openMoveCopyFilesDialog,openShareFilesDialog,- openAddRemoveTagsDialog,reorderTop,reorderBottom,anchorEl,@@ -103,12 +98,17 @@ function FileMenu(props: Props) {mouseY,open,onClose,- selectedFilePath,+ // selectedFilePath,} = props;const keyBindings = useSelector(getKeyBindingObject);const { t } = useTranslation();- const { selectedEntries } = useSelectedEntriesContext();+ const {+ openAddRemoveTagsDialog,+ openMoveCopyFilesDialog,+ openRenameEntryDialog,+ } = useMenuContext();+ const { selectedEntries, lastSelectedEntry } = useSelectedEntriesContext();const { openDeleteMultipleEntriesDialog } =useDeleteMultipleEntriesDialogContext();const {@@ -132,15 +132,15 @@ function FileMenu(props: Props) {const currentLocation = findLocation();useEffect(() => {- if (currentLocation?.haveObjectStoreSupport()) {+ if (currentLocation?.haveObjectStoreSupport() && lastSelectedEntry) {currentLocation- .generateURLforPath(selectedFilePath, 86400)+ .generateURLforPath(lastSelectedEntry.path, 86400).then((url) => {downloadFileUrl.current = url;forceUpdate();});}- }, [currentLocationId, selectedFilePath]);+ }, [currentLocationId, lastSelectedEntry]);function generateFileLink(): Promise<string> {const entryPath = selectedEntries[0].path;@@ -194,7 +194,7 @@ function FileMenu(props: Props) {function showRenameFileDialog() {onClose();- openRenameFileDialog();+ openRenameEntryDialog();}function showMoveCopyFilesDialog() {@@ -209,11 +209,11 @@ function FileMenu(props: Props) {function setFolderThumbnail() {onClose();- setFolderThumbnailPromise(selectedEntries[0].path) //selectedFilePath)+ setFolderThumbnailPromise(lastSelectedEntry.path).then((thumbPath: string) => {const entry: TS.FileSystemEntry = currentLocation.toFsEntry(extractContainingDirectoryPath(- selectedEntries[0].path,+ lastSelectedEntry.path,currentLocation?.getDirSeparator(),),false,@@ -228,7 +228,7 @@ function FileMenu(props: Props) {.catch((error) => {showNotification('Thumbnail creation failed.');console.log(- 'Error setting Thumb for entry: ' + selectedEntries[0].path,+ 'Error setting Thumb for entry: ' + lastSelectedEntry.path,error,);return true;@@ -243,13 +243,16 @@ function FileMenu(props: Props) {(currentLocation.haveObjectStoreSupport() ||currentLocation.haveWebDavSupport())) {- path = await currentLocation.generateURLforPath(selectedFilePath, 604800); // 7 days+ path = await currentLocation.generateURLforPath(+ lastSelectedEntry.path,+ 604800,+ ); // 7 days} else {- path = selectedFilePath;+ path = lastSelectedEntry.path;}const directoryPath = extractContainingDirectoryPath(- selectedFilePath,+ lastSelectedEntry.path,currentLocation?.getDirSeparator(),);@@ -263,7 +266,7 @@ function FileMenu(props: Props) {.catch((error) => {showNotification('Background creation failed.');console.log(- 'Error setting Background for entry: ' + selectedFilePath,+ 'Error setting Background for entry: ' + lastSelectedEntry.path,error,);return true;@@ -277,14 +280,18 @@ function FileMenu(props: Props) {function duplicateFileHandler() {onClose();- duplicateFile(selectedFilePath);+ duplicateFile(lastSelectedEntry.path);}function openParentFolderInternally() {onClose();- if (selectedFilePath) {+ if (lastSelectedEntry) {+ const directoryPath = extractContainingDirectoryPath(+ lastSelectedEntry.path,+ currentLocation?.getDirSeparator(),+ );const parentFolder = extractParentDirectoryPath(- selectedFilePath,+ directoryPath,currentLocation?.getDirSeparator(),);return openDirectory(parentFolder);@@ -293,8 +300,8 @@ function FileMenu(props: Props) {function openFile() {onClose();- if (selectedFilePath) {- return openEntry(selectedFilePath);+ if (lastSelectedEntry) {+ return openEntry(lastSelectedEntry.path);}}@@ -311,16 +318,16 @@ function FileMenu(props: Props) {function openFileNativelyHandler() {onClose();- if (selectedFilePath) {- openFileNatively(selectedFilePath);+ if (lastSelectedEntry) {+ openFileNatively(lastSelectedEntry.path);}}const menuItems = [];- const pathLowerCase = selectedFilePath.toLowerCase();+ const pathLowerCase = lastSelectedEntry?.path.toLowerCase();const isImageFile = supportedImgs.some((ext) =>- pathLowerCase.endsWith('.' + ext),+ pathLowerCase?.endsWith('.' + ext),);if (selectedEntries.length < 2) {@@ -391,8 +398,8 @@ function FileMenu(props: Props) {data-tid="fileMenuOpenContainingFolder"onClick={() => {onClose();- if (selectedFilePath) {- openDirectoryMessage(selectedFilePath);+ if (lastSelectedEntry) {+ openDirectoryMessage(lastSelectedEntry.path);}}}>diff --git a/src/renderer/containers/DialogsRoot.tsx b/src/renderer/containers/DialogsRoot.tsxindex 5406b0945..bca48cb31 100644--- a/src/renderer/containers/DialogsRoot.tsx+++ b/src/renderer/containers/DialogsRoot.tsx@@ -35,11 +35,9 @@ import { SettingsDialogContextProvider } from '-/components/dialogs/hooks/Settinimport { DeleteMultipleEntriesDialogContextProvider } from '-/components/dialogs/hooks/DeleteMultipleEntriesDialogContextProvider';import { ResolveConflictContextProvider } from '-/components/dialogs/hooks/ResolveConflictContextProvider';import { FileUploadContextProvider } from '-/hooks/FileUploadContextProvider';-import {- DownloadUrlContextProvider,- DownloadUrlDialogContext,-} from '-/components/dialogs/hooks/DownloadUrlDialogContextProvider';+import { DownloadUrlContextProvider } from '-/components/dialogs/hooks/DownloadUrlDialogContextProvider';import { AiGenerationDialogContextProvider } from '-/components/dialogs/hooks/AiGenerationDialogContextProvider';+import { MenuContextProvider } from '-/components/dialogs/hooks/MenuContextProvider';export type DialogsRootProps = {children: React.ReactNode;@@ -67,7 +65,9 @@ function DialogsRoot({ children }: DialogsRootProps) {<SettingsDialogContextProvider><ResolveConflictContextProvider><DownloadUrlContextProvider>- {children}+ <MenuContextProvider>+ {children}+ </MenuContextProvider></DownloadUrlContextProvider></ResolveConflictContextProvider></SettingsDialogContextProvider>diff --git a/src/renderer/hooks/SelectedEntryContextProvider.tsx b/src/renderer/hooks/SelectedEntryContextProvider.tsxindex d93f283da..b5875a5c4 100644--- a/src/renderer/hooks/SelectedEntryContextProvider.tsx+++ b/src/renderer/hooks/SelectedEntryContextProvider.tsx@@ -30,15 +30,17 @@ import useFirstRender from '-/utils/useFirstRender';type SelectedEntryContextData = {selectedEntries: TS.FileSystemEntry[];- lastSelectedEntryPath: string;+ lastSelectedEntry: TS.FileSystemEntry | undefined;setSelectedEntries(entries: TS.FileSystemEntry[]);+ addToSelection(entry: TS.FileSystemEntry);selectEntry(entry: TS.FileSystemEntry, select?: boolean);};export const SelectedEntryContext = createContext<SelectedEntryContextData>({selectedEntries: undefined,- lastSelectedEntryPath: undefined,+ lastSelectedEntry: undefined,setSelectedEntries: undefined,+ addToSelection: undefined,selectEntry: undefined,});@@ -68,6 +70,20 @@ export const SelectedEntryContextProvider = ({}return undefined;}*/+ const addToSelection = (fsEntry: TS.FileSystemEntry) => {+ const entries = selectedEntries.current;++ // If the last entry is the same as fsEntry, do nothing.+ if (entries.length && entries[entries.length - 1].path === fsEntry.path)+ return;++ // Otherwise, remove any previous occurrences of fsEntry and add it at the end.+ setSelectedEntries([+ ...entries.filter((entry) => entry.path !== fsEntry.path),+ fsEntry,+ ]);+ };+const setSelectedEntries = (entries: TS.FileSystemEntry[]) => {selectedEntries.current = entries ? entries : [];forceUpdate();@@ -93,9 +109,9 @@ export const SelectedEntryContextProvider = ({forceUpdate();};- const lastSelectedEntryPath = useMemo(() => {+ const lastSelectedEntry = useMemo(() => {if (selectedEntries.current && selectedEntries.current.length > 0) {- return selectedEntries.current[selectedEntries.current.length - 1].path;+ return selectedEntries.current[selectedEntries.current.length - 1];}return undefined;}, [selectedEntries.current]);@@ -103,8 +119,9 @@ export const SelectedEntryContextProvider = ({const context = useMemo(() => {return {selectedEntries: selectedEntries.current,- lastSelectedEntryPath,+ lastSelectedEntry,setSelectedEntries,+ addToSelection,selectEntry,};}, [selectedEntries.current]);diff --git a/src/renderer/perspectives/common/CellView.tsx b/src/renderer/perspectives/common/CellView.tsxindex 9655d964b..aa9bbea21 100644--- a/src/renderer/perspectives/common/CellView.tsx+++ b/src/renderer/perspectives/common/CellView.tsx@@ -45,6 +45,7 @@ import { useNotificationContext } from '-/hooks/useNotificationContext';import { useEntryExistDialogContext } from '-/components/dialogs/hooks/useEntryExistDialogContext';import i18n from '-/services/i18n';import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';+import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';interface Props {fsEntry: TS.FileSystemEntry;@@ -61,30 +62,27 @@ interface Props {handleGridCellDblClick,isLast?: boolean,) => any;- setFileContextMenuAnchorEl;- setDirContextMenuAnchorEl;isLast?: boolean;}function CellView(props: Props) {- const {- fsEntry,- index,- cellContent,- setFileContextMenuAnchorEl,- setDirContextMenuAnchorEl,- isLast,- } = props;+ const { fsEntry, index, cellContent, isLast } = props;const { showDirectories, singleClickAction } =usePerspectiveSettingsContext();const theme = useTheme();++ const { openMenu } = useMenuContext();const { openEntryInternal, openedEntry } = useOpenedEntryContext();const { openDirectory } = useDirectoryContentContext();const { moveFiles, openFileNatively } = useIOActionsContext();const { readOnlyMode, currentLocationId, findLocation } =useCurrentLocationContext();- const { selectedEntries, setSelectedEntries, lastSelectedEntryPath } =- useSelectedEntriesContext();+ const {+ selectedEntries,+ setSelectedEntries,+ addToSelection,+ lastSelectedEntry,+ } = useSelectedEntriesContext();const { handleEntryExist, openEntryExistDialog } =useEntryExistDialogContext();const { sortedDirContent, nativeDragModeEnabled } = useSortedDirContext();@@ -117,57 +115,21 @@ function CellView(props: Props) {const handleGridContextMenu = (event, fsEntry: TS.FileSystemEntry) => {event.preventDefault();event.stopPropagation();- // setMouseX(event.clientX);- // setMouseY(event.clientY);const isEntryExist = selectedEntries.some((entry) => entry.uuid === fsEntry.uuid,);- if (fsEntry.isFile) {- if (!desktopMode) {- if (!isEntryExist) {- if (selectedEntries.length > 0) {- setSelectedEntries([...selectedEntries, fsEntry]);- } else {- setSelectedEntries([fsEntry]);- }- }- } else if (- selectedEntries.length === 0 ||- !fileOperationsEnabled(selectedEntries)- ) {- setSelectedEntries([fsEntry]);- } else if (event.ctrlKey) {- if (!isEntryExist) {- setSelectedEntries([...selectedEntries, fsEntry]);- }- } else if (isEntryExist) {- // update selected entry- setSelectedEntries([- ...selectedEntries.filter((entry) => entry.uuid !== fsEntry.uuid),- fsEntry,- ]);- } else {- setSelectedEntries([fsEntry]);- }- setFileContextMenuAnchorEl(event.currentTarget);+ if (event.ctrlKey) {+ addToSelection(fsEntry);} else {- if (- selectedEntries.length === 0 ||- !folderOperationsEnabled(selectedEntries)- ) {+ const operationEnabled = fsEntry.isFile+ ? fileOperationsEnabled(selectedEntries)+ : folderOperationsEnabled(selectedEntries);+ if (selectedEntries.length === 0 || !operationEnabled || !isEntryExist) {setSelectedEntries([fsEntry]);- } else if (isEntryExist) {- // update selected entry- setSelectedEntries([- ...selectedEntries.filter((entry) => entry.uuid !== fsEntry.uuid),- fsEntry,- ]);} else {- setSelectedEntries([fsEntry]);- }- if (setDirContextMenuAnchorEl) {- setDirContextMenuAnchorEl(event.currentTarget);+ addToSelection(fsEntry);}+ openMenu(event, fsEntry);}};@@ -191,9 +153,9 @@ function CellView(props: Props) {const selectHelperKey = AppConfig.isMacLike ? event.metaKey : event.ctrlKey;if (event.shiftKey) {let lastSelectedIndex = -1;- if (lastSelectedEntryPath) {+ if (lastSelectedEntry) {lastSelectedIndex = sortedDirContent.findIndex(- (entry) => entry.path === lastSelectedEntryPath,+ (entry) => entry.path === lastSelectedEntry.path,);}const currentSelectedIndex = sortedDirContent.findIndex(diff --git a/src/renderer/perspectives/common/DirectoryMenuItems.tsx b/src/renderer/perspectives/common/DirectoryMenuItems.tsxindex 6ffd03620..847e392a4 100644--- a/src/renderer/perspectives/common/DirectoryMenuItems.tsx+++ b/src/renderer/perspectives/common/DirectoryMenuItems.tsx@@ -38,7 +38,7 @@ import { useSelector } from 'react-redux';export function getDirectoryMenuItems(currentLocation: CommonLocation,- selectedEntriesLength: number,+ selectedEntries: TS.FileSystemEntry[],perspectiveMode: boolean,isReadOnlyMode: boolean,onClose: () => void,@@ -46,7 +46,7 @@ export function getDirectoryMenuItems(openDirectory?: () => void,reloadDirectory?: () => void,showRenameDirectoryDialog?: () => void,- openMoveCopyDialog?: () => void,+ openMoveCopyDialog?: (entries?: TS.FileSystemEntry[]) => void,showDeleteDirectoryDialog?: () => void,showInFileManager?: () => void,createNewFile?: (fileType?: TS.FileType) => void,@@ -66,7 +66,7 @@ export function getDirectoryMenuItems() {const keyBindings = useSelector(getKeyBindingObject);const menuItems = [];- if (selectedEntriesLength < 2) {+ if (selectedEntries.length < 2) {if (perspectiveMode) {if (openDirectory) {menuItems.push(@@ -153,7 +153,7 @@ export function getDirectoryMenuItems(data-tid="fileMenuMoveCopyDirectoryTID"onClick={() => {onClose();- openMoveCopyDialog();+ openMoveCopyDialog(selectedEntries);}}><ListItemIcon>@@ -186,7 +186,7 @@ export function getDirectoryMenuItems(if (currentLocation &&- selectedEntriesLength < 2 &&+ selectedEntries.length < 2 &&!(currentLocation.haveObjectStoreSupport() ||currentLocation.haveWebDavSupport() ||@@ -339,7 +339,7 @@ export function getDirectoryMenuItems();}}- if (Pro && !isReadOnlyMode && selectedEntriesLength < 2) {+ if (Pro && !isReadOnlyMode && selectedEntries.length < 2) {if (setFolderThumbnail && perspectiveMode) {menuItems.push(<MenuItem@@ -392,7 +392,7 @@ export function getDirectoryMenuItems();}}- if (selectedEntriesLength === 1 && copySharingLink) {+ if (selectedEntries.length === 1 && copySharingLink) {menuItems.push(<MenuItemkey="copySharingLink"@@ -430,7 +430,7 @@ export function getDirectoryMenuItems(}if (- selectedEntriesLength < 2 &&+ selectedEntries.length < 2 &&AppConfig.isElectron &&AppConfig.isMacLike &&importMacTags@@ -511,7 +511,7 @@ export function getDirectoryMenuItems(});}- if (selectedEntriesLength < 2 && showProperties) {+ if (selectedEntries.length < 2 && showProperties) {menuItems.push(<Divider key="divider4" />);menuItems.push(<MenuItemdiff --git a/src/renderer/perspectives/common/main-container.tsx b/src/renderer/perspectives/common/main-container.tsxindex 40e1d741a..76b33251a 100644--- a/src/renderer/perspectives/common/main-container.tsx+++ b/src/renderer/perspectives/common/main-container.tsx@@ -1,13 +1,5 @@-import { TS } from '-/tagspaces.namespace';-import FileSourceDnd from '-/components/FileSourceDnd';-import TargetMoveFileBox from '-/components/TargetMoveFileBox';-import DragItemTypes from '-/components/DragItemTypes';import React from 'react';-import AppConfig from '-/AppConfig';import TagDropContainer from '-/components/TagDropContainer';-import CustomDragLayer from '-/components/CustomDragLayer';-import TargetFileBox from '-/components/TargetFileBox';-import { NativeTypes } from 'react-dnd-html5-backend';export const fileOperationsEnabled = (selectedEntries) => {let selectionContainsDirectories = false;@@ -30,290 +22,6 @@ export const folderOperationsEnabled = (selectedEntries) => {return !selectionContainsFiles;};-/*export const renderCell = (- fsEntry: TS.FileSystemEntry,- index: number,- cellContent: (- fsEntry: TS.FileSystemEntry,- selectedEntries: Array<TS.FileSystemEntry>,- index: number,- handleGridContextMenu: (- event: React.MouseEvent<HTMLDivElement>,- fsEntry: TS.FileSystemEntry,- ) => void,- handleGridCellClick,- handleGridCellDblClick,- isLast?: boolean,- ) => any,- showDirectories: boolean,- isReadOnlyMode: boolean,- desktopMode: boolean,- singleClickAction: string,- currentLocation,- selectedEntries,- setSelectedEntries,- lastSelectedEntryPath,- directoryContent,- openEntryInternal,- openFileNatively,- openDirectory,- setFileContextMenuAnchorEl,- setDirContextMenuAnchorEl,- showNotification: (- text: string,- notificationType: string,- autohide: boolean,- ) => void,- moveFiles: (- files: Array<string>,- destination: string,- locationID: string,- onProgress?,- reflect?: boolean,- ) => Promise<boolean>,- handleEntryExist,- openEntryExistDialog,- clearSelection: () => void,- isLast?: boolean,-) => {- if (!fsEntry.isFile && !showDirectories) {- return;- }-- const handleGridContextMenu = (event, fsEntry: TS.FileSystemEntry) => {- event.preventDefault();- event.stopPropagation();- // setMouseX(event.clientX);- // setMouseY(event.clientY);- const isEntryExist = selectedEntries.some(- (entry) => entry.uuid === fsEntry.uuid,- );- if (fsEntry.isFile) {- if (!desktopMode) {- if (!isEntryExist) {- if (selectedEntries.length > 0) {- setSelectedEntries([...selectedEntries, fsEntry]);- } else {- setSelectedEntries([fsEntry]);- }- }- } else if (- selectedEntries.length === 0 ||- !fileOperationsEnabled(selectedEntries)- ) {- setSelectedEntries([fsEntry]);- } else if (event.ctrlKey) {- if (!isEntryExist) {- setSelectedEntries([...selectedEntries, fsEntry]);- }- } else if (isEntryExist) {- // update selected entry- setSelectedEntries([- ...selectedEntries.filter((entry) => entry.uuid !== fsEntry.uuid),- fsEntry,- ]);- } else {- setSelectedEntries([fsEntry]);- }- setFileContextMenuAnchorEl(event.currentTarget);- } else {- if (- selectedEntries.length === 0 ||- !folderOperationsEnabled(selectedEntries)- ) {- setSelectedEntries([fsEntry]);- } else if (isEntryExist) {- // update selected entry- setSelectedEntries([- ...selectedEntries.filter((entry) => entry.uuid !== fsEntry.uuid),- fsEntry,- ]);- } else {- setSelectedEntries([fsEntry]);- }- if (setDirContextMenuAnchorEl) {- setDirContextMenuAnchorEl(event.currentTarget);- }- }- };-- const openLocation = (fsEntry: TS.FileSystemEntry) => {- if (fsEntry.isFile) {- setSelectedEntries([fsEntry]);- openEntryInternal(fsEntry);- //openEntry(fsEntry.path);- } else {- console.log('Handle Grid cell db click, selected path : ', fsEntry.path);- openDirectory(fsEntry.path);- }- };-- const handleGridCellDblClick = (event, fsEntry: TS.FileSystemEntry) => {- setSelectedEntries([]);- openLocation(fsEntry);- };-- const handleGridCellClick = (event, fsEntry: TS.FileSystemEntry) => {- /!*const {- selectedEntries,- directoryContent,- lastSelectedEntry,- setSelectedEntries- } = props;*!/- const selectHelperKey = AppConfig.isMacLike ? event.metaKey : event.ctrlKey;- if (event.shiftKey) {- let lastSelectedIndex = -1;- if (lastSelectedEntryPath) {- lastSelectedIndex = directoryContent.findIndex(- (entry) => entry.path === lastSelectedEntryPath,- );- }- const currentSelectedIndex = directoryContent.findIndex(- (entry) => entry.path === fsEntry.path,- );- if (lastSelectedIndex < 0) {- lastSelectedIndex = currentSelectedIndex;- }-- let entriesToSelect;- // console.log('lastSelectedIndex: ' + lastSelectedIndex + ' currentSelectedIndex: ' + currentSelectedIndex);- if (currentSelectedIndex > lastSelectedIndex) {- entriesToSelect = directoryContent.slice(- lastSelectedIndex,- currentSelectedIndex + 1,- );- } else if (currentSelectedIndex < lastSelectedIndex) {- entriesToSelect = directoryContent- .slice(currentSelectedIndex, lastSelectedIndex + 1)- .reverse();- } else if (currentSelectedIndex === lastSelectedIndex) {- entriesToSelect = [fsEntry];- }-- setSelectedEntries(entriesToSelect);- } else if (event.type === 'drag') {- if (- selectedEntries &&- selectedEntries.some((entry) => entry.path === fsEntry.path)- ) {- } else {- const currentSelectedEntry = directoryContent.find(- (entry) => entry.path === fsEntry.path,- );- if (currentSelectedEntry) {- // in KanBan directoryContent not content dragging entry from subfolder- setSelectedEntries([currentSelectedEntry]);- }- }- } else if (selectHelperKey) {- if (- selectedEntries &&- selectedEntries.some((entry) => entry.path === fsEntry.path)- ) {- setSelectedEntries(- selectedEntries.filter((entry) => entry.path !== fsEntry.path),- ); // deselect selected entry- } else {- setSelectedEntries([...selectedEntries, fsEntry]);- }- } else {- setSelectedEntries([fsEntry]);- if (fsEntry.isFile) {- if (singleClickAction === 'openInternal') {- openEntryInternal(fsEntry);- } else if (singleClickAction === 'openExternal') {- openFileNatively(fsEntry.path);- }- }- }- };-- const handleFileMoveDrop = (item, monitor) => {- if (isReadOnlyMode) {- showNotification(- 'Importing files is disabled because the location is in read-only mode.',- 'error',- true,- ); //i18n.t('core:dndDisabledReadOnlyMode')- return;- }- if (item) {- // const mItem = monitor.getItem();- let arrPath;- if (item.selectedEntries && item.selectedEntries.length > 0) {- const arrSelected = item.selectedEntries- .map((entry) => entry.path)- // remove target folder selection- .filter((epath) => epath !== item.targetPath);- if (arrSelected.length > 0) {- arrPath = arrSelected;- } else {- arrPath = [item.path];- }- } else {- arrPath = [item.path];- }- console.log('Dropped files: ' + item.path);- handleEntryExist(item.selectedEntries, item.targetPath).then((exist) => {- if (exist) {- openEntryExistDialog(exist, () => {- moveFiles(arrPath, item.targetPath, currentLocation.uuid);- });- } else {- moveFiles(arrPath, item.targetPath, currentLocation.uuid);- }- });- }- };-- const key = fsEntry.path;-- if (fsEntry.isFile) {- return (- <FileSourceDnd key={key}>- {cellContent(- fsEntry,- selectedEntries,- index,- handleGridContextMenu,- handleGridCellClick,- handleGridCellDblClick,- isLast,- )}- </FileSourceDnd>- );- }- const { FILE } = NativeTypes;-- return (- <div- style={{- position: 'relative',- }}- key={key}- >- <TargetFileBox accepts={[FILE]} directoryPath={fsEntry.path}>- <CustomDragLayer />- <TargetMoveFileBox- accepts={[DragItemTypes.FILE]}- targetPath={fsEntry.path}- onDrop={handleFileMoveDrop}- >- {cellContent(- fsEntry,- selectedEntries,- index,- handleGridContextMenu,- handleGridCellClick,- handleGridCellDblClick,- isLast,- )}- </TargetMoveFileBox>- </TargetFileBox>- </div>- );-};*/-export const renderCellPlaceholder = () => {return (<divdiff --git a/src/renderer/perspectives/grid/components/GridPagination.tsx b/src/renderer/perspectives/grid/components/GridPagination.tsxindex 826606598..9150c138b 100644--- a/src/renderer/perspectives/grid/components/GridPagination.tsx+++ b/src/renderer/perspectives/grid/components/GridPagination.tsx@@ -47,6 +47,7 @@ import { extractDirectoryName } from '@tagspaces/tagspaces-common/paths';import React, { useContext, useEffect, useReducer, useRef } from 'react';import { useTranslation } from 'react-i18next';import GridCellsContainer from './GridCellsContainer';+import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';interface Props {desktopMode: boolean;@@ -60,14 +61,11 @@ interface Props {isLast?: boolean,) => void;currentDirectoryPath: string;- onContextMenu: (event: React.MouseEvent<HTMLDivElement>) => void;- openRenameEntryDialog: () => void;+ //onContextMenu: (event: React.MouseEvent<HTMLDivElement>) => void;onClick: (event: React.MouseEvent<HTMLDivElement>) => void;// eslint-disable-next-line react/no-unused-prop-typesselectedEntries; // cache onlysetSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;- setFileContextMenuAnchorEl: (HTMLElement) => void;- setDirContextMenuAnchorEl: (HTMLElement) => void;clearSelection: () => void;}@@ -76,12 +74,10 @@ function GridPagination(props: Props) {const {getCellContent,currentDirectoryPath,- openRenameEntryDialog,- setFileContextMenuAnchorEl,- setDirContextMenuAnchorEl,selectedEntries,setSelectedEntries,} = props;+ const { openDirectoryMenu, openRenameEntryDialog } = useMenuContext();const {showDetails,showDescription,@@ -220,7 +216,7 @@ function GridPagination(props: Props) {<divref={containerEl}onContextMenu={(event: React.MouseEvent<HTMLDivElement>) =>- props.onContextMenu(event)+ openDirectoryMenu(event, currentDirectoryPath)}onClick={(event: React.MouseEvent<HTMLDivElement>) =>props.onClick(event)@@ -426,8 +422,6 @@ function GridPagination(props: Props) {fsEntry={entry}index={index}cellContent={getCellContent}- setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}- setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}isLast={index === dArray.length - 1}/>))}diff --git a/src/renderer/perspectives/grid/components/MainContainer.tsx b/src/renderer/perspectives/grid/components/MainContainer.tsxindex 4eb19c9b0..2cdc7a62e 100644--- a/src/renderer/perspectives/grid/components/MainContainer.tsx+++ b/src/renderer/perspectives/grid/components/MainContainer.tsx@@ -20,11 +20,7 @@ import React, { useEffect, useRef, useState } from 'react';import { useSelector } from 'react-redux';import { GlobalHotKeys } from 'react-hotkeys';import { getDesktopMode, getKeyBindingObject } from '-/reducers/settings';-import FileMenu from '-/components/menus/FileMenu';-import DirectoryMenu from '-/components/menus/DirectoryMenu';import EntryTagMenu from '-/components/menus/EntryTagMenu';-import AddRemoveTagsDialog from '-/components/dialogs/AddRemoveTagsDialog';-import MoveCopyFilesDialog from '-/components/dialogs/MoveCopyFilesDialog';import TagDropContainer from '-/components/TagDropContainer';import GridCell from './GridCell';import MainToolbar from '-/perspectives/grid/components/MainToolbar';@@ -52,14 +48,16 @@ import useFirstRender from '-/utils/useFirstRender';import { useDeleteMultipleEntriesDialogContext } from '-/components/dialogs/hooks/useDeleteMultipleEntriesDialogContext';import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';import FileSourceDnd from '-/components/FileSourceDnd';+import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';-interface Props {- openRenameEntryDialog: () => void;-}+interface Props {}function GridPerspective(props: Props) {- const { openRenameEntryDialog } = props;-+ const {+ openRenameEntryDialog,+ openAddRemoveTagsDialog,+ openMoveCopyFilesDialog,+ } = useMenuContext();const { openEntry, openPrevFile, openNextFile } = useOpenedEntryContext();const { actions } = usePerspectiveActionsContext();const { showDirectories } = usePerspectiveSettingsContext();@@ -72,8 +70,7 @@ function GridPerspective(props: Props) {const { sortedDirContent, sortBy, orderBy, setSortBy, setOrderBy } =useSortedDirContext();const desktopMode = useSelector(getDesktopMode);- const { selectedEntries, setSelectedEntries, lastSelectedEntryPath } =- useSelectedEntriesContext();+ const { selectedEntries, setSelectedEntries } = useSelectedEntriesContext();const keyBindings = useSelector(getKeyBindingObject);// Create functions that dispatch actions@@ -90,11 +87,7 @@ function GridPerspective(props: Props) {const [mouseY, setMouseY] = useState<number>(undefined);const selectedEntry = useRef<TS.FileSystemEntry>(undefined);const selectedTag = useRef<TS.Tag | null>(null);- const perspectiveMode = useRef<boolean>(true);- const [fileContextMenuAnchorEl, setFileContextMenuAnchorEl] =- useState<null | HTMLElement>(null);- const [dirContextMenuAnchorEl, setDirContextMenuAnchorEl] =- useState<null | HTMLElement>(null);+ //const perspectiveMode = useRef<boolean>(true);const [tagContextMenuAnchorEl, setTagContextMenuAnchorEl] =useState<null | HTMLElement>(null);const [sortingContextMenuAnchorEl, setSortingContextMenuAnchorEl] =@@ -103,12 +96,8 @@ function GridPerspective(props: Props) {useState<null | HTMLElement>(null);const [isAddTagDialogOpened, setIsAddTagDialogOpened] =useState<TS.Tag>(undefined);- const [isMoveCopyFilesDialogOpened, setIsMoveCopyFilesDialogOpened] =- useState<boolean>(false);const [isShareFilesDialogOpened, setIsShareFilesDialogOpened] =useState<boolean>(false);- const [isAddRemoveTagsDialogOpened, setIsAddRemoveTagsDialogOpened] =- useState<boolean>(false);const [isGridSettingsDialogOpened, setIsGridSettingsDialogOpened] =useState<boolean>(false);const firstRender = useFirstRender();@@ -189,10 +178,6 @@ function GridPerspective(props: Props) {setOptionsContextMenuAnchorEl(null);};- const openMoveCopyFilesDialog = () => {- setIsMoveCopyFilesDialogOpened(true);- };-const openShareFilesDialog = () => {const currentLocation = findLocation();if (currentLocation && currentLocation.haveObjectStoreSupport()) {@@ -200,10 +185,6 @@ function GridPerspective(props: Props) {}};- const openAddRemoveTagsDialog = () => {- setIsAddRemoveTagsDialogOpened(true);- };-const keyMap = {nextDocument: keyBindings.nextDocument,prevDocument: keyBindings.prevDocument,@@ -219,7 +200,7 @@ function GridPerspective(props: Props) {reloadDocument: keyBindings.reloadDocument,};- const onContextMenu = (event: React.MouseEvent<HTMLDivElement>) => {+ /*const onContextMenu = (event: React.MouseEvent<HTMLDivElement>) => {event.preventDefault();setMouseX(event.clientX);setMouseY(event.clientY);@@ -228,7 +209,7 @@ function GridPerspective(props: Props) {}perspectiveMode.current = false;setDirContextMenuAnchorEl(event.currentTarget);- };+ };*/const onClick = (event: React.MouseEvent<HTMLDivElement>) => {event.preventDefault();@@ -247,7 +228,7 @@ function GridPerspective(props: Props) {}},addRemoveTags: () => {- if (lastSelectedEntryPath) {+ if (selectedEntries && selectedEntries.length > 1) {openAddRemoveTagsDialog();}},@@ -295,9 +276,6 @@ function GridPerspective(props: Props) {},};- //const sortedDirectories = sortedDirContent.filter((entry) => !entry.isFile);- //const sortedFiles = sortedDirContent.filter((entry) => entry.isFile);-const getCellContent = (fsEntry: TS.FileSystemEntry,selectedEntries: Array<TS.FileSystemEntry>,@@ -354,8 +332,6 @@ function GridPerspective(props: Props) {<MainToolbarprefixDataTID={'grid'}toggleSelectAllFiles={toggleSelectAllFiles}- openAddRemoveTagsDialog={openAddRemoveTagsDialog}- openMoveCopyFilesDialog={openMoveCopyFilesDialog}handleSortingMenu={handleSortingMenu}handleExportCsvMenu={handleExportCsvMenu}openSettings={openSettings}@@ -370,26 +346,16 @@ function GridPerspective(props: Props) {<GridPagination//directories={sortedDirectories}desktopMode={desktopMode}- openRenameEntryDialog={openRenameEntryDialog}//files={sortedFiles}getCellContent={getCellContent}currentDirectoryPath={currentDirectoryPath}onClick={onClick}- onContextMenu={onContextMenu}selectedEntries={selectedEntries}setSelectedEntries={handleSetSelectedEntries}- setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}- setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}clearSelection={clearSelection}/></GridCellsStyleContextProvider></GlobalHotKeys>- {isAddRemoveTagsDialogOpened && (- <AddRemoveTagsDialog- open={isAddRemoveTagsDialogOpened}- onClose={() => setIsAddRemoveTagsDialogOpened(false)}- />- )}{isAddTagDialogOpened !== undefined && (<AddTagToTagGroupDialogopen={true}@@ -407,50 +373,13 @@ function GridPerspective(props: Props) {handleSortingMenu={handleSortingMenu}/>)}- {isMoveCopyFilesDialogOpened && (- <MoveCopyFilesDialog- open={isMoveCopyFilesDialogOpened}- onClose={() => setIsMoveCopyFilesDialogOpened(false)}- />- )}{isShareFilesDialogOpened && Pro && (<ShareFilesDialogopen={isShareFilesDialogOpened}onClose={() => setIsShareFilesDialogOpened(false)}/>)}- {Boolean(fileContextMenuAnchorEl) && (- <FileMenu- anchorEl={fileContextMenuAnchorEl}- mouseX={mouseX}- mouseY={mouseY}- open={Boolean(fileContextMenuAnchorEl)}- onClose={() => setFileContextMenuAnchorEl(null)}- openRenameFileDialog={openRenameEntryDialog}- openMoveCopyFilesDialog={openMoveCopyFilesDialog}- openShareFilesDialog={openShareFilesDialog}- openAddRemoveTagsDialog={openAddRemoveTagsDialog}- selectedFilePath={- lastSelectedEntryPath ? lastSelectedEntryPath : currentDirectoryPath- }- />- )}- <DirectoryMenu- open={Boolean(dirContextMenuAnchorEl)}- onClose={() => {- setDirContextMenuAnchorEl(null);- perspectiveMode.current = true;- }}- anchorEl={dirContextMenuAnchorEl}- mouseX={mouseX}- mouseY={mouseY}- directoryPath={lastSelectedEntryPath}- openRenameDirectoryDialog={openRenameEntryDialog}- openMoveCopyFilesDialog={openMoveCopyFilesDialog}- perspectiveMode={perspectiveMode.current}- openAddRemoveTagsDialog={openAddRemoveTagsDialog}- />- {/* {Boolean(tagContextMenuAnchorEl) && ( // TODO EntryTagMenu is used in TagSelect we cannot move confirm dialog from menu */}+ {/* TODO EntryTagMenu is used in TagSelect we cannot move confirm dialog from menu */}<EntryTagMenuanchorEl={tagContextMenuAnchorEl}open={Boolean(tagContextMenuAnchorEl)}diff --git a/src/renderer/perspectives/grid/components/MainToolbar.tsx b/src/renderer/perspectives/grid/components/MainToolbar.tsxindex 22db988d1..1b79fb421 100644--- a/src/renderer/perspectives/grid/components/MainToolbar.tsx+++ b/src/renderer/perspectives/grid/components/MainToolbar.tsx@@ -52,12 +52,11 @@ import { alpha, useTheme } from '@mui/material/styles';import { saveAs } from 'file-saver';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';+import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';interface Props {prefixDataTID?: string;toggleSelectAllFiles: (event: any) => void;- openAddRemoveTagsDialog: () => void;- openMoveCopyFilesDialog: () => void;handleSortingMenu: (event: Object) => void;handleExportCsvMenu: () => void;openSettings: () => void;@@ -68,14 +67,13 @@ function MainToolbar(props: Props) {const {prefixDataTID,toggleSelectAllFiles,- openAddRemoveTagsDialog,- openMoveCopyFilesDialog,handleSortingMenu,handleExportCsvMenu,openSettings,openShareFilesDialog,} = props;+ const { openMoveCopyFilesDialog, openAddRemoveTagsDialog } = useMenuContext();const { haveLocalSetting } = usePerspectiveSettingsContext();const { openAiGenerationDialog } = useAiGenerationDialogContext();const { nativeDragModeEnabled, setNativeDragModeEnabled } =@@ -194,7 +192,7 @@ function MainToolbar(props: Props) {keyBinding={keyBindings['addRemoveTags']}aria-label={t('core:tagSelectedEntries')}data-tid={prefixDataTID + 'PerspectiveAddRemoveTags'}- onClick={openAddRemoveTagsDialog}+ onClick={() => openAddRemoveTagsDialog(selectedEntries)}><TagIcon /></TsToolbarButton>@@ -219,7 +217,7 @@ function MainToolbar(props: Props) {keyBinding={keyBindings['copyMoveSelectedEntries']}aria-label={t('core:copyMoveSelectedEntries')}data-tid={prefixDataTID + 'PerspectiveCopySelectedFiles'}- onClick={openMoveCopyFilesDialog}+ onClick={() => openMoveCopyFilesDialog(selectedEntries)}><CopyMoveIcon /></TsToolbarButton>diff --git a/src/renderer/perspectives/list/components/MainContainer.tsx b/src/renderer/perspectives/list/components/MainContainer.tsxindex 21b64cad7..0ac9556eb 100644--- a/src/renderer/perspectives/list/components/MainContainer.tsx+++ b/src/renderer/perspectives/list/components/MainContainer.tsx@@ -20,11 +20,7 @@ import React, { useEffect, useRef, useState } from 'react';import { useSelector } from 'react-redux';import { GlobalHotKeys } from 'react-hotkeys';import { getDesktopMode, getKeyBindingObject } from '-/reducers/settings';-import FileMenu from '-/components/menus/FileMenu';-import DirectoryMenu from '-/components/menus/DirectoryMenu';import EntryTagMenu from '-/components/menus/EntryTagMenu';-import AddRemoveTagsDialog from '-/components/dialogs/AddRemoveTagsDialog';-import MoveCopyFilesDialog from '-/components/dialogs/MoveCopyFilesDialog';import TagDropContainer from '-/components/TagDropContainer';import RowCell from '-/perspectives/list/components/RowCell';import MainToolbar from '-/perspectives/grid/components/MainToolbar';@@ -52,14 +48,16 @@ import useFirstRender from '-/utils/useFirstRender';import { useDeleteMultipleEntriesDialogContext } from '-/components/dialogs/hooks/useDeleteMultipleEntriesDialogContext';import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';import FileSourceDnd from '-/components/FileSourceDnd';+import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';-interface Props {- openRenameEntryDialog: () => void;-}+interface Props {}function ListPerspective(props: Props) {- const { openRenameEntryDialog } = props;-+ const {+ openRenameEntryDialog,+ openAddRemoveTagsDialog,+ openMoveCopyFilesDialog,+ } = useMenuContext();const { openEntry, openPrevFile, openNextFile } = useOpenedEntryContext();const { actions } = usePerspectiveActionsContext();const { showDirectories } = usePerspectiveSettingsContext();@@ -72,8 +70,7 @@ function ListPerspective(props: Props) {const { sortedDirContent, sortBy, orderBy, setSortBy, setOrderBy } =useSortedDirContext();const desktopMode = useSelector(getDesktopMode);- const { selectedEntries, setSelectedEntries, lastSelectedEntryPath } =- useSelectedEntriesContext();+ const { selectedEntries, setSelectedEntries } = useSelectedEntriesContext();const keyBindings = useSelector(getKeyBindingObject);// Create functions that dispatch actions@@ -90,11 +87,7 @@ function ListPerspective(props: Props) {const [mouseY, setMouseY] = useState<number>(undefined);const selectedEntry = useRef<TS.FileSystemEntry>(undefined);const selectedTag = useRef<TS.Tag | null>(null);- const perspectiveMode = useRef<boolean>(true);- const [fileContextMenuAnchorEl, setFileContextMenuAnchorEl] =- useState<null | HTMLElement>(null);- const [dirContextMenuAnchorEl, setDirContextMenuAnchorEl] =- useState<null | HTMLElement>(null);+ //const perspectiveMode = useRef<boolean>(true);const [tagContextMenuAnchorEl, setTagContextMenuAnchorEl] =useState<null | HTMLElement>(null);const [sortingContextMenuAnchorEl, setSortingContextMenuAnchorEl] =@@ -103,12 +96,8 @@ function ListPerspective(props: Props) {useState<null | HTMLElement>(null);const [isAddTagDialogOpened, setIsAddTagDialogOpened] =useState<TS.Tag>(undefined);- const [isMoveCopyFilesDialogOpened, setIsMoveCopyFilesDialogOpened] =- useState<boolean>(false);const [isShareFilesDialogOpened, setIsShareFilesDialogOpened] =useState<boolean>(false);- const [isAddRemoveTagsDialogOpened, setIsAddRemoveTagsDialogOpened] =- useState<boolean>(false);const [isGridSettingsDialogOpened, setIsGridSettingsDialogOpened] =useState<boolean>(false);const firstRender = useFirstRender();@@ -189,10 +178,6 @@ function ListPerspective(props: Props) {setOptionsContextMenuAnchorEl(null);};- const openMoveCopyFilesDialog = () => {- setIsMoveCopyFilesDialogOpened(true);- };-const openShareFilesDialog = () => {const currentLocation = findLocation();if (currentLocation && currentLocation.haveObjectStoreSupport()) {@@ -200,10 +185,6 @@ function ListPerspective(props: Props) {}};- const openAddRemoveTagsDialog = () => {- setIsAddRemoveTagsDialogOpened(true);- };-const keyMap = {nextDocument: keyBindings.nextDocument,prevDocument: keyBindings.prevDocument,@@ -219,7 +200,7 @@ function ListPerspective(props: Props) {reloadDocument: keyBindings.reloadDocument,};- const onContextMenu = (event: React.MouseEvent<HTMLDivElement>) => {+ /*const onContextMenu = (event: React.MouseEvent<HTMLDivElement>) => {event.preventDefault();setMouseX(event.clientX);setMouseY(event.clientY);@@ -228,7 +209,7 @@ function ListPerspective(props: Props) {}perspectiveMode.current = false;setDirContextMenuAnchorEl(event.currentTarget);- };+ };*/const onClick = (event: React.MouseEvent<HTMLDivElement>) => {event.preventDefault();@@ -247,7 +228,7 @@ function ListPerspective(props: Props) {}},addRemoveTags: () => {- if (lastSelectedEntryPath) {+ if (selectedEntries && selectedEntries.length > 1) {openAddRemoveTagsDialog();}},@@ -351,8 +332,6 @@ function ListPerspective(props: Props) {<MainToolbarprefixDataTID={'list'}toggleSelectAllFiles={toggleSelectAllFiles}- openAddRemoveTagsDialog={openAddRemoveTagsDialog}- openMoveCopyFilesDialog={openMoveCopyFilesDialog}handleSortingMenu={handleSortingMenu}handleExportCsvMenu={handleExportCsvMenu}openSettings={openSettings}@@ -367,26 +346,16 @@ function ListPerspective(props: Props) {<GridPagination//directories={sortedDirectories}desktopMode={desktopMode}- openRenameEntryDialog={openRenameEntryDialog}//files={sortedFiles}getCellContent={getCellContent}currentDirectoryPath={currentDirectoryPath}onClick={onClick}- onContextMenu={onContextMenu}selectedEntries={selectedEntries}setSelectedEntries={handleSetSelectedEntries}- setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}- setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}clearSelection={clearSelection}/></ListCellsStyleContextProvider></GlobalHotKeys>- {isAddRemoveTagsDialogOpened && (- <AddRemoveTagsDialog- open={isAddRemoveTagsDialogOpened}- onClose={() => setIsAddRemoveTagsDialogOpened(false)}- />- )}{isAddTagDialogOpened !== undefined && (<AddTagToTagGroupDialogopen={true}@@ -404,50 +373,13 @@ function ListPerspective(props: Props) {handleSortingMenu={handleSortingMenu}/>)}- {isMoveCopyFilesDialogOpened && (- <MoveCopyFilesDialog- open={isMoveCopyFilesDialogOpened}- onClose={() => setIsMoveCopyFilesDialogOpened(false)}- />- )}{isShareFilesDialogOpened && Pro && (<ShareFilesDialogopen={isShareFilesDialogOpened}onClose={() => setIsShareFilesDialogOpened(false)}/>)}- {Boolean(fileContextMenuAnchorEl) && (- <FileMenu- anchorEl={fileContextMenuAnchorEl}- mouseX={mouseX}- mouseY={mouseY}- open={Boolean(fileContextMenuAnchorEl)}- onClose={() => setFileContextMenuAnchorEl(null)}- openRenameFileDialog={openRenameEntryDialog}- openMoveCopyFilesDialog={openMoveCopyFilesDialog}- openShareFilesDialog={openShareFilesDialog}- openAddRemoveTagsDialog={openAddRemoveTagsDialog}- selectedFilePath={- lastSelectedEntryPath ? lastSelectedEntryPath : currentDirectoryPath- }- />- )}- <DirectoryMenu- open={Boolean(dirContextMenuAnchorEl)}- onClose={() => {- setDirContextMenuAnchorEl(null);- perspectiveMode.current = true;- }}- anchorEl={dirContextMenuAnchorEl}- mouseX={mouseX}- mouseY={mouseY}- directoryPath={lastSelectedEntryPath}- openRenameDirectoryDialog={openRenameEntryDialog}- openMoveCopyFilesDialog={openMoveCopyFilesDialog}- perspectiveMode={perspectiveMode.current}- openAddRemoveTagsDialog={openAddRemoveTagsDialog}- />- {/* {Boolean(tagContextMenuAnchorEl) && ( // TODO EntryTagMenu is used in TagSelect we cannot move confirm dialog from menu */}+ {/* TODO EntryTagMenu is used in TagSelect we cannot move confirm dialog from menu */}<EntryTagMenuanchorEl={tagContextMenuAnchorEl}open={Boolean(tagContextMenuAnchorEl)}