TagSpaces is an offline, open source, document manager with tagging support
e2e fix
Stanimir2d2f3b26acb1
diff --git a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsxindex 35969e528..d60e1808e 100644--- a/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx+++ b/src/renderer/components/dialogs/AddRemoveTagsDialog.tsx@@ -41,11 +41,12 @@ import {import { useReducer, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';import TagsSelect from '../TagsSelect';+import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';interface Props {open: boolean;onClose: (clearSelection?: boolean) => void;- selected: TS.FileSystemEntry[];+ selected?: TS.FileSystemEntry[];}function AddRemoveTagsDialog(props: Props) {@@ -54,10 +55,12 @@ function AddRemoveTagsDialog(props: Props) {const { findLocation } = useCurrentLocationContext();const { addTagsToFsEntries, removeTags } = useTaggingActionsContext();+ const { selectedEntries } = useSelectedEntriesContext();const [newlyAddedTags, setNewlyAddedTags] = useState<TS.Tag[]>([]);const inputTags = useRef<TS.Tag[]>([]);const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);const currentLocation = findLocation();+ const currentEntries = selected || selectedEntries;const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {if (action === 'remove-value') {@@ -102,9 +105,9 @@ function AddRemoveTagsDialog(props: Props) {};const addTagsAction = () => {- if (selected && selected.length > 0) {+ if (currentEntries && currentEntries.length > 0) {addTagsToFsEntries(- selected,+ currentEntries,uniqueTags([...newlyAddedTags, ...inputTags.current]),);}@@ -112,15 +115,15 @@ function AddRemoveTagsDialog(props: Props) {};const removeTagsAction = () => {- if (selected && selected.length > 0) {- removeTags(selected, [...newlyAddedTags, ...inputTags.current]);+ if (currentEntries && currentEntries.length > 0) {+ removeTags(currentEntries, [...newlyAddedTags, ...inputTags.current]);}onCloseDialog(true);};const removeAllTagsAction = () => {- if (selected && selected.length > 0) {- removeTags(selected);+ if (currentEntries && currentEntries.length > 0) {+ removeTags(currentEntries);}onCloseDialog(true);};@@ -128,7 +131,7 @@ function AddRemoveTagsDialog(props: Props) {const disabledButtons =(!newlyAddedTags && !inputTags.current) ||(newlyAddedTags.length < 1 && inputTags.current.length < 1) ||- selected.length < 1;+ currentEntries.length < 1;const theme = useTheme();const smallScreen = useMediaQuery(theme.breakpoints.down('md'));@@ -169,8 +172,8 @@ function AddRemoveTagsDialog(props: Props) {{t('selectedFilesAndFolders')}</Typography><List dense style={{ width: 550, marginLeft: -15 }}>- {selected.length > 0 &&- selected.map((entry) => (+ {currentEntries.length > 0 &&+ currentEntries.map((entry) => (<ListItem key={entry.path} title={entry.path}><ListItemIcon>{entry.isFile ? <FileIcon /> : <FolderIcon />}@@ -199,7 +202,7 @@ function AddRemoveTagsDialog(props: Props) {</TsButton><TsButtondata-tid="cleanTagsMultipleEntries"- disabled={selected.length < 1}+ disabled={currentEntries.length < 1}onClick={removeAllTagsAction}>{t('core:tagOperationCleanTags')}diff --git a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsxindex feb61282a..c0abfeb2b 100644--- a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx+++ b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx@@ -1,3 +1,4 @@+import React, { useEffect, useReducer, useRef, useState } from 'react';import AppConfig from '-/AppConfig';import { FileIcon, FolderIcon } from '-/components/CommonIcons';import DirectoryListView from '-/components/DirectoryListView';@@ -24,9 +25,9 @@ import Typography from '@mui/material/Typography';import { useTheme } from '@mui/material/styles';import useMediaQuery from '@mui/material/useMediaQuery';import { formatBytes } from '@tagspaces/tagspaces-common/misc';-import { useEffect, useReducer, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';import { useDispatch } from 'react-redux';+import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';interface Props {open: boolean;@@ -47,6 +48,8 @@ function MoveCopyFilesDialog(props: Props) {useEntryExistDialogContext();const { copyFiles, copyDirs, moveFiles, moveDirs } = useIOActionsContext();const { openFileUploadDialog } = useFileUploadDialogContext();+ const { selectedEntries } = useSelectedEntriesContext();+ const currentEntries = entries || selectedEntries;const [targetPath, setTargetPath] = useState(targetDir ? targetDir : currentDirectoryPath,@@ -58,12 +61,14 @@ function MoveCopyFilesDialog(props: Props) {const currentLocation = findLocation();const targetLocation = findLocation(targetLocationId);- const selectedFiles = entries- ? entries.filter((fsEntry) => fsEntry.isFile).map((fsentry) => fsentry.path)+ const selectedFiles = currentEntries+ ? currentEntries+ .filter((fsEntry) => fsEntry.isFile)+ .map((fsentry) => fsentry.path): [];- const selectedDirs = entries- ? entries+ const selectedDirs = currentEntries+ ? currentEntries.filter((fsEntry) => !fsEntry.isFile).map((fsentry) => fsentry.path): [];@@ -156,7 +161,7 @@ function MoveCopyFilesDialog(props: Props) {}function copyMove(copy: boolean) {- handleEntryExist(entries, targetPath).then((exist) => {+ handleEntryExist(currentEntries, targetPath).then((exist) => {if (exist) {openEntryExistDialog(exist, () => {if (copy) {@@ -204,8 +209,8 @@ function MoveCopyFilesDialog(props: Props) {maxHeight: 200,}}>- {entries.length > 0 &&- entries.map((entry) => (+ {currentEntries.length > 0 &&+ currentEntries.map((entry) => (<ListItem title={entry.path} key={entry.path}><ListItemIcon>{entry.isFile ? <FileIcon /> : <FolderIcon />}@@ -269,5 +274,24 @@ function MoveCopyFilesDialog(props: Props) {</Dialog>);}+/*const areEqual = (prev: Props, next: Props) => {+ if (prev.open !== next.open) return false;+ if (prev.targetDir !== next.targetDir) return false;+ if (prev.targetLocationId !== next.targetLocationId) return false;+ if (prev.onClose !== next.onClose) return false;++ const a = prev.entries || [];+ const b = next.entries || [];+ if (a.length !== b.length) return false;++ for (let i = 0; i < a.length; i++) {+ if (a[i].path !== b[i].path) return false;+ if (a[i].isFile !== b[i].isFile) return false;+ // add any other small stable fields you rely on (name, uuid, etc.)+ }++ return true;+};+export default React.memo(MoveCopyFilesDialog, areEqual);*/export default MoveCopyFilesDialog;diff --git a/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsxindex 03ac099c3..09b8d31a0 100644--- a/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx+++ b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx@@ -18,6 +18,7 @@import React, {createContext,+ useCallback,useMemo,useReducer,useRef,@@ -25,11 +26,9 @@ import React, {} 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';import { Pro } from '-/pro';-import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';import { useNotificationContext } from '-/hooks/useNotificationContext';type MenuContextData = {@@ -55,12 +54,12 @@ type MenuContextData = {openRenameEntryDialog: () => void;closeRenameEntryDialog: () => void;openMoveCopyFilesDialog: (- entries?: TS.FileSystemEntry[],+ entries: TS.FileSystemEntry[],targetDirectory?: string,targetLocationId?: string,) => void;closeMoveCopyFilesDialog: () => void;- openAddRemoveTagsDialog: (entries?: TS.FileSystemEntry[]) => void;+ openAddRemoveTagsDialog: (entries: TS.FileSystemEntry[]) => void;closeAddRemoveTagsDialog: () => void;openShareFilesDialog: (entries?: TS.FileSystemEntry[]) => void;closeShareFilesDialog: () => void;@@ -113,9 +112,7 @@ const AddRemoveTagsDialog = React.lazy(export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {const { findLocation } = useCurrentLocationContext();- const { selectedEntries } = useSelectedEntriesContext();- const { openedEntry, fileChanged } = useOpenedEntryContext();- const { showNotification } = useNotificationContext();+ // const { showNotification } = useNotificationContext();const [directoryContextMenuAnchorEl, setDirectoryContextMenuAnchorEl] =useState<null | HTMLElement>(null);const [fileContextMenuAnchorEl, setFileContextMenuAnchorEl] =@@ -140,43 +137,49 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {const ShareFilesDialog = Pro && Pro.UI ? Pro.UI.ShareFilesDialog : false;- 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 openMenu = useCallback(+ (+ 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 openDirectoryMenu = useCallback(+ (+ 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 = () => {+ const closeDirectoryMenu = useCallback(() => {directoryPath.current = undefined;mouseX.current = undefined;mouseY.current = undefined;@@ -184,95 +187,107 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {switchPerspectives.current = false;menuItems.current = undefined;setDirectoryContextMenuAnchorEl(null);- };+ }, []);- const openFileMenu = (- event: MouseEvent | React.MouseEvent<Element, MouseEvent>,- dirPath: string,- orderTop?: (entry: TS.FileSystemEntry) => void,- orderBottom?: (entry: TS.FileSystemEntry) => 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 openFileMenu = useCallback(+ (+ event: MouseEvent | React.MouseEvent<Element, MouseEvent>,+ dirPath: string,+ orderTop?: (entry: TS.FileSystemEntry) => void,+ orderBottom?: (entry: TS.FileSystemEntry) => void,+ ) => {+ event.preventDefault();+ directoryPath.current = dirPath;+ mouseX.current = event.clientX;+ mouseY.current = event.clientY;+ reorderTop.current = orderTop;+ reorderBottom.current = orderBottom;+ // @ts-ignore+ setFileContextMenuAnchorEl(event.currentTarget);+ },+ [],+ );- const closeFileMenu = () => {+ const closeFileMenu = useCallback(() => {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 = () => {+ const openRenameEntryDialog = useCallback(() => {openRenameEntry.current = true;forceUpdate();- };+ }, []);- const openMoveCopyFilesDialog = (- entries?: TS.FileSystemEntry[],- tDirectory?: string,- tLocationId?: string,- ) => {- openMoveCopyFiles.current = true;- currentEntries.current = entries;- targetDirectory.current = tDirectory;- targetLocationId.current = tLocationId;+ const closeRenameEntryDialog = useCallback(() => {+ openRenameEntry.current = false;forceUpdate();- };+ }, []);- const openAddRemoveTagsDialog = (entries?: TS.FileSystemEntry[]) => {- const ent = entries || selectedEntries;- if (- openedEntry &&- fileChanged &&- ent &&- ent.some((e) => e.path === openedEntry.path)- ) {- showNotification(- `You can't edit tags, because '${openedEntry.path}' is opened for editing`,- 'default',- true,- );- return;- }- openAddRemoveTags.current = true;- currentEntries.current = entries;+ const openMoveCopyFilesDialog = useCallback(+ (+ entries: TS.FileSystemEntry[],+ tDirectory?: string,+ tLocationId?: string,+ ) => {+ openMoveCopyFiles.current = true;+ currentEntries.current = entries;+ targetDirectory.current = tDirectory;+ targetLocationId.current = tLocationId;+ forceUpdate();+ },+ [],+ );++ const closeMoveCopyFilesDialog = useCallback(() => {+ openMoveCopyFiles.current = false;+ forceUpdate();+ }, []);++ const openAddRemoveTagsDialog = useCallback(+ (entries: TS.FileSystemEntry[]) => {+ openAddRemoveTags.current = true;+ currentEntries.current = entries;+ forceUpdate();+ },+ [],+ );++ const closeAddRemoveTagsDialog = useCallback(() => {+ openAddRemoveTags.current = false;forceUpdate();- };+ }, []);- const openShareFilesDialog = (entries?: TS.FileSystemEntry[]) => {+ const openShareFilesDialog = useCallback((entries?: TS.FileSystemEntry[]) => {openShareFiles.current = true;currentEntries.current = entries;forceUpdate();- };+ }, []);- const closeRenameEntryDialog = () => {- openRenameEntry.current = false;- forceUpdate();- };- const closeMoveCopyFilesDialog = () => {- openMoveCopyFiles.current = false;- forceUpdate();- };- const closeAddRemoveTagsDialog = () => {- openAddRemoveTags.current = false;- forceUpdate();- };- const closeShareFilesDialog = () => {+ const closeShareFilesDialog = useCallback(() => {openShareFiles.current = false;forceUpdate();- };+ }, []);++ // memoize provider value so consumers only re-render when callbacks change ---+ const context = useMemo(() => {+ return {+ openMenu,+ openDirectoryMenu,+ closeDirectoryMenu,+ openFileMenu,+ closeFileMenu,+ openRenameEntryDialog,+ closeRenameEntryDialog,+ openMoveCopyFilesDialog,+ closeMoveCopyFilesDialog,+ openAddRemoveTagsDialog,+ closeAddRemoveTagsDialog,+ openShareFilesDialog,+ closeShareFilesDialog,+ };+ }, []);function DirectoryMenuAsync(props) {return (@@ -310,25 +325,6 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {);}- const context = useMemo(() => {- return {- openMenu,- openDirectoryMenu,- closeDirectoryMenu,- openFileMenu,- closeFileMenu,- //setMousePosition,- openRenameEntryDialog,- closeRenameEntryDialog,- openMoveCopyFilesDialog,- closeMoveCopyFilesDialog,- openAddRemoveTagsDialog,- closeAddRemoveTagsDialog,- openShareFilesDialog,- closeShareFilesDialog,- };- }, [selectedEntries, openedEntry, fileChanged]);-return (<MenuContext.Provider value={context}><RenameEntryDialogAsync@@ -338,18 +334,14 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {<MoveCopyFilesDialogAsyncopen={openMoveCopyFiles.current}onClose={closeMoveCopyFilesDialog}- entries={- currentEntries.current ? currentEntries.current : selectedEntries- }+ entries={currentEntries.current}targetDir={targetDirectory.current}targetLocationId={targetLocationId.current}/><AddRemoveTagsDialogAsyncopen={openAddRemoveTags.current}onClose={closeAddRemoveTagsDialog}- selected={- currentEntries.current ? currentEntries.current : selectedEntries- }+ selected={currentEntries.current}/>{ShareFilesDialog && (<ShareFilesDialog@@ -359,7 +351,7 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {)}<DirectoryMenuAsyncopen={Boolean(directoryContextMenuAnchorEl)}- onClose={() => closeDirectoryMenu()}+ onClose={closeDirectoryMenu}anchorEl={directoryContextMenuAnchorEl}perspectiveMode={perspectiveMode.current}switchPerspectives={switchPerspectives.current}@@ -371,7 +363,7 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {/><FileMenuAsyncopen={Boolean(fileContextMenuAnchorEl)}- onClose={() => closeFileMenu()}+ onClose={closeFileMenu}anchorEl={fileContextMenuAnchorEl}selectedFilePath={directoryPath.current}mouseX={mouseX.current}diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsxindex 5d858ff9c..c95d3aec3 100644--- a/src/renderer/components/menus/FileMenu.tsx+++ b/src/renderer/components/menus/FileMenu.tsx@@ -107,7 +107,7 @@ function FileMenu(props: Props) {downloadFsEntry,getMetadataID,} = useIOActionsContext();- const { openEntry } = useOpenedEntryContext();+ const { openEntry, openedEntry, fileChanged } = useOpenedEntryContext();const { openDirectory, currentLocationPath, getAllPropertiesPromise } =useDirectoryContentContext();const { showNotification } = useNotificationContext();@@ -184,7 +184,7 @@ function FileMenu(props: Props) {function showMoveCopyFilesDialog() {onClose();- openMoveCopyFilesDialog();+ openMoveCopyFilesDialog([lastSelectedEntry]);}function showShareFilesDialog() {@@ -258,7 +258,20 @@ function FileMenu(props: Props) {function showAddRemoveTagsDialog() {onClose();- openAddRemoveTagsDialog();+ if (+ openedEntry &&+ fileChanged &&+ selectedEntries &&+ selectedEntries.some((e) => e.path === openedEntry.path)+ ) {+ showNotification(+ `You can't edit tags, because '${openedEntry.path}' is opened for editing`,+ 'default',+ true,+ );+ return;+ }+ openAddRemoveTagsDialog(selectedEntries);}function duplicateFileHandler() {diff --git a/src/renderer/hooks/EditedEntryContextProvider.tsx b/src/renderer/hooks/EditedEntryContextProvider.tsxindex 6d5be5b16..0610efb2d 100644--- a/src/renderer/hooks/EditedEntryContextProvider.tsx+++ b/src/renderer/hooks/EditedEntryContextProvider.tsx@@ -16,13 +16,19 @@**/-import React, { createContext, useMemo, useReducer, useRef } from 'react';+import React, {+ createContext,+ useCallback,+ useMemo,+ useReducer,+ useState,+} from 'react';import { extractTagsAsObjects } from '@tagspaces/tagspaces-common/paths';import { TS } from '-/tagspaces.namespace';import AppConfig from '-/AppConfig';type EditedEntryContextData = {- actions: TS.EditAction[];+ actions: TS.EditAction[] | undefined;reflectUpdateMeta: (...entries: TS.FileSystemEntry[]) => void;setReflectActions: (...actionsArray: TS.EditAction[]) => void;reflectDeleteEntries: (...entries: TS.FileSystemEntry[]) => void;@@ -53,55 +59,65 @@ export type EditedEntryContextProviderProps = {export const EditedEntryContextProvider = ({children,}: EditedEntryContextProviderProps) => {- const actions = useRef<TS.EditAction[]>(undefined);- //const { getAllPropertiesPromise } = useDirectoryContentContext(); // cannot be injected here!-- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);+ const [actions, setActions] = useState<TS.EditAction[] | undefined>(+ undefined,+ );- function setReflectActions(...actionsArray: TS.EditAction[]) {- actions.current = actionsArray;- forceUpdate();- }+ const setReflectActions = useCallback((...actionsArray: TS.EditAction[]) => {+ // keep the array as provided — immutability is preserved+ setActions(actionsArray.length > 0 ? [...actionsArray] : undefined);+ }, []);- function reflectDeleteEntries(...entries: TS.FileSystemEntry[]) {- const actionsArray = [];- for (let i = 0; i < entries.length; i++) {- const currentAction: TS.EditAction = {+ const reflectDeleteEntries = useCallback(+ (...entries: TS.FileSystemEntry[]) => {+ if (!entries || entries.length === 0) {+ setActions(undefined);+ return;+ }+ const actionsArray: TS.EditAction[] = entries.map((entry) => ({action: 'delete',- entry: entries[i],- };- actionsArray.push(currentAction);- }- actions.current = actionsArray;- forceUpdate();- }+ entry,+ }));+ setActions(actionsArray);+ },+ [],+ );- function reflectUpdateMeta(...entries: TS.FileSystemEntry[]) {- actions.current = entries.map((fsEntry) => ({+ const reflectUpdateMeta = useCallback((...entries: TS.FileSystemEntry[]) => {+ if (!entries || entries.length === 0) {+ setActions(undefined);+ return;+ }+ const actionsArray: TS.EditAction[] = entries.map((fsEntry) => ({action: 'update',entry: fsEntry,oldEntryPath: fsEntry.path,}));- forceUpdate();- }+ setActions(actionsArray);+ }, []);- function reflectAddEntryPath(- ...entriesPromises: Promise<TS.FileSystemEntry>[]- ): Promise<boolean> {- //const entriesPromises = paths.map((path) => getAllPropertiesPromise(path));- return Promise.all(entriesPromises).then((entries) => {- const actions: TS.EditAction[] = entries- .filter((entry) => entry)- .map((entry) => ({- action: 'add',- entry: entry,- }));- if (actions.length > 0) {- setReflectActions(...actions);+ const reflectAddEntryPath = useCallback(+ async (...entriesPromises: Promise<TS.FileSystemEntry>[]) => {+ try {+ const entries = await Promise.all(entriesPromises);+ const newActions: TS.EditAction[] = entries+ .filter((e) => !!e)+ .map((entry) => ({+ action: 'add',+ entry,+ }));+ if (newActions.length > 0) {+ setActions(newActions);+ }+ return true;+ } catch (err) {+ // handle silently or rethrow depending on your error policy+ // for now return false to indicate failure+ return false;}- return true;- });- }+ },+ [],+ );/*** warning: no entry.meta will be added in reflectAddEntry. To add meta use reflectAddEntryPath@@ -110,36 +126,46 @@ export const EditedEntryContextProvider = ({* @param actionSource* @param skipSelection*/- function reflectAddEntry(- entry: TS.FileSystemEntry,- open = true,- actionSource: TS.ActionSource = 'local',- skipSelection: boolean = false,- ) {- if (!entry.tags || entry.tags.length === 0) {- entry.tags = extractTagsAsObjects(entry.name, AppConfig.tagDelimiter);- }- const currentAction: TS.EditAction = {- action: 'add',- entry: entry,- open: open,- ...(typeof actionSource !== 'boolean' && { source: actionSource }),- ...(skipSelection !== undefined && { skipSelection: skipSelection }),- };- actions.current = [currentAction];- forceUpdate();- }+ const reflectAddEntry = useCallback(+ (+ entry: TS.FileSystemEntry,+ open = true,+ actionSource: TS.ActionSource = 'local',+ skipSelection: boolean = false,+ ) => {+ if (!entry.tags || entry.tags.length === 0) {+ entry.tags = extractTagsAsObjects(entry.name, AppConfig.tagDelimiter);+ }+ const currentAction: TS.EditAction = {+ action: 'add',+ entry,+ open,+ ...(typeof actionSource !== 'boolean' && { source: actionSource }),+ ...(skipSelection !== undefined && { skipSelection }),+ };+ setActions([currentAction]);+ },+ [],+ );- const context = useMemo(() => {- return {- actions: actions.current,+ const context = useMemo(+ () => ({+ actions,reflectUpdateMeta,setReflectActions,reflectDeleteEntries,reflectAddEntryPath,reflectAddEntry,- };- }, [actions.current]);+ }),+ [+ actions,+ reflectUpdateMeta,+ setReflectActions,+ reflectDeleteEntries,+ reflectAddEntryPath,+ reflectAddEntry,+ ],+ );return (<EditedEntryContext.Provider value={context}>diff --git a/src/renderer/perspectives/common/DirectoryMenuItems.tsx b/src/renderer/perspectives/common/DirectoryMenuItems.tsxindex 5e0fcbd0c..0532c0123 100644--- a/src/renderer/perspectives/common/DirectoryMenuItems.tsx+++ b/src/renderer/perspectives/common/DirectoryMenuItems.tsx@@ -59,7 +59,11 @@ export function getDirectoryMenuItems(switchPerspective?: (perspectiveId: string) => void,showProperties?: () => void,cameraTakePicture?: () => void,- showAddRemoveTagsDialog?: () => void,+ showAddRemoveTagsDialog?: (+ entries: TS.FileSystemEntry[],+ openedEntry?: TS.FileSystemEntry,+ fileChanged?: boolean,+ ) => void,openInNewWindow?: () => void,changeFolderThumbnail?: () => void,changeFolderBackground?: () => void,@@ -419,7 +423,7 @@ export function getDirectoryMenuItems(data-tid="dirMenuAddRemoveTags"onClick={() => {onClose();- showAddRemoveTagsDialog();+ showAddRemoveTagsDialog(selectedEntries);}}><ListItemIcon>diff --git a/src/renderer/perspectives/grid/components/MainContainer.tsx b/src/renderer/perspectives/grid/components/MainContainer.tsxindex 93b034cc3..91c6fd3aa 100644--- a/src/renderer/perspectives/grid/components/MainContainer.tsx+++ b/src/renderer/perspectives/grid/components/MainContainer.tsx@@ -49,6 +49,7 @@ import { GlobalHotKeys } from 'react-hotkeys';import { useSelector } from 'react-redux';import GridCell from './GridCell';import { useReloadOnFocus } from '-/perspectives/common/useReloadOnFocus';+import { useNotificationContext } from '-/hooks/useNotificationContext';interface Props {}@@ -58,7 +59,9 @@ function GridPerspective(props: Props) {openAddRemoveTagsDialog,openMoveCopyFilesDialog,} = useMenuContext();- const { openEntry, openPrevFile, openNextFile } = useOpenedEntryContext();+ const { openEntry, openPrevFile, openNextFile, openedEntry, fileChanged } =+ useOpenedEntryContext();+ const { showNotification } = useNotificationContext();const { actions } = usePerspectiveActionsContext();const { showDirectories } = usePerspectiveSettingsContext();const { currentLocation } = useCurrentLocationContext();@@ -211,7 +214,20 @@ function GridPerspective(props: Props) {},addRemoveTags: () => {if (selectedEntries && selectedEntries.length > 0) {- openAddRemoveTagsDialog();+ if (+ openedEntry &&+ fileChanged &&+ selectedEntries &&+ selectedEntries.some((e) => e.path === openedEntry.path)+ ) {+ showNotification(+ `You can't edit tags, because '${openedEntry.path}' is opened for editing`,+ 'default',+ true,+ );+ return;+ }+ openAddRemoveTagsDialog(selectedEntries);}},renameFile: () => {@@ -221,7 +237,7 @@ function GridPerspective(props: Props) {},copyMoveSelectedEntries: () => {if (selectedEntries && selectedEntries.length > 0) {- openMoveCopyFilesDialog();+ openMoveCopyFilesDialog(selectedEntries);}},openEntry: (e) => {diff --git a/src/renderer/perspectives/grid/components/MainToolbar.tsx b/src/renderer/perspectives/grid/components/MainToolbar.tsxindex b91825715..92b20e10e 100644--- a/src/renderer/perspectives/grid/components/MainToolbar.tsx+++ b/src/renderer/perspectives/grid/components/MainToolbar.tsx@@ -53,6 +53,7 @@ import { saveAs } from 'file-saver';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';import { useMenuContext } from '-/components/dialogs/hooks/useMenuContext';+import { useNotificationContext } from '-/hooks/useNotificationContext';interface Props {prefixDataTID?: string;@@ -76,6 +77,7 @@ function MainToolbar(props: Props) {openAddRemoveTagsDialog,openShareFilesDialog,} = useMenuContext();+ const { showNotification } = useNotificationContext();const { haveLocalSetting } = usePerspectiveSettingsContext();const { openAiGenerationDialog } = useAiGenerationDialogContext();const { nativeDragModeEnabled, setNativeDragModeEnabled } =@@ -83,7 +85,7 @@ function MainToolbar(props: Props) {const { t } = useTranslation();const theme = useTheme();- const { openEntry } = useOpenedEntryContext();+ const { openEntry, openedEntry, fileChanged } = useOpenedEntryContext();const { loadParentDirectoryContent, currentDirectoryPath } =useDirectoryContentContext();const { selectedEntries } = useSelectedEntriesContext();@@ -193,7 +195,22 @@ function MainToolbar(props: Props) {keyBinding={keyBindings['addRemoveTags']}aria-label={t('core:tagSelectedEntries')}data-tid={prefixDataTID + 'PerspectiveAddRemoveTags'}- onClick={() => openAddRemoveTagsDialog(selectedEntries)}+ onClick={() => {+ if (+ openedEntry &&+ fileChanged &&+ selectedEntries &&+ selectedEntries.some((e) => e.path === openedEntry.path)+ ) {+ showNotification(+ `You can't edit tags, because '${openedEntry.path}' is opened for editing`,+ 'default',+ true,+ );+ return;+ }+ openAddRemoveTagsDialog(selectedEntries);+ }}><TagIcon /></TsToolbarButton>diff --git a/src/renderer/perspectives/list/components/MainContainer.tsx b/src/renderer/perspectives/list/components/MainContainer.tsxindex 471392e2d..563218297 100644--- a/src/renderer/perspectives/list/components/MainContainer.tsx+++ b/src/renderer/perspectives/list/components/MainContainer.tsx@@ -49,6 +49,7 @@ import { GlobalHotKeys } from 'react-hotkeys';import { useSelector } from 'react-redux';import { ListCellsStyleContextProvider } from '../hooks/ListCellsStyleProvider';import { useReloadOnFocus } from '-/perspectives/common/useReloadOnFocus';+import { useNotificationContext } from '-/hooks/useNotificationContext';interface Props {}@@ -58,7 +59,9 @@ function ListPerspective(props: Props) {openAddRemoveTagsDialog,openMoveCopyFilesDialog,} = useMenuContext();- const { openEntry, openPrevFile, openNextFile } = useOpenedEntryContext();+ const { openEntry, openPrevFile, openNextFile, openedEntry, fileChanged } =+ useOpenedEntryContext();+ const { showNotification } = useNotificationContext();const { actions } = usePerspectiveActionsContext();const { showDirectories } = usePerspectiveSettingsContext();const { currentLocation } = useCurrentLocationContext();@@ -211,7 +214,20 @@ function ListPerspective(props: Props) {},addRemoveTags: () => {if (selectedEntries && selectedEntries.length > 0) {- openAddRemoveTagsDialog();+ if (+ openedEntry &&+ fileChanged &&+ selectedEntries &&+ selectedEntries.some((e) => e.path === openedEntry.path)+ ) {+ showNotification(+ `You can't edit tags, because '${openedEntry.path}' is opened for editing`,+ 'default',+ true,+ );+ return;+ }+ openAddRemoveTagsDialog(selectedEntries);}},renameFile: () => {@@ -221,7 +237,7 @@ function ListPerspective(props: Props) {},copyMoveSelectedEntries: () => {if (selectedEntries && selectedEntries.length > 0) {- openMoveCopyFilesDialog();+ openMoveCopyFilesDialog(selectedEntries);}},openEntry: (e) => {