TagSpaces is an offline, open source, document manager with tagging support
limit the parent directory navigation to current location
Ilian Sapundshievedd09cfecb4c
diff --git a/app/components/FolderContainer.js b/app/components/FolderContainer.jsindex fb5c14d23..b69453b20 100644--- a/app/components/FolderContainer.js+++ b/app/components/FolderContainer.js@@ -38,11 +38,11 @@ import {getDirectoryPath,getLastSelectedEntry,getSearchResultCount,- isReadOnlyMode+ isReadOnlyMode,+ getCurrentLocationPath} from '../reducers/app';import TaggingActions from '../reducers/tagging-actions';import {- extractDirectoryName,normalizePath,extractShortDirectoryName} from '../utils/paths';@@ -178,24 +178,27 @@ class FolderContainer extends React.Component<Props, State> {};static getDerivedStateFromProps(nextProps, prevState) {- if (prevState.currentPath !== nextProps.currentDirectoryPath) {+ if (nextProps.currentDirectoryPath && prevState.currentPath !== nextProps.currentDirectoryPath) {+ let currentLocationPath = '';+ if (nextProps.currentLocationPath) {+ currentLocationPath = nextProps.currentLocationPath;+ }// Make the path unix like ending always with /- let normalizedPath =- normalizePath(nextProps.currentDirectoryPath.split('\\').join('/')) +- '/';+ const normalizedOrigCurrentPath = normalizePath(nextProps.currentDirectoryPath.split('\\').join('/'));+ let normalizedCurrentPath = normalizedOrigCurrentPath;+ const normalizedCurrentLocationPath = normalizePath(currentLocationPath.split('\\').join('/'));+ // console.log('Current path : ' + normalizedCurrentPath);+ // console.log('Current location path : ' + normalizedCurrentLocationPath);let pathParts = [];- while (normalizedPath.lastIndexOf('/') > 0) {- pathParts.push(normalizedPath);- normalizedPath = normalizedPath.substring(- 0,- normalizedPath.lastIndexOf('/')- );+ while (normalizedCurrentPath.lastIndexOf('/') > 0 && normalizedCurrentPath.startsWith(currentLocationPath)) {+ // console.log('Current splitting : ' + normalizedCurrentPath);+ pathParts.push(normalizedCurrentPath);+ normalizedCurrentPath = normalizedCurrentPath.substring(0, normalizedCurrentPath.lastIndexOf('/'));}- pathParts = pathParts.reverse();- // let pathParts = normalizedPath.split('/');- if (pathParts.length > 1) {- pathParts = pathParts.slice(0, pathParts.length - 2); // remove current directory+ if (pathParts.length >= 1) {+ pathParts = pathParts.slice(1, pathParts.length); // remove current directory}+ pathParts = pathParts.reverse();if (pathParts.length > 2) {pathParts = pathParts.slice(pathParts.length - 2, pathParts.length); // leave only the last 2 dirs in the path}@@ -314,7 +317,6 @@ class FolderContainer extends React.Component<Props, State> {<GridPerspectivedirectoryContent={this.props.directoryContent}loadDirectoryContent={this.props.loadDirectoryContent}- loadParentDirectoryContent={this.props.loadParentDirectoryContent}openFile={this.props.openFile}openFileNatively={this.props.openFileNatively}deleteFile={this.props.deleteFile}@@ -423,6 +425,8 @@ function mapStateToProps(state) {perspectives: getPerspectives(state),directoryContent: getDirectoryContent(state),searchResultCount: getSearchResultCount(state),+ // pathPart: getPathTrail(state),+ currentLocationPath: getCurrentLocationPath(state),isReadOnlyMode: isReadOnlyMode(state)};}diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 679ec831e..b192fad93 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -390,5 +390,6 @@"entrySizeBig": "Large mode","singleClickOpenInternally": "Single click opens file internally","singleClickOpenExternally": "Single click opens file externally",+ "parentDirNotInLocation": "Unable to navigate! Parent folder not in the current location.","-": "-"}diff --git a/app/perspectives/grid-perspective/src/styles.css.js b/app/perspectives/grid-perspective/src/styles.css.jsindex 72f5b3952..6cd19022c 100644--- a/app/perspectives/grid-perspective/src/styles.css.js+++ b/app/perspectives/grid-perspective/src/styles.css.js@@ -87,8 +87,8 @@ export default (theme) => ({opacity: 0.6},gridCellDescription: {- padding: 0,- margin: 4,+ padding: 2,+ margin: 2,backgroundColor: theme.palette.background.paper,opacity: 0.6,borderRadius: 5diff --git a/app/reducers/app.js b/app/reducers/app.jsindex f42509f40..49ee0fe09 100644--- a/app/reducers/app.js+++ b/app/reducers/app.js@@ -530,16 +530,8 @@ export const actions = {},showSelectDirectoryDialog: () => (dispatch: (actions: Object) => void,- getState: () => Object) => {- const { app } = getState();- // if (!app.currentDirectoryPath) {- // dispatch(- // actions.showNotification(i18n.t('core:firstOpenaFolder'), 'warning', true)- // );- // } else {dispatch(actions.toggleSelectDirectoryDialog());- // }},toggleAboutDialog: () => ({ type: types.TOGGLE_ABOUT_DIALOG }),toggleKeysDialog: () => ({ type: types.TOGGLE_KEYBOARD_DIALOG }),@@ -553,10 +545,17 @@ export const actions = {dispatch: (actions: Object) => void,getState: () => Object) => {- const { app } = getState();- if (app.currentDirectoryPath) {- const parentDirectory = extractParentDirectoryPath(app.currentDirectoryPath);- dispatch(actions.loadDirectoryContent(parentDirectory));+ const state = getState();+ const currentDirectoryPath = state.app.currentDirectoryPath;+ const currentLocationPath = getCurrentLocationPath(state);++ if (currentDirectoryPath) {+ const parentDirectory = extractParentDirectoryPath(currentDirectoryPath);+ if (parentDirectory.startsWith(currentLocationPath)) {+ dispatch(actions.loadDirectoryContent(parentDirectory));+ } else {+ dispatch(actions.showNotification(i18n.t('core:parentDirNotInLocation'), 'warning', true));+ }} else {dispatch(actions.showNotification(i18n.t('core:firstOpenaFolder'), 'warning', true));}