Skip to content

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

Location setting for opening a file automatically on folder opening (#2134)

Stanimir71e26c3be662
diff --git a/src/renderer/components/dialogs/CreateEditLocationDialog.tsx b/src/renderer/components/dialogs/CreateEditLocationDialog.tsx
index 73a872de2..40b926a14 100644
--- a/src/renderer/components/dialogs/CreateEditLocationDialog.tsx
+++ b/src/renderer/components/dialogs/CreateEditLocationDialog.tsx
@@ -39,7 +39,6 @@ import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
import ToggleButton from '@mui/material/ToggleButton';
import CheckIcon from '@mui/icons-material/Check';
import RemoveIcon from '@mui/icons-material/RemoveCircleOutline';
-import IdIcon from '@mui/icons-material/Abc';
import InputAdornment from '@mui/material/InputAdornment';
import IconButton from '@mui/material/IconButton';
import { useSelector, useDispatch } from 'react-redux';
@@ -67,7 +66,7 @@ import WebdavForm from '-/components/dialogs/WebdavForm';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
-import { ExpandIcon } from '-/components/CommonIcons';
+import { ExpandIcon, IDIcon, FolderIcon } from '-/components/CommonIcons';
import MaxLoopsSelect from '-/components/dialogs/MaxLoopsSelect';
import { useTranslation } from 'react-i18next';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
@@ -218,6 +217,9 @@ function CreateEditLocationDialog(props: Props) {
const [newuuid, setNewUuid] = useState<string>(
selectedLocation ? selectedLocation.uuid : getUuid(),
);
+ const [autoOpenedFilename, setAutoOpenedFilename] = useState<string>(
+ selectedLocation ? selectedLocation.autoOpenedFilename : undefined,
+ );
const [cloudErrorTextName, setCloudErrorTextName] = useState<boolean>(false);
const [webdavErrorUrl, setWebdavErrorUrl] = useState<boolean>(false);
const [cloudErrorAccessKey, setCloudErrorAccessKey] =
@@ -391,6 +393,7 @@ function CreateEditLocationDialog(props: Props) {
watchForChanges,
maxIndexAge,
ignorePatternPaths,
+ autoOpenedFilename,
};
} else if (type === locationType.TYPE_WEBDAV) {
loc = {
@@ -410,6 +413,7 @@ function CreateEditLocationDialog(props: Props) {
watchForChanges,
maxIndexAge,
ignorePatternPaths,
+ autoOpenedFilename,
};
} else if (type === locationType.TYPE_CLOUD) {
loc = {
@@ -433,6 +437,7 @@ function CreateEditLocationDialog(props: Props) {
maxIndexAge,
maxLoops,
ignorePatternPaths,
+ autoOpenedFilename,
};
}
if (persistTagsInSidecarFile !== null) {
@@ -693,7 +698,7 @@ function CreateEditLocationDialog(props: Props) {
label={
<>
{t('core:watchForChangesInLocation')}
- {Pro ? <BetaLabel /> : <ProLabel />}
+ {!Pro && <ProLabel />}
</>
}
/>
@@ -737,7 +742,7 @@ function CreateEditLocationDialog(props: Props) {
}}
size="large"
>
- <IdIcon />
+ <IDIcon />
</IconButton>
</Tooltip>
</InputAdornment>
@@ -745,6 +750,22 @@ function CreateEditLocationDialog(props: Props) {
}}
/>
</FormControl>
+ <FormControl fullWidth={true}>
+ <TextField
+ margin="dense"
+ name="autoOpenedFilename"
+ fullWidth={true}
+ data-tid="autoOpenedFilenameTID"
+ placeholder={
+ t('core:forExample') + ': index.md, index.html or readme.md'
+ }
+ onChange={(event) =>
+ setAutoOpenedFilename(event.target.value)
+ }
+ value={autoOpenedFilename}
+ label={t('core:autoOpenedFilename')}
+ />
+ </FormControl>
<FormControlLabel
className={classes.formControl}
labelPlacement="start"
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index f5b791c79..36a201beb 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -267,18 +267,24 @@ export const OpenedEntryContextProvider = ({
}
}, [metaActions]);
- /*useEffect(() => {
+ useEffect(() => {
if (
- currentEntry.current &&
- currentEntry.current.path === currentDirectoryPath
+ currentLocation &&
+ currentLocation.autoOpenedFilename &&
+ currentLocation.autoOpenedFilename.length > 0
) {
- currentEntry.current = {
- ...currentEntry.current,
- perspective: currentDirectoryPerspective,
- };
- forceUpdate();
+ const autoOpenedFilePath = joinPaths(
+ currentLocation?.getDirSeparator(),
+ currentDirectoryPath,
+ currentLocation.autoOpenedFilename,
+ );
+ currentLocation.checkFileExist(autoOpenedFilePath).then((exist) => {
+ if (exist) {
+ openEntry(autoOpenedFilePath);
+ }
+ });
}
- }, [currentDirectoryPerspective]);*/
+ }, [currentDirectoryPath]);
function openNextFile(entries: TS.FileSystemEntry[]): TS.FileSystemEntry {
const nextFile = getNextFile(
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index 916d6ebf0..1978f35cc 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -826,6 +826,8 @@
"filenameTagPlacedAtEnd": "Filename End",
"fileNameBeginTagPlaceExplanation": "Tags will be placed at the beginning of the filename, like this '[tag1 tag2] filename.ext'",
"fileNameEndTagPlaceExplanation": "Tags will be placed at end of the filename, like this 'filename [tag1 tag2].ext'",
+ "autoOpenedFilename": "File to be opened on navigation to a folder",
+ "forExample": "For example",
"entryId": "Entry ID",
"copyIdToClipboard": "Copy entry ID to the clipboard",
"entryIdCopied": "Entry ID copied",
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index 313da013c..6a06af690 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -45,6 +45,7 @@ export namespace TS {
maxLoops?: number;
persistTagsInSidecarFile?: boolean;
ignorePatternPaths?: Array<string>;
+ autoOpenedFilename?: string;
}
interface S3Location extends Location {
diff --git a/src/renderer/utils/CommonLocation.ts b/src/renderer/utils/CommonLocation.ts
index a06199ab3..55adbffd8 100644
--- a/src/renderer/utils/CommonLocation.ts
+++ b/src/renderer/utils/CommonLocation.ts
@@ -54,6 +54,7 @@ export class CommonLocation implements TS.Location {
bucketName?: string;
region?: string;
endpointURL?: string;
+ autoOpenedFilename?: string;
ioAPI?: any; //AWS.S3; //common API for IO operations interface
urlCache = {};
@@ -84,6 +85,7 @@ export class CommonLocation implements TS.Location {
this.maxLoops = location.maxLoops;
this.persistTagsInSidecarFile = location.persistTagsInSidecarFile;
this.ignorePatternPaths = location.ignorePatternPaths;
+ this.autoOpenedFilename = location.autoOpenedFilename;
if (location.type === locationType.TYPE_CLOUD) {
this.accessKeyId = (location as TS.S3Location).accessKeyId;
this.secretAccessKey = (location as TS.S3Location).secretAccessKey;