Skip to content

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

fix rename file from menu (#2362)

Stanimir68b9c023f44d
diff --git a/src/renderer/components/dialogs/RenameEntryDialog.tsx b/src/renderer/components/dialogs/RenameEntryDialog.tsx
index 09f982d5d..3c1b63663 100644
--- a/src/renderer/components/dialogs/RenameEntryDialog.tsx
+++ b/src/renderer/components/dialogs/RenameEntryDialog.tsx
@@ -40,6 +40,7 @@ import {
} from '@tagspaces/tagspaces-common/paths';
import React, { useReducer, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { TS } from '-/tagspaces.namespace';
interface Props {
open: boolean;
@@ -50,15 +51,13 @@ function RenameEntryDialog(props: Props) {
const { open, onClose } = props;
const { t } = useTranslation();
const { renameDirectory, renameFile } = useIOActionsContext();
- const { findLocation } = useCurrentLocationContext();
+ const { currentLocation } = useCurrentLocationContext();
const { currentDirectoryPath } = useDirectoryContentContext();
- const { selectedEntries } = useSelectedEntriesContext();
- const lastSelectedEntry = selectedEntries[selectedEntries.length - 1];
+ const { lastSelectedEntry } = useSelectedEntriesContext();
const [inputError, setInputError] = useState<boolean>(false);
const disableConfirmButton = useRef<boolean>(true);
const theme = useTheme();
const smallScreen = useMediaQuery(theme.breakpoints.down('md'));
- const currentLocation = findLocation();
let defaultName = '';
let originPath;
@@ -88,7 +87,7 @@ function RenameEntryDialog(props: Props) {
const name = useRef<string>(defaultName);
// eslint-disable-next-line no-unused-vars
- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0);
+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
const onInputFocus = (event) => {
if (name.current) {
diff --git a/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx
index 09b8d31a0..c8be91e1f 100644
--- a/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/MenuContextProvider.tsx
@@ -143,6 +143,7 @@ export const MenuContextProvider = ({ children }: MenuContextProviderProps) => {
entry: TS.FileSystemEntry,
) => {
if (entry) {
+ currentEntries.current = [entry];
if (entry.isFile) {
const currentLocation = findLocation(entry.locationID);
const dirPath = extractContainingDirectoryPath(
diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsx
index c95d3aec3..092773b08 100644
--- a/src/renderer/components/menus/FileMenu.tsx
+++ b/src/renderer/components/menus/FileMenu.tsx
@@ -184,7 +184,7 @@ function FileMenu(props: Props) {
function showMoveCopyFilesDialog() {
onClose();
- openMoveCopyFilesDialog([lastSelectedEntry]);
+ openMoveCopyFilesDialog(selectedEntries);
}
function showShareFilesDialog() {
@@ -457,20 +457,21 @@ function FileMenu(props: Props) {
);
}
menuItems.push(<Divider key={`divider-${menuItems.length}`} />);
- menuItems.push(
- <MenuItem
- key="fileMenuRenameFile"
- data-tid="fileMenuRenameFile"
- onClick={showRenameFileDialog}
- >
- <ListItemIcon>
- <RenameIcon />
- </ListItemIcon>
- <ListItemText primary={t('core:renameFile')} />
- <MenuKeyBinding keyBinding={keyBindings['renameFile']} />
- </MenuItem>,
- );
if (selectedEntries.length < 2) {
+ menuItems.push(
+ <MenuItem
+ key="fileMenuRenameFile"
+ data-tid="fileMenuRenameFile"
+ onClick={showRenameFileDialog}
+ >
+ <ListItemIcon>
+ <RenameIcon />
+ </ListItemIcon>
+ <ListItemText primary={t('core:renameFile')} />
+ <MenuKeyBinding keyBinding={keyBindings['renameFile']} />
+ </MenuItem>,
+ );
+
menuItems.push(
<MenuItem
key="fileMenuDuplicateFile"
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index e5502e968..e4b904241 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -461,7 +461,7 @@ export const DirectoryContentContextProvider = ({
function reflectSelection(actions: TS.EditAction[]) {
let updated = false;
if (actions && actions.length > 0) {
- let selected = [];
+ let selected = [...selectedEntries];
for (const action of actions) {
if (
action.source !== 'fsWatcher' &&
@@ -482,26 +482,13 @@ export const DirectoryContentContextProvider = ({
) {
selected.push(action.entry);
updated = true;
- /*if (
- !selectedEntries.some(
- (entry) => entry.path === action.entry.path,
- )
- ) {
- if (selectedEntries.length > 0) {
- selected = [...selectedEntries, action.entry];
- } else {
- selected.push(action.entry);
- }
- updated = true;
- }*/
}
} else if (action.action === 'delete') {
let index = selectedEntries.findIndex(
(e) => e.path === action.entry.path,
);
if (index !== -1) {
- selectedEntries.splice(index, 1);
- selected = [...selectedEntries];
+ selected.splice(index, 1);
updated = true;
}
} else if (action.action === 'update') {
@@ -509,8 +496,7 @@ export const DirectoryContentContextProvider = ({
(e) => e.path === action.oldEntryPath,
);
if (index !== -1) {
- selectedEntries[index] = action.entry;
- selected = [...selectedEntries];
+ selected[index] = action.entry;
updated = true;
}
}
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index d87a4b927..621f6da9c 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -695,12 +695,12 @@ export const OpenedEntryContextProvider = ({
//setOpenedTab(tabSelected, entryForOpening);
//dispatch(SettingsActions.setShowDetails(tabSelected));
}
- if (
+ /*if (
selectedEntries.length !== 1 ||
selectedEntries.some((e) => e.path !== fsEntry.path)
) {
setSelectedEntries([fsEntry]);
- }
+ }*/
if (loc.fullTextIndex && entryForOpening.extension === 'pdf') {
//extract text from pdf
loc
diff --git a/src/renderer/perspectives/grid/components/GridPagination.tsx b/src/renderer/perspectives/grid/components/GridPagination.tsx
index bb02bfcc4..4c166ab63 100644
--- a/src/renderer/perspectives/grid/components/GridPagination.tsx
+++ b/src/renderer/perspectives/grid/components/GridPagination.tsx
@@ -48,6 +48,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 { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
interface Props {
desktopMode: boolean;
@@ -64,7 +65,7 @@ interface Props {
//onContextMenu: (event: React.MouseEvent<HTMLDivElement>) => void;
onClick: (event: React.MouseEvent<HTMLDivElement>) => void;
// eslint-disable-next-line react/no-unused-prop-types
- selectedEntries; // cache only
+ //selectedEntries; // cache only
setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;
clearSelection: () => void;
}
@@ -74,9 +75,10 @@ function GridPagination(props: Props) {
const {
getCellContent,
currentDirectoryPath,
- selectedEntries,
+ //selectedEntries,
setSelectedEntries,
} = props;
+ const { selectedEntries } = useSelectedEntriesContext();
const { openDirectoryMenu, openRenameEntryDialog } = useMenuContext();
const {
showDetails,
diff --git a/src/renderer/perspectives/grid/components/MainContainer.tsx b/src/renderer/perspectives/grid/components/MainContainer.tsx
index 91c6fd3aa..32b29ca23 100644
--- a/src/renderer/perspectives/grid/components/MainContainer.tsx
+++ b/src/renderer/perspectives/grid/components/MainContainer.tsx
@@ -347,7 +347,6 @@ function GridPerspective(props: Props) {
getCellContent={getCellContent}
currentDirectoryPath={currentDirectoryPath}
onClick={onClick}
- selectedEntries={selectedEntries}
setSelectedEntries={handleSetSelectedEntries}
clearSelection={clearSelection}
/>
diff --git a/src/renderer/perspectives/list/components/MainContainer.tsx b/src/renderer/perspectives/list/components/MainContainer.tsx
index 563218297..c617a8ce8 100644
--- a/src/renderer/perspectives/list/components/MainContainer.tsx
+++ b/src/renderer/perspectives/list/components/MainContainer.tsx
@@ -347,7 +347,6 @@ function ListPerspective(props: Props) {
getCellContent={getCellContent}
currentDirectoryPath={currentDirectoryPath}
onClick={onClick}
- selectedEntries={selectedEntries}
setSelectedEntries={handleSetSelectedEntries}
clearSelection={clearSelection}
/>