TagSpaces is an offline, open source, document manager with tagging support
Close file on sucessfull move (#2002)
Stanimir60ea8aa049f0
diff --git a/app/hooks/FsActionsContextProvider.tsx b/app/hooks/FsActionsContextProvider.tsxindex 112151494..37537e95f 100644--- a/app/hooks/FsActionsContextProvider.tsx+++ b/app/hooks/FsActionsContextProvider.tsx@@ -59,7 +59,7 @@ export const FsActionsContextProvider = ({}: FsActionsContextProviderProps) => {const { t } = useTranslation();const { setSelectedEntries, selectedEntries } = useSelectedEntriesContext();- const { openedEntries, reflectRenameDirectory } = useOpenedEntryContext();+ const { openedEntries, reflectRenameOpenedEntry } = useOpenedEntryContext();const { openDirectory, currentDirectoryPath } = useDirectoryContentContext();const { reflectRenameEntry } = useLocationIndexContext();const { showNotification } = useNotificationContext();@@ -76,7 +76,7 @@ export const FsActionsContextProvider = ({.then((newDirPath) => {if (currentDirectoryPath === directoryPath) {openDirectory(newDirPath).then(() => {- reflectRenameDirectory(directoryPath, newDirPath);+ reflectRenameOpenedEntry(directoryPath, newDirPath);reflectRenameEntry(directoryPath, newDirPath);});} else {diff --git a/app/hooks/IOActionsContextProvider.tsx b/app/hooks/IOActionsContextProvider.tsxindex 3d83d85ac..3e84f4295 100644--- a/app/hooks/IOActionsContextProvider.tsx+++ b/app/hooks/IOActionsContextProvider.tsx@@ -146,7 +146,11 @@ export const IOActionsContextProvider = ({deleteFilePromise,deleteDirectoryPromise,} = usePlatformFacadeContext();- const { reflectDeleteDirectory, reflectDeleteFile } = useOpenedEntryContext();+ const {+ reflectDeleteDirectory,+ reflectDeleteFile,+ reflectRenameOpenedEntry,+ } = useOpenedEntryContext();const {currentDirectoryEntries,currentDirectoryPath,@@ -395,8 +399,9 @@ export const IOActionsContextProvider = ({joinPaths(PlatformIO.getDirSeparator(), targetPath, dirName),onProgress,)- .then(() => {+ .then((newDirPath) => {removeDirectoryEntries([path]);+ reflectRenameOpenedEntry(path, newDirPath);console.log('Moving dir from ' + path + ' to ' + targetPath);reflectDeleteEntry(path);dispatch(AppActions.reflectDeleteEntry(path));@@ -424,6 +429,10 @@ export const IOActionsContextProvider = ({return renameFilesPromise(moveJobs, onProgress).then(() => {removeDirectoryEntries(paths);+ for (let i = 0; i < moveJobs.length; i++) {+ const [srcPath, destPath] = moveJobs[i];+ reflectRenameOpenedEntry(srcPath, destPath);+ }showNotification(t('core:filesMovedSuccessful'));// moved files should be added to the index, if the target dir in indexreflectDeleteEntries(paths);diff --git a/app/hooks/OpenedEntryContextProvider.tsx b/app/hooks/OpenedEntryContextProvider.tsxindex 4fafb0489..9de83b0fd 100644--- a/app/hooks/OpenedEntryContextProvider.tsx+++ b/app/hooks/OpenedEntryContextProvider.tsx@@ -102,7 +102,7 @@ type OpenedEntryContextData = {fileType: 'md' | 'txt' | 'html',) => void;createFile: () => void;- reflectRenameDirectory: (directoryPath: string, newDirPath: string) => void;+ reflectRenameOpenedEntry: (entryPath: string, newEntryPath: string) => void;reflectDeleteDirectory: (directoryPath: string) => void;reflectDeleteFile: (filePath: string) => void;};@@ -126,7 +126,7 @@ export const OpenedEntryContext = createContext<OpenedEntryContextData>({openLink: () => {},createFile: () => {},createFileAdvanced: () => {},- reflectRenameDirectory: () => {},+ reflectRenameOpenedEntry: () => {},reflectDeleteDirectory: undefined,reflectDeleteFile: undefined,});@@ -945,12 +945,13 @@ export const OpenedEntryContextProvider = ({});}- function reflectRenameDirectory(directoryPath, newDirPath) {+ function reflectRenameOpenedEntry(entryPath, newEntryPath) {if (openedEntries && openedEntries.length > 0) {- if (openedEntries[0].path === directoryPath) {- const openedFile = openedEntries[0];- openedFile.path = newDirPath;- addToEntryContainer(openedFile);+ if (openedEntries[0].path === entryPath) {+ if (currentLocation) {+ updateHistory(currentLocation, currentDirectoryPath, newEntryPath);+ }+ addToEntryContainer({ ...openedEntries[0], path: newEntryPath });}}}@@ -1005,7 +1006,7 @@ export const OpenedEntryContextProvider = ({openLink,createFile,createFileAdvanced,- reflectRenameDirectory,+ reflectRenameOpenedEntry,reflectDeleteDirectory,reflectDeleteFile,};