Skip to content

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

Add folder ignore patterns for navigation, indexing and watching (#1440)

Stanimireb68b7768bc0
diff --git a/app/components/dialogs/CreateEditLocationDialog.tsx b/app/components/dialogs/CreateEditLocationDialog.tsx
index 3de1c0348..c28ac6a15 100644
--- a/app/components/dialogs/CreateEditLocationDialog.tsx
+++ b/app/components/dialogs/CreateEditLocationDialog.tsx
@@ -34,6 +34,10 @@ import Radio from '@material-ui/core/Radio';
import RadioGroup from '@material-ui/core/RadioGroup';
import Tooltip from '@material-ui/core/Tooltip';
import Dialog from '@material-ui/core/Dialog';
+import List from '@material-ui/core/List';
+import ListItem from '@material-ui/core/ListItem';
+import ListItemIcon from '@material-ui/core/ListItemIcon';
+import ListItemText from '@material-ui/core/ListItemText';
import Input from '@material-ui/core/Input';
import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';
import ToggleButton from '@material-ui/lab/ToggleButton';
@@ -41,6 +45,8 @@ import IconButton from '@material-ui/core/IconButton';
import CloseIcon from '@material-ui/icons/Close';
import CheckIcon from '@material-ui/icons/Check';
import InfoIcon from '@material-ui/icons/InfoOutlined';
+import AddIcon from '@material-ui/icons/AddCircleOutline';
+import RemoveIcon from '@material-ui/icons/RemoveCircleOutline';
import i18n from '-/services/i18n';
import { Pro } from '-/pro';
import ObjectStoreForm from './ObjectStoreForm';
@@ -49,10 +55,13 @@ import useFirstRender from '-/utils/useFirstRender';
import AppConfig from '-/config';
import { TS } from '-/tagspaces.namespace';
import { locationType } from '-/utils/misc';
+import { getLocationPath } from '-/utils/paths';
+import IgnorePatternDialog from '-/components/dialogs/IgnorePatternDialog';
const styles: any = theme => ({
formControl: {
- marginLeft: theme.spacing(0)
+ marginLeft: theme.spacing(0),
+ width: '100%'
}
});
@@ -155,6 +164,14 @@ const CreateEditLocationDialog = (props: Props) => {
boolean
>(false);
+ const [ignorePatternPaths, setIgnorePatternPaths] = useState<Array<string>>(
+ location ? location.ignorePatternPaths : undefined
+ );
+
+ const [isIgnorePatternDialogOpen, setIgnorePatternDialogOpen] = useState<
+ boolean
+ >(false);
+
const firstRender = useFirstRender();
function changeMaxIndexAge(ageInMinutes) {
@@ -253,7 +270,8 @@ const CreateEditLocationDialog = (props: Props) => {
persistIndex,
fullTextIndex,
watchForChanges,
- maxIndexAge
+ maxIndexAge,
+ ignorePatternPaths
};
} else if (type === locationType.TYPE_CLOUD) {
loc = {
@@ -273,7 +291,8 @@ const CreateEditLocationDialog = (props: Props) => {
persistIndex,
fullTextIndex,
watchForChanges: false,
- maxIndexAge
+ maxIndexAge,
+ ignorePatternPaths
};
}
if (persistTagsInSidecarFile !== null) {
@@ -365,9 +384,10 @@ const CreateEditLocationDialog = (props: Props) => {
event.preventDefault();
event.stopPropagation();
onConfirm();
- } else if (event.key === 'Escape') {
- onClose();
}
+ // } else if (event.key === 'Escape') {
+ // onClose();
+ // }
}}
>
<DialogTitle>
@@ -524,143 +544,197 @@ const CreateEditLocationDialog = (props: Props) => {
}
/>
)}
- {showAdvancedMode && (
+ </FormGroup>
+ {showAdvancedMode && (
+ <FormControlLabel
+ className={classes.formControl}
+ labelPlacement="start"
+ style={{ justifyContent: 'space-between' }}
+ control={
+ <Input
+ name="maxIndexAge"
+ style={{
+ maxWidth: 70,
+ marginLeft: 15,
+ marginBottom: 15
+ }}
+ type="number"
+ data-tid="maxIndexAgeTID"
+ inputProps={{ min: 0 }}
+ value={maxIndexAge / (1000 * 60)}
+ onChange={event => changeMaxIndexAge(event.target.value)}
+ />
+ }
+ label={
+ <Tooltip arrow title={i18n.t('core:maxIndexAgeHelp')}>
+ <Typography>{i18n.t('core:maxIndexAge')}</Typography>
+ </Tooltip>
+ }
+ />
+ )}
+ {showAdvancedMode &&
+ (AppConfig.useSidecarsForFileTaggingDisableSetting ? (
<FormControlLabel
className={classes.formControl}
labelPlacement="start"
style={{ justifyContent: 'space-between' }}
control={
- <Tooltip title={i18n.t('core:maxIndexAgeHelp')}>
- <Input
- name="maxIndexAge"
- style={{
- maxWidth: 70,
- marginLeft: 15,
- marginRight: 15,
- marginBottom: 15
- }}
- type="number"
- data-tid="maxIndexAgeTID"
- inputProps={{ min: 0 }}
- value={maxIndexAge / (1000 * 60)}
- onChange={event => changeMaxIndexAge(event.target.value)}
- />
- </Tooltip>
+ <Button size="small" variant="outlined" disabled>
+ {currentTagsSetting ? 'Use Sidecar Files' : 'Rename Files'}
+ </Button>
+ }
+ label={
+ <Typography variant="caption" display="block" gutterBottom>
+ {i18n.t('core:fileTaggingSetting')}
+ </Typography>
}
- label={i18n.t('core:maxIndexAge')}
/>
- )}
- {showAdvancedMode &&
- (AppConfig.useSidecarsForFileTaggingDisableSetting ? (
- <FormControlLabel
- className={classes.formControl}
- labelPlacement="start"
- style={{ justifyContent: 'space-between' }}
- control={
- <Button size="small" variant="outlined" disabled>
- {currentTagsSetting ? 'Use Sidecar Files' : 'Rename Files'}
- </Button>
- }
- label={
- <Typography variant="caption" display="block" gutterBottom>
- {i18n.t('core:fileTaggingSetting')}
- </Typography>
- }
- />
- ) : (
- <FormControlLabel
- labelPlacement="top"
- className={classes.formControl}
- style={{ alignItems: 'start' }}
- control={
- <ToggleButtonGroup
- value={persistTagsInSidecarFile}
- size="small"
- exclusive
+ ) : (
+ <FormControlLabel
+ labelPlacement="top"
+ className={classes.formControl}
+ style={{ alignItems: 'start' }}
+ control={
+ <ToggleButtonGroup
+ value={persistTagsInSidecarFile}
+ size="small"
+ exclusive
+ >
+ <ToggleButton
+ value={null}
+ data-tid="settingsSetPersistTagsDefault"
+ onClick={() => setPersistTagsInSidecarFile(null)}
>
- <ToggleButton
- value={null}
- data-tid="settingsSetPersistTagsDefault"
- onClick={() => setPersistTagsInSidecarFile(null)}
+ <Tooltip
+ arrow
+ title={
+ <Typography color="inherit">
+ Use the default settings for saving the tags:{' '}
+ <b>
+ {currentTagsSetting
+ ? 'Use Sidecar Files'
+ : 'Rename Files'}
+ </b>
+ </Typography>
+ }
>
- <Tooltip
- arrow
- title={
- <Typography color="inherit">
- Use the default settings for saving the tags:{' '}
- <b>
- {currentTagsSetting
- ? 'Use Sidecar Files'
- : 'Rename Files'}
- </b>
- </Typography>
- }
- >
- <div style={{ display: 'flex' }}>
- {persistTagsInSidecarFile === null && <CheckIcon />}
- &nbsp;{i18n.t('core:default')}&nbsp;&nbsp;
- <InfoIcon />
- </div>
- </Tooltip>
- </ToggleButton>
- <ToggleButton
- value={false}
- data-tid="settingsSetPersistTagsInFileName"
- onClick={() => setPersistTagsInSidecarFile(false)}
+ <div style={{ display: 'flex' }}>
+ {persistTagsInSidecarFile === null && <CheckIcon />}
+ &nbsp;{i18n.t('core:default')}&nbsp;&nbsp;
+ <InfoIcon />
+ </div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton
+ value={false}
+ data-tid="settingsSetPersistTagsInFileName"
+ onClick={() => setPersistTagsInSidecarFile(false)}
+ >
+ <Tooltip
+ arrow
+ title={
+ <Typography color="inherit">
+ Use the name of file for saving the tags - Tagging the
+ file <b>image.jpg</b> with a tag <b>sunset</b> will
+ rename it to <b>image[sunset].jpg</b>
+ </Typography>
+ }
>
- <Tooltip
- arrow
- title={
- <Typography color="inherit">
- Use the name of file for saving the tags - Tagging
- the file <b>image.jpg</b> with a tag <b>sunset</b>{' '}
- will rename it to <b>image[sunset].jpg</b>
- </Typography>
- }
- >
- <div style={{ display: 'flex' }}>
- {persistTagsInSidecarFile !== null &&
- !persistTagsInSidecarFile && <CheckIcon />}
- &nbsp;Rename Files&nbsp;&nbsp;
- <InfoIcon />
- </div>
- </Tooltip>
- </ToggleButton>
- <ToggleButton
- value={true}
- data-tid="settingsSetPersistTagsInSidecarFile"
- onClick={() => setPersistTagsInSidecarFile(true)}
+ <div style={{ display: 'flex' }}>
+ {persistTagsInSidecarFile !== null &&
+ !persistTagsInSidecarFile && <CheckIcon />}
+ &nbsp;Rename Files&nbsp;&nbsp;
+ <InfoIcon />
+ </div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton
+ value={true}
+ data-tid="settingsSetPersistTagsInSidecarFile"
+ onClick={() => setPersistTagsInSidecarFile(true)}
+ >
+ <Tooltip
+ arrow
+ title={
+ <Typography color="inherit">
+ Use sidecar file for saving the tags - Tagging the
+ file <b>image.jpg</b> with a tag <b>sunset</b> will
+ save this tag in an additional sidecar file called{' '}
+ <b>image.jpg.json</b> located in a sub folder with the
+ name <b>.ts</b>
+ </Typography>
+ }
>
- <Tooltip
- arrow
- title={
- <Typography color="inherit">
- Use sidecar file for saving the tags - Tagging the
- file <b>image.jpg</b> with a tag <b>sunset</b> will
- save this tag in an additional sidecar file called{' '}
- <b>image.jpg.json</b> located in a sub folder with
- the name <b>.ts</b>
- </Typography>
+ <div style={{ display: 'flex' }}>
+ {persistTagsInSidecarFile !== null &&
+ persistTagsInSidecarFile && <CheckIcon />}
+ &nbsp;Use Sidecar Files&nbsp;&nbsp;
+ <InfoIcon />
+ </div>
+ </Tooltip>
+ </ToggleButton>
+ </ToggleButtonGroup>
+ }
+ label={
+ <Typography variant="caption" display="block" gutterBottom>
+ {i18n.t('core:fileTaggingSetting')}
+ </Typography>
+ }
+ />
+ ))}
+ {showAdvancedMode && (
+ <>
+ <Typography
+ variant="caption"
+ display="block"
+ gutterBottom
+ style={{ marginTop: 10 }}
+ >
+ {i18n.t('core:ignorePatterns')}
+ </Typography>
+ <List style={{ padding: 0 }} dense>
+ {ignorePatternPaths &&
+ ignorePatternPaths.map(ignorePatternPath => (
+ <ListItem style={{ padding: 0 }}>
+ <ListItemText primary={ignorePatternPath} />
+ <ListItemIcon
+ style={{ minWidth: 0 }}
+ title={i18n.t('core:ignorePatternRemove')}
+ onClick={() => {
+ const array = [...ignorePatternPaths];
+ const index = array.indexOf(ignorePatternPath);
+ if (index !== -1) {
+ array.splice(index, 1);
+ setIgnorePatternPaths(array);
}
- >
- <div style={{ display: 'flex' }}>
- {persistTagsInSidecarFile !== null &&
- persistTagsInSidecarFile && <CheckIcon />}
- &nbsp;Use Sidecar Files&nbsp;&nbsp;
- <InfoIcon />
- </div>
- </Tooltip>
- </ToggleButton>
- </ToggleButtonGroup>
- }
- label={
- <Typography variant="caption" display="block" gutterBottom>
- {i18n.t('core:fileTaggingSetting')}
- </Typography>
- }
+ }}
+ >
+ <RemoveIcon />
+ </ListItemIcon>
+ </ListItem>
+ ))}
+ </List>
+ <Button
+ endIcon={<AddIcon />}
+ color="primary"
+ size="small"
+ onClick={() => {
+ setIgnorePatternDialogOpen(true);
+ }}
+ >
+ {i18n.t('ignorePatternDialogTitle')}
+ </Button>
+ {isIgnorePatternDialogOpen && (
+ <IgnorePatternDialog
+ open={isIgnorePatternDialogOpen}
+ onClose={() => setIgnorePatternDialogOpen(false)}
+ ignorePatternPaths={ignorePatternPaths}
+ setIgnorePatternPaths={setIgnorePatternPaths}
+ locationPath={getLocationPath(location)}
/>
- ))}
- </FormGroup>
+ )}
+ </>
+ )}
</DialogContent>
<DialogActions style={{ justifyContent: 'space-between' }}>
<Button
diff --git a/app/components/dialogs/CreateFileDialog.tsx b/app/components/dialogs/CreateFileDialog.tsx
index 71801abe5..a026235f6 100644
--- a/app/components/dialogs/CreateFileDialog.tsx
+++ b/app/components/dialogs/CreateFileDialog.tsx
@@ -137,7 +137,6 @@ const CreateFileDialog = (props: Props) => {
if (name === 'fileName') {
setFileName(value);
- setFileName(value);
} else if (name === 'fileContent') {
fileContent.current = value;
} else if (name === 'selectedDirectoryPath') {
@@ -272,7 +271,7 @@ const CreateFileDialog = (props: Props) => {
name="selectedDirectoryPath"
fullWidth={true}
data-tid="createFileDialog_filePath"
- value={selectedDirectoryPath}
+ value={selectedDirectoryPath.current}
onChange={handleFileChange}
endAdornment={
PlatformIO.haveObjectStoreSupport() ? (
diff --git a/app/components/dialogs/IgnorePatternDialog.tsx b/app/components/dialogs/IgnorePatternDialog.tsx
new file mode 100644
index 000000000..8e734d529
--- /dev/null
+++ b/app/components/dialogs/IgnorePatternDialog.tsx
@@ -0,0 +1,186 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * 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, { useState } from 'react';
+import Button from '@material-ui/core/Button';
+import { withStyles } from '@material-ui/core/styles';
+import withMobileDialog from '@material-ui/core/withMobileDialog';
+import DialogActions from '@material-ui/core/DialogActions';
+import DialogContent from '@material-ui/core/DialogContent';
+import DialogTitle from '@material-ui/core/DialogTitle';
+import FormControl from '@material-ui/core/FormControl';
+import Dialog from '@material-ui/core/Dialog';
+import Input from '@material-ui/core/Input';
+import AddIcon from '@material-ui/icons/Add';
+import InputLabel from '@material-ui/core/InputLabel';
+import InputAdornment from '@material-ui/core/InputAdornment';
+import IconButton from '@material-ui/core/IconButton';
+import FolderIcon from '@material-ui/icons/FolderOpen';
+import FormHelperText from '@material-ui/core/FormHelperText';
+import i18n from '-/services/i18n';
+import PlatformIO from '-/services/platform-io';
+import useValidation from '-/utils/useValidation';
+
+const styles: any = theme => ({
+ root: {
+ display: 'flex'
+ },
+ formControl: {
+ margin: theme.spacing(3)
+ },
+ group: {
+ margin: theme.spacing(1, 0),
+ display: 'flex',
+ flexDirection: 'row'
+ }
+});
+
+interface Props {
+ locationPath: string;
+ open: boolean;
+ onClose: () => void;
+ ignorePatternPaths: Array<string>;
+ setIgnorePatternPaths: (pattern: Array<string>) => void;
+}
+
+const CreateEditLocationDialog = (props: Props) => {
+ const { setError, haveError } = useValidation();
+ const [selectedDirectoryPath, setSelectedDirectoryPath] = useState<string>(
+ ''
+ );
+
+ const { open, onClose } = props;
+
+ const onConfirm = () => {
+ if (selectedDirectoryPath) {
+ if (!props.ignorePatternPaths || props.ignorePatternPaths.length === 0) {
+ props.setIgnorePatternPaths([selectedDirectoryPath]);
+ } else if (
+ props.ignorePatternPaths.indexOf(selectedDirectoryPath) === -1
+ ) {
+ props.setIgnorePatternPaths([
+ ...props.ignorePatternPaths,
+ selectedDirectoryPath
+ ]);
+ }
+ }
+ props.onClose();
+ };
+
+ const openFolderChooser = () => {
+ PlatformIO.selectDirectoryDialog()
+ .then(selectedPaths => {
+ setSelectedDirectoryPath(
+ selectedPaths[0].replace(props.locationPath, '**') + '/**'
+ );
+ if (selectedPaths[0].startsWith(props.locationPath)) {
+ setError('pathNotInCurrentLocation', false);
+ } else {
+ setError('pathNotInCurrentLocation');
+ }
+ return true;
+ })
+ .catch(err => {
+ console.log('selectDirectoryDialog failed with: ' + err);
+ });
+ };
+
+ const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
+ const { target } = event;
+ const { value } = target;
+
+ setSelectedDirectoryPath(value);
+ setError('pathNotInCurrentLocation', false);
+ };
+
+ return (
+ <Dialog
+ open={open}
+ onClose={onClose}
+ keepMounted
+ scroll="paper"
+ onKeyDown={event => {
+ if (event.key === 'Enter' || event.keyCode === 13) {
+ event.preventDefault();
+ event.stopPropagation();
+ onConfirm();
+ } else if (event.key === 'Escape') {
+ onClose();
+ }
+ }}
+ >
+ <DialogTitle>{i18n.t('core:ignorePatternDialogTitle')}</DialogTitle>
+ <DialogContent>
+ <FormControl
+ fullWidth={true}
+ error={haveError('pathNotInCurrentLocation')}
+ >
+ <InputLabel htmlFor="ignorePatternPath">
+ {i18n.t('core:ignorePatternPath')}
+ </InputLabel>
+ <Input
+ error={haveError('pathNotInCurrentLocation')}
+ margin="dense"
+ name="ignorePatternPath"
+ placeholder={i18n.t('core:ignorePatternPlaceholder')}
+ fullWidth={true}
+ data-tid="ignorePatternPathTID"
+ onChange={handleFileChange}
+ value={selectedDirectoryPath}
+ endAdornment={
+ PlatformIO.haveObjectStoreSupport() ? (
+ undefined
+ ) : (
+ <InputAdornment position="end" style={{ height: 32 }}>
+ <IconButton onClick={openFolderChooser}>
+ <FolderIcon />
+ </IconButton>
+ </InputAdornment>
+ )
+ }
+ />
+ {haveError('pathNotInCurrentLocation') && (
+ <FormHelperText>
+ {i18n.t('core:pathNotInCurrentLocation')}
+ </FormHelperText>
+ )}
+ <FormHelperText>
+ {
+ "Wildcards (**, *.js)\nNegation ('!a/*.js', '*!(b).js'])\nextglobs (+(x|y), !(a|b))\nPOSIX character classes ([[:alpha:][:digit:]])\nbrace expansion (foo/{1..5}.md, bar/{a,b,c}.js)\nregex character classes (foo-[1-5].js)\nregex logical \"or\" (foo/(abc|xyz).js)\nYou can mix and match these features to create whatever patterns you need!"
+ }
+ </FormHelperText>
+ </FormControl>
+ </DialogContent>
+ <DialogActions>
+ <Button onClick={() => onClose()} color="primary">
+ {i18n.t('core:cancel')}
+ </Button>
+ <Button
+ disabled={selectedDirectoryPath.length === 0 || haveError()}
+ onClick={onConfirm}
+ data-tid="confirmLocationCreation"
+ color="primary"
+ >
+ {i18n.t('core:ok')}
+ </Button>
+ </DialogActions>
+ </Dialog>
+ );
+};
+
+export default withMobileDialog()(withStyles(styles)(CreateEditLocationDialog));
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index e2d1cdf92..93f6a8b55 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -573,5 +573,11 @@
"noSubFoldersFound": "No sub folders in the current folder",
"fileTaggingSetting": "File tagging method",
"default": "Default",
+ "ignorePatterns": "Ignore patterns",
+ "ignorePatternPath": "Path to ignore pattern folder",
+ "ignorePatternPlaceholder": "Ignore pattern",
+ "ignorePatternDialogTitle": "Add Ignore Pattern",
+ "ignorePatternRemove": "Remove ignore pattern",
+ "pathNotInCurrentLocation": "Ignore pattern path is not in the current location",
"-": "-"
}
diff --git a/app/main.dev.ts b/app/main.dev.ts
index 23ef792ae..6c6b8df29 100644
--- a/app/main.dev.ts
+++ b/app/main.dev.ts
@@ -190,7 +190,7 @@ app.on('ready', async () => {
throw new Error('"mainWindow" is not defined');
}
// mainWindow.show();
- (global as any).splashWorkerWindow.hide(); // Comment for easy debugging of the worker
+ (global as any).splashWorkerWindow.hide(); // Comment for easy debugging of the worker (global as any).splashWorkerWindow.show();
if (portableMode) {
mainWindow.setTitle(mainWindow.title + ' Portable 🔌');
}
diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsx
index d802f276b..0602bda82 100644
--- a/app/perspectives/grid-perspective/components/CellContent.tsx
+++ b/app/perspectives/grid-perspective/components/CellContent.tsx
@@ -152,6 +152,7 @@ const CellContent = (props: Props) => {
height: 150 // fsEntry.isFile ? 150 : 70
}}
>
+ {fsEntry.isIgnored && <span>Ignored</span>}
{fsEntry.thumbPath ? (
<img
alt="thumbnail"
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 66f7b61b2..702300b29 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -929,7 +929,16 @@ export const actions = {
} */
// dispatch(actions.setCurrentDirectoryColor('')); // this is to reset color only
dispatch(actions.showNotification(i18n.t('core:loading'), 'info', false));
- PlatformIO.listDirectoryPromise(directoryPath, false)
+ const currentLocation: TS.Location = getLocation(
+ getState(),
+ getState().app.currentLocationId
+ );
+ PlatformIO.listDirectoryPromise(
+ directoryPath,
+ false,
+ true,
+ currentLocation ? currentLocation.ignorePatternPaths : []
+ )
.then(results => {
if (results !== undefined) {
prepareDirectoryContent(
diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.ts
index 85542f03b..49a349912 100644
--- a/app/reducers/location-index.ts
+++ b/app/reducers/location-index.ts
@@ -186,10 +186,11 @@ export const actions = {
createDirectoryIndex: (
directoryPath: string,
extractText: boolean,
- isCurrentLocation: boolean = true
+ isCurrentLocation: boolean = true,
+ ignorePatterns: Array<string> = []
) => (dispatch: (actions: Object) => void) => {
dispatch(actions.startDirectoryIndexing());
- createDirectoryIndex(directoryPath, extractText)
+ createDirectoryIndex(directoryPath, extractText, ignorePatterns)
.then(directoryIndex => {
if (isCurrentLocation) {
// Load index only if current location
@@ -216,32 +217,30 @@ export const actions = {
const state = getState();
dispatch(actions.startDirectoryIndexing());
const allLocations = getLocations(state);
- const locationPaths = [];
- allLocations.forEach(location => {
- locationPaths.push(getLocationPath(location));
+
+ const promises = allLocations.map(location => {
+ const nextPath = getLocationPath(location);
+ return createDirectoryIndex(
+ nextPath,
+ extractText,
+ location.ignorePatternPaths
+ )
+ .then(directoryIndex => {
+ if (Pro && Pro.Indexer) {
+ Pro.Indexer.persistIndex(
+ nextPath,
+ directoryIndex,
+ PlatformIO.getDirSeparator()
+ );
+ }
+ return true;
+ })
+ .catch(err => {
+ dispatch(actions.indexDirectoryFailure(err));
+ });
});
- const result = locationPaths.reduce(
- (accumulatorPromise, nextPath) =>
- accumulatorPromise.then(() =>
- createDirectoryIndex(nextPath, extractText)
- .then(directoryIndex => {
- if (Pro && Pro.Indexer) {
- Pro.Indexer.persistIndex(
- nextPath,
- directoryIndex,
- PlatformIO.getDirSeparator()
- );
- }
- return true;
- })
- .catch(err => {
- dispatch(actions.indexDirectoryFailure(err));
- })
- ),
- Promise.resolve()
- );
- result
+ Promise.all(promises)
.then(e => {
dispatch(actions.indexDirectorySuccess());
console.log('Resolution is complete!', e);
@@ -338,7 +337,8 @@ export const actions = {
} else {
GlobalSearch.index = await createDirectoryIndex(
currentPath,
- currentLocation.fullTextIndex
+ currentLocation.fullTextIndex,
+ currentLocation.ignorePatternPaths
);
if (Pro && Pro.Indexer && Pro.Indexer.persistIndex) {
Pro.Indexer.persistIndex(
@@ -443,7 +443,8 @@ export const actions = {
console.log('Creating index for : ' + nextPath);
directoryIndex = await createDirectoryIndex(
nextPath,
- location.fullTextIndex
+ location.fullTextIndex,
+ location.ignorePatternPaths
);
if (Pro && Pro.Indexer && Pro.Indexer.persistIndex) {
Pro.Indexer.persistIndex(
diff --git a/app/services/electron-io.ts b/app/services/electron-io.ts
index 309102aca..c61ef3f3e 100644
--- a/app/services/electron-io.ts
+++ b/app/services/electron-io.ts
@@ -18,6 +18,7 @@
import fsextra from 'fs-extra';
import pathLib from 'path';
import winattr from 'winattr';
+import micromatch from 'micromatch';
import {
extractFileExtension,
extractFileName,
@@ -222,7 +223,8 @@ export default class ElectronIO {
createDirectoryIndexInWorker = (
directoryPath: string,
- extractText: boolean
+ extractText: boolean,
+ ignorePatterns: Array<string>
): Promise<any> =>
new Promise((resolve, reject) => {
if (this.isWorkerAvailable()) {
@@ -231,7 +233,8 @@ export default class ElectronIO {
id: timestamp,
action: 'createDirectoryIndex',
path: directoryPath,
- extractText
+ extractText,
+ ignorePatterns
});
this.ipcRenderer.once(timestamp, (event, data) => {
// console.log('Answer from worker recieved ' + data.result);
@@ -265,7 +268,9 @@ export default class ElectronIO {
listDirectoryPromise = (
path: string,
lite: boolean = true,
- extractTextContent: boolean = false
+ extractTextContent: boolean = false,
+ ignorePatterns: Array<string> = [],
+ showIgnored: boolean = true
): Promise<Array<Object>> =>
new Promise(resolve => {
const enhancedEntries = [];
@@ -292,6 +297,16 @@ export default class ElectronIO {
}
if (entries) {
+ if (!showIgnored && ignorePatterns.length > 0) {
+ // eslint-disable-next-line no-param-reassign
+ entries = entries.filter(
+ entry =>
+ !micromatch.isMatch(
+ path + AppConfig.dirSeparator + entry,
+ ignorePatterns
+ )
+ );
+ }
entries.forEach(entry => {
entryPath = path + AppConfig.dirSeparator + entry;
eentry = {};
@@ -300,6 +315,12 @@ export default class ElectronIO {
eentry.tags = [];
eentry.thumbPath = '';
eentry.meta = {};
+ if (
+ ignorePatterns.length > 0 &&
+ micromatch.isMatch(entryPath, ignorePatterns) // { basename: true })
+ ) {
+ eentry.isIgnored = true;
+ }
try {
stats = this.fs.statSync(entryPath);
diff --git a/app/services/platform-io.ts b/app/services/platform-io.ts
index fc7335975..73dda20a3 100644
--- a/app/services/platform-io.ts
+++ b/app/services/platform-io.ts
@@ -132,9 +132,14 @@ export default class PlatformIO {
static createDirectoryIndexInWorker = (
directoryPath: string,
- extractText: boolean
+ extractText: boolean,
+ ignorePatterns: Array<string>
): Promise<any> =>
- nativeAPI.createDirectoryIndexInWorker(directoryPath, extractText);
+ nativeAPI.createDirectoryIndexInWorker(
+ directoryPath,
+ extractText,
+ ignorePatterns
+ );
static createThumbnailsInWorker = (
tmbGenerationList: Array<string>
@@ -145,16 +150,23 @@ export default class PlatformIO {
* @param path
* @param lite
* @param extractText
+ * @param ignorePatterns
*/
static listDirectoryPromise = (
path: string,
lite: boolean = true,
- extractText: boolean = true
+ extractText: boolean = true,
+ ignorePatterns: Array<string> = []
): Promise<Array<any>> => {
if (objectStoreAPI) {
return objectStoreAPI.listDirectoryPromise(path, lite);
}
- return nativeAPI.listDirectoryPromise(path, lite, extractText);
+ return nativeAPI.listDirectoryPromise(
+ path,
+ lite,
+ extractText,
+ ignorePatterns
+ );
};
static getPropertiesPromise = (path: string): Promise<any> => {
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 0dadd9722..e79bd4d01 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -18,6 +18,7 @@
import uuidv1 from 'uuid';
import { saveAs } from 'file-saver';
+import micromatch from 'micromatch';
import PlatformIO from './platform-io';
import AppConfig from '../config';
import {
@@ -128,7 +129,8 @@ export function enhanceEntry(entry: any): TS.FileSystemEntry {
tags: [...sidecarTags, ...fileNameTags],
size: entry.size,
lmdt: entry.lmdt,
- path: entry.path
+ path: entry.path,
+ isIgnored: entry.isIgnored
};
if (sidecarDescription) {
enhancedEntry.description = sidecarDescription;
@@ -377,12 +379,17 @@ export function getPrevFile(
export function createDirectoryIndex(
directoryPath: string,
- extractText: boolean = false
+ extractText: boolean = false,
+ ignorePatterns: Array<string>
): Promise<Array<TS.FileSystemEntry>> {
const dirPath = cleanTrailingDirSeparator(directoryPath);
if (PlatformIO.isWorkerAvailable() && !PlatformIO.haveObjectStoreSupport()) {
// Start indexing in worker if not in the object store mode
- return PlatformIO.createDirectoryIndexInWorker(dirPath, extractText);
+ return PlatformIO.createDirectoryIndexInWorker(
+ dirPath,
+ extractText,
+ ignorePatterns
+ );
}
const SearchIndex = [];
@@ -413,7 +420,8 @@ export function createDirectoryIndex(
counter += 1;
SearchIndex.push(enhanceEntry(directoryEntry));
}
- }
+ },
+ ignorePatterns
)
.then(() => {
// entries - can be used for further processing
@@ -442,8 +450,12 @@ export function walkDirectory(
path: string,
options: Object = {},
fileCallback: any,
- dirCallback: any
+ dirCallback: any,
+ ignorePatterns: Array<string> = []
) {
+ if (ignorePatterns.length > 0 && micromatch.isMatch(path, ignorePatterns)) {
+ return;
+ }
const mergedOptions = {
recursive: false,
skipMetaFolder: true,
@@ -460,12 +472,20 @@ export function walkDirectory(
if (window.walkCanceled || entries === undefined) {
return false;
}
+
return Promise.all(
entries.map(entry => {
if (window.walkCanceled) {
return false;
}
+ if (
+ ignorePatterns.length > 0 &&
+ micromatch.isMatch(entry.path, ignorePatterns)
+ ) {
+ return false;
+ }
+
if (entry.isFile) {
if (
fileCallback &&
@@ -504,7 +524,8 @@ export function walkDirectory(
entry.path,
mergedOptions,
fileCallback,
- dirCallback
+ dirCallback,
+ ignorePatterns
);
}
return entry;
diff --git a/app/splash-worker.ts b/app/splash-worker.ts
index 5f76efeb3..6b5650919 100644
--- a/app/splash-worker.ts
+++ b/app/splash-worker.ts
@@ -52,7 +52,8 @@ function init() {
counter += 1;
directoryIndex.push(enhanceEntry(directoryEntry));
}
- }
+ },
+ arg.ignorePatterns
)
.then(() => {
// entries - can be used for further processing
diff --git a/app/tagspaces.namespace.d.ts b/app/tagspaces.namespace.d.ts
index 6a82e1188..695b7abea 100644
--- a/app/tagspaces.namespace.d.ts
+++ b/app/tagspaces.namespace.d.ts
@@ -41,6 +41,7 @@ export namespace TS {
fullTextIndex?: boolean;
maxIndexAge?: number;
persistTagsInSidecarFile?: boolean;
+ ignorePatternPaths?: Array<string>;
}
interface SearchQuery {
@@ -114,6 +115,7 @@ export namespace TS {
path: string;
url?: string;
meta?: FileSystemEntryMeta;
+ isIgnored?: boolean;
}
interface FileSystemEntryMeta {
diff --git a/app/utils/useValidation.ts b/app/utils/useValidation.ts
index 7e6c8fe92..f5328cf28 100644
--- a/app/utils/useValidation.ts
+++ b/app/utils/useValidation.ts
@@ -20,11 +20,10 @@ export default function useValidation() {
};
/**
- *
* @param errorKey - if have error for the specified key
* if not set errorKey return if its have errors at general
*/
- const haveError = (errorKey?: string) => {
+ const haveError = (errorKey?: string): boolean => {
if (errorKey) {
return errorInput.some(err => err === errorKey);
}
diff --git a/package.json b/package.json
index f2437cab6..3f1230fb8 100644
--- a/package.json
+++ b/package.json
@@ -274,6 +274,7 @@
"jszip": "^3.1.5",
"leaflet": "^1.7.1",
"marked": "^2.0.1",
+ "micromatch": "^4.0.4",
"open-location-code": "^1.0.3",
"open-location-code-typescript": "^1.5.0",
"path": "^0.12.7",
diff --git a/yarn.lock b/yarn.lock
index 62077f091..1fcc3d16e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -12860,6 +12860,14 @@ micromatch@^4.0.0, micromatch@^4.0.2:
braces "^3.0.1"
picomatch "^2.0.5"
+micromatch@^4.0.4:
+ version "4.0.4"
+ resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.4.tgz#896d519dfe9db25fce94ceb7a500919bf881ebf9"
+ integrity sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==
+ dependencies:
+ braces "^3.0.1"
+ picomatch "^2.2.3"
+
miller-rabin@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/miller-rabin/-/miller-rabin-4.0.1.tgz#f080351c865b0dc562a8462966daa53543c78a4d"
@@ -14307,6 +14315,11 @@ picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1:
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==
+picomatch@^2.2.3:
+ version "2.3.0"
+ resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
+ integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==
+
pify@^2.0.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"