TagSpaces is an offline, open source, document manager with tagging support
refactoring
Ilian Sapundshiev23f2d86438a8
diff --git a/app/components/FolderContainer.js b/app/components/FolderContainer.jsindex 31187a959..c85ab9bf6 100644--- a/app/components/FolderContainer.js+++ b/app/components/FolderContainer.js@@ -26,7 +26,6 @@ import BackButtonIcon from '@material-ui/icons/ArrowBack';import MenuIcon from '@material-ui/icons/Menu';import Badge from '@material-ui/core/Badge';import { withStyles } from '@material-ui/core/styles';-import { HotKeys } from 'react-hotkeys';import LocationMenu from './menus/LocationMenu';import DirectoryMenu from './menus/DirectoryMenu';import i18n from '../services/i18n';@@ -165,7 +164,6 @@ type Props = {directoryContent: Array<Object>,currentDirectoryPath: string | null,searchResultCount: number,- lastSelectedEntry: string | null,addTags: () => void,removeTags: () => void,removeAllTags: () => void,@@ -174,8 +172,6 @@ type Props = {toggleCreateFileDialog: () => void,deleteFile: () => void,renameFile: () => void,- getNextFile: () => string,- getPrevFile: () => string,openDirectory: () => void,showInFileManager: () => void,openFile: (path: string) => void,@@ -203,6 +199,8 @@ type State = {directoryMenuAnchorEl?: null | Object,perspectiveChooserMenuOpened?: boolean,perspectiveChooserMenuAnchorEl?: null | Object,+ directoryContextMenuOpened: boolean,+ directoryContextMenuAnchorEl: null | Object,perspectiveCommand?: null | Object};@@ -254,79 +252,6 @@ class FolderContainer extends React.Component<Props, State> {return null;}- keyBindingHandlers = {- nextDocument: () => {- const nextFilePath = this.props.getNextFile();- if (nextFilePath) {- this.props.setLastSelectedEntry(nextFilePath);- }- },- prevDocument: () => {- const prevFilePath = this.props.getPrevFile();- if (prevFilePath) {- this.props.setLastSelectedEntry(prevFilePath);- }- },- selectAll: () => {- this.setState(- {- perspectiveCommand: { key: 'TOGGLE_SELECT_ALL' }- },- () => {- this.setState({ perspectiveCommand: null });- }- );- },- deleteDocument: () => {- this.setState(- {- perspectiveCommand: { key: 'DELETE_SELECTED_ENTRIES' }- },- () => {- this.setState({ perspectiveCommand: null });- }- );- },- addRemoveTags: () => {- this.setState(- {- perspectiveCommand: { key: 'ADD_REMOVE_TAGS' }- },- () => {- this.setState({ perspectiveCommand: null });- }- );- },- renameFile: () => {- this.setState(- {- perspectiveCommand: { key: 'RENAME_ENTRY' }- },- () => {- this.setState({ perspectiveCommand: null });- }- );- },- openEntry: () => {- const { lastSelectedEntry } = this.props;- if (lastSelectedEntry) {- const isLastSelectedEntryFile = this.props.directoryContent.some(- fsEntry => fsEntry.isFile && fsEntry.path === lastSelectedEntry- );- if (isLastSelectedEntryFile) {- this.props.openFile(lastSelectedEntry);- } else {- this.props.loadDirectoryContent(lastSelectedEntry);- }- }- },- openFileExternally: () => {- if (this.props.lastSelectedEntry) {- this.props.openFileNatively(this.props.lastSelectedEntry);- }- }- };-openDirectoryMenu = (event: Object) => {this.setState({directoryContextMenuOpened: true,@@ -347,7 +272,7 @@ class FolderContainer extends React.Component<Props, State> {return;}this.setState({- currentPerspective: perspectiveId ? perspectiveId : 'default'+ currentPerspective: perspectiveId || 'default'});}@@ -430,102 +355,100 @@ class FolderContainer extends React.Component<Props, State> {const normalizedCurrentDirPath = normalizePath(currentDirectoryPath.split('\\').join('/'));let searchResultCounterText = searchResultCount + ' ' + i18n.t('entries');if (searchResultCount >= maxSearchResults) {- searchResultCounterText = 'More than ' + (maxSearchResults - 1) + ' entries found, showing only the first ' + maxSearchResults ;+ searchResultCounterText = 'More than ' + (maxSearchResults - 1) + ' entries found, showing only the first ' + maxSearchResults;}return (- <HotKeys handlers={this.keyBindingHandlers}>- <div className={classes.mainPanel}>- <div className={classes.topPanel}>- <div className={classes.toolbar}>- {isDesktopMode ? (- <LocationMenu />- ) : (- <Button style={{ marginLeft: -8 }} onClick={showDrawer}>- <MenuIcon />- </Button>- )}- <CounterBadge- showZero={true}- title={searchResultCounterText}- badgeContent={searchResultCount}- color="secondary"- max={maxSearchResults - 1}- onClick={() => {- openSearchPanel();- }}- />- <div className={classes.flexMiddle} />- {currentDirectoryPath && (- <React.Fragment>- {isDesktopMode && this.state.pathParts &&- this.state.pathParts.map(pathPart => (- <Button- key={pathPart}- onClick={() => loadDirectoryContent(pathPart)}- title={'Navigate to: ' + pathPart}- style={{ paddingLeft: 3, paddingRight: 0, minWidth: 10 }}- >- {extractShortDirectoryName(pathPart, '/')}- / - </Button>- ))}- {!isDesktopMode && this.state.pathParts && this.state.pathParts.length > 0 && (- <React.Fragment>- <Button- onClick={loadParentDirectoryContent}- data-tid="openParentDirectory"- style={{ paddingLeft: 3, paddingRight: 0}}- >- <BackButtonIcon />- </Button>- </React.Fragment>+ <div className={classes.mainPanel}>+ <div className={classes.topPanel}>+ <div className={classes.toolbar}>+ {isDesktopMode ? (+ <LocationMenu />+ ) : (+ <Button style={{ marginLeft: -8 }} onClick={showDrawer}>+ <MenuIcon />+ </Button>+ )}+ <CounterBadge+ showZero={true}+ title={searchResultCounterText}+ badgeContent={searchResultCount}+ color="secondary"+ max={maxSearchResults - 1}+ onClick={() => {+ openSearchPanel();+ }}+ />+ <div className={classes.flexMiddle} />+ {currentDirectoryPath && (+ <React.Fragment>+ {isDesktopMode && this.state.pathParts &&+ this.state.pathParts.map(pathPart => (+ <Button+ key={pathPart}+ onClick={() => loadDirectoryContent(pathPart)}+ title={'Navigate to: ' + pathPart}+ style={{ paddingLeft: 3, paddingRight: 0, minWidth: 10 }}+ >+ {extractShortDirectoryName(pathPart, '/')}+ / + </Button>+ ))}+ {!isDesktopMode && this.state.pathParts && this.state.pathParts.length > 0 && (+ <React.Fragment>+ <Button+ onClick={loadParentDirectoryContent}+ data-tid="openParentDirectory"+ style={{ paddingLeft: 3, paddingRight: 0}}+ >+ <BackButtonIcon />+ </Button>+ </React.Fragment>+ )}+ <Button+ data-tid="folderContainerOpenDirMenu"+ title={+ i18n.t('core:openDirectoryMenu') ++ ' - ' ++ (currentDirectoryPath || '')+ }+ className={classes.folderButton}+ onClick={this.openDirectoryMenu}+ onContextMenu={this.openDirectoryMenu}+ >+ {extractShortDirectoryName(+ normalizePath(normalizedCurrentDirPath), '/')}- <Button- data-tid="folderContainerOpenDirMenu"- title={- i18n.t('core:openDirectoryMenu') +- ' - ' +- (currentDirectoryPath || '')- }- className={classes.folderButton}- onClick={this.openDirectoryMenu}- onContextMenu={this.openDirectoryMenu}- >- {extractShortDirectoryName(- normalizePath(normalizedCurrentDirPath), '/'- )}- <MoreVertIcon />- </Button>- <DirectoryMenu- open={this.state.directoryContextMenuOpened}- onClose={this.closeDirectoryMenu}- anchorEl={this.state.directoryContextMenuAnchorEl}- directoryPath={currentDirectoryPath}- loadDirectoryContent={this.props.loadDirectoryContent}- openFileNatively={this.props.openFileNatively}- openDirectory={this.props.openDirectory}- loadParentDirectoryContent={loadParentDirectoryContent}- showInFileManager={this.props.showInFileManager}- reflectCreateEntry={this.props.reflectCreateEntry}- openFile={this.props.openFile}- toggleCreateFileDialog={this.props.toggleCreateFileDialog}- deleteDirectory={this.props.deleteDirectory}- showNotification={this.props.showNotification}- switchPerspective={this.switchPerspective}- isReadOnlyMode={this.props.isReadOnlyMode}- />- </React.Fragment>- )}- </div>- </div>- <div- className={classes.centerPanel}- style={{ height: this.props.windowHeight }}- >- {this.renderPerspective()}+ <MoreVertIcon />+ </Button>+ <DirectoryMenu+ open={this.state.directoryContextMenuOpened}+ onClose={this.closeDirectoryMenu}+ anchorEl={this.state.directoryContextMenuAnchorEl}+ directoryPath={currentDirectoryPath}+ loadDirectoryContent={this.props.loadDirectoryContent}+ openFileNatively={this.props.openFileNatively}+ openDirectory={this.props.openDirectory}+ loadParentDirectoryContent={loadParentDirectoryContent}+ showInFileManager={this.props.showInFileManager}+ reflectCreateEntry={this.props.reflectCreateEntry}+ openFile={this.props.openFile}+ toggleCreateFileDialog={this.props.toggleCreateFileDialog}+ deleteDirectory={this.props.deleteDirectory}+ showNotification={this.props.showNotification}+ switchPerspective={this.switchPerspective}+ isReadOnlyMode={this.props.isReadOnlyMode}+ />+ </React.Fragment>+ )}</div></div>- </HotKeys>+ <div+ className={classes.centerPanel}+ style={{ height: this.props.windowHeight }}+ >+ {this.renderPerspective()}+ </div>+ </div>);}}@@ -537,7 +460,6 @@ function mapStateToProps(state) {perspectives: getPerspectives(state),directoryContent: getDirectoryContent(state),searchResultCount: getSearchResultCount(state),- // pathPart: getPathTrail(state),currentLocationPath: getCurrentLocationPath(state),maxSearchResults: getMaxSearchResults(state),isDesktopMode: getDesktopMode(state),diff --git a/app/perspectives/grid-perspective/components/MainContainer.js b/app/perspectives/grid-perspective/components/MainContainer.jsindex ae63c7aba..91db23298 100644--- a/app/perspectives/grid-perspective/components/MainContainer.js+++ b/app/perspectives/grid-perspective/components/MainContainer.js@@ -22,6 +22,7 @@ import uuidv1 from 'uuid';import { connect } from 'react-redux';import { bindActionCreators } from 'redux';import memoize from 'memoize-one';+import { GlobalHotKeys } from 'react-hotkeys';import { withStyles } from '@material-ui/core/styles';import Typography from '@material-ui/core/Typography';import Toolbar from '@material-ui/core/Toolbar';@@ -30,7 +31,6 @@ import RadioCheckedIcon from '@material-ui/icons/RadioButtonChecked';import RadioUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked';import ListItemIcon from '@material-ui/core/ListItemIcon';import ListItemText from '@material-ui/core/ListItemText';-import ParentDirIcon from '@material-ui/icons/SubdirectoryArrowLeft';import ViewListIcon from '@material-ui/icons/ViewList';import SwapVertIcon from '@material-ui/icons/SwapVert';import ViewGridIcon from '@material-ui/icons/ViewModule';@@ -57,6 +57,7 @@ import { type Tag } from '../../../reducers/taglibrary';import {getSupportedFileTypes,getDesktopMode,+ getKeyBindingObject} from '../../../reducers/settings';import {sortByCriteria,@@ -120,6 +121,7 @@ type Props = {perspectiveCommand: Object,directoryContent: Array<FileSystemEntry>,moveFiles: (files: Array<string>, destination: string) => void,+ keyBindings: Object,showNotification: (text: string,notificationType: string,@@ -190,32 +192,7 @@ class GridPerspective extends React.Component<Props, State> {}componentWillReceiveProps = (nextProps: Props) => {- const { lastSelectedEntryPath, perspectiveCommand, selectedEntries } = nextProps;-- if (perspectiveCommand && perspectiveCommand.key) {- this.props.setLastSelectedEntry(null);- if (perspectiveCommand.key === 'TOGGLE_SELECT_ALL') {- this.toggleSelectAllFiles();- } else if (- perspectiveCommand.key === 'ADD_REMOVE_TAGS' &&- selectedEntries &&- selectedEntries.length > 0- ) {- this.openAddRemoveTagsDialog();- } else if (- perspectiveCommand.key === 'RENAME_ENTRY' &&- selectedEntries &&- selectedEntries.length === 1- ) {- if (selectedEntries[0].isFile) {- this.setState({ selectedEntryPath: selectedEntries[0].path }, () => {- this.openFileRenameDialog();- });- }- } else if (perspectiveCommand.key === 'DELETE_SELECTED_ENTRIES' && this.state.fileOperationsEnabled) {- this.openDeleteFileDialog();- }- }+ const { lastSelectedEntryPath } = nextProps;if (lastSelectedEntryPath !== null) {this.computeFileOperationsEnabled();@@ -648,6 +625,60 @@ class GridPerspective extends React.Component<Props, State> {);};++ keyMap = this.props.keyBindings;++ keyBindingHandlers = {+ // nextDocument: () => {+ // const nextFilePath = this.props.getNextFile();+ // if (nextFilePath) {+ // this.props.setLastSelectedEntry(nextFilePath);+ // }+ // },+ // prevDocument: () => {+ // const prevFilePath = this.props.getPrevFile();+ // if (prevFilePath) {+ // this.props.setLastSelectedEntry(prevFilePath);+ // }+ // },+ selectAll: () => this.toggleSelectAllFiles(),+ deleteDocument: () => {+ if (this.state.fileOperationsEnabled) {+ this.openDeleteFileDialog();+ }+ },+ addRemoveTags: () => {+ if (this.props.selectedEntries && this.props.selectedEntries.length > 0) {+ this.openAddRemoveTagsDialog();+ }+ },+ renameFile: () => {+ if (this.props.selectedEntries && this.props.selectedEntries.length === 1 && this.props.selectedEntries[0].isFile) {+ this.setState({ selectedEntryPath: this.props.selectedEntries[0].path }, () => {+ this.openFileRenameDialog();+ });+ }+ },+ openEntry: () => {+ const { lastSelectedEntryPath } = this.props;+ if (lastSelectedEntryPath) {+ const isLastSelectedEntryFile = this.props.directoryContent.some(+ fsEntry => fsEntry.isFile && fsEntry.path === lastSelectedEntryPath+ );+ if (isLastSelectedEntryFile) {+ this.props.openFile(lastSelectedEntryPath);+ } else {+ this.props.loadDirectoryContent(lastSelectedEntryPath);+ }+ }+ },+ openFileExternally: () => {+ if (this.props.lastSelectedEntryPath) {+ this.props.openFileNatively(this.props.lastSelectedEntryPath);+ }+ }+ };+render() {const {classes,@@ -781,47 +812,49 @@ class GridPerspective extends React.Component<Props, State> {<MoreVertIcon /></IconButton></Toolbar>- <div style={{- height: '100%',- backgroundColor: theme.palette.background.default- }}- >+ {/* <GlobalHotKeys keyMap={this.keyMap} handlers={this.keyBindingHandlers}> */}<div style={{height: '100%',- overflowY: AppConfig.isFirefox ? 'auto' : 'overlay',- backgroundColor: currentDirectoryColor || 'transparent',+ backgroundColor: theme.palette.background.default}}>- <div- className={layoutType === 'grid' ? classes.gridContainer : classes.rowContainer}- style={{- gridTemplateColumns: layoutType === 'grid' ? 'repeat(auto-fit,minmax(' + entryWidth + 'px,1fr))' : 'none',- }}- ref={ref => {- this.mainGrid = ref;- }}- data-tid="perspectiveGridFileTable"+ <div style={{+ height: '100%',+ overflowY: AppConfig.isFirefox ? 'auto' : 'overlay',+ backgroundColor: currentDirectoryColor || 'transparent',+ }}>- {(sortedDirectories.map(entry => this.renderCell(entry)))}- {(sortedFiles.map(entry => this.renderCell(entry)))}- {isAppLoading && (- <Typography style={{ padding: 15 }}>- {i18n.t('core:loading')}- </Typography>- )}- {(!isAppLoading && sortedFiles.length < 1 && sortedDirectories.length < 1) && (- <Typography style={{ padding: 15 }}>- {i18n.t('core:noFileFolderFound')}- </Typography>- )}- {(!isAppLoading && sortedFiles.length < 1 && sortedDirectories.length >= 1 && !this.state.showDirectories) && (- <Typography style={{ padding: 15 }}>- {i18n.t('core:noFileButFoldersFound')}- </Typography>- )}+ <div+ className={layoutType === 'grid' ? classes.gridContainer : classes.rowContainer}+ style={{+ gridTemplateColumns: layoutType === 'grid' ? 'repeat(auto-fit,minmax(' + entryWidth + 'px,1fr))' : 'none',+ }}+ ref={ref => {+ this.mainGrid = ref;+ }}+ data-tid="perspectiveGridFileTable"+ >+ {(sortedDirectories.map(entry => this.renderCell(entry)))}+ {(sortedFiles.map(entry => this.renderCell(entry)))}+ {isAppLoading && (+ <Typography style={{ padding: 15 }}>+ {i18n.t('core:loading')}+ </Typography>+ )}+ {(!isAppLoading && sortedFiles.length < 1 && sortedDirectories.length < 1) && (+ <Typography style={{ padding: 15 }}>+ {i18n.t('core:noFileFolderFound')}+ </Typography>+ )}+ {(!isAppLoading && sortedFiles.length < 1 && sortedDirectories.length >= 1 && !this.state.showDirectories) && (+ <Typography style={{ padding: 15 }}>+ {i18n.t('core:noFileButFoldersFound')}+ </Typography>+ )}+ </div></div></div>- </div>+ {/* </GlobalHotKeys> */}<AddRemoveTagsDialogopen={this.state.isAddRemoveTagsDialogOpened}onClose={this.handleCloseDialogs}@@ -1104,7 +1137,8 @@ function mapStateToProps(state) {lastSelectedEntryPath: getLastSelectedEntry(state),currentDirectoryColor: getCurrentDirectoryColor(state),desktopMode: getDesktopMode(state),- selectedEntries: getSelectedEntries(state)+ selectedEntries: getSelectedEntries(state),+ keyBindings: getKeyBindingObject(state),};}