TagSpaces is an offline, open source, document manager with tagging support
separate create entries dialog (#1946)
Stanimir00c912abbd2d
diff --git a/app/components/MobileNavigation.tsx b/app/components/MobileNavigation.tsxindex bfde45409..be30dec02 100644--- a/app/components/MobileNavigation.tsx+++ b/app/components/MobileNavigation.tsx@@ -75,7 +75,7 @@ interface Props {language: string;toggleProTeaser: (slidePage?: string) => void;toggleOnboardingDialog: () => void;- toggleCreateFileDialog: () => void;+ toggleNewEntryDialog: () => void;toggleAboutDialog: () => void;toggleKeysDialog: () => void;toggleSettingsDialog: () => void;@@ -109,7 +109,7 @@ function MobileNavigation(props: Props) {const {classes,- toggleCreateFileDialog,+ toggleNewEntryDialog,toggleLocationDialog,toggleOnboardingDialog,toggleSettingsDialog,@@ -160,7 +160,7 @@ function MobileNavigation(props: Props) {<Buttondata-tid="createNewFileTID"onClick={() => {- toggleCreateFileDialog();+ toggleNewEntryDialog();if (hideDrawer) {hideDrawer();}@@ -368,7 +368,7 @@ function mapStateToProps(state) {function mapActionCreatorsToProps(dispatch) {return bindActionCreators({- toggleCreateFileDialog: AppActions.toggleCreateFileDialog,+ toggleNewEntryDialog: AppActions.toggleNewEntryDialog,toggleOnboardingDialog: AppActions.toggleOnboardingDialog,toggleSettingsDialog: AppActions.toggleSettingsDialog,toggleProTeaser: AppActions.toggleProTeaser,diff --git a/app/components/WelcomePanel.tsx b/app/components/WelcomePanel.tsxindex e9e015cc5..1962bde9b 100644--- a/app/components/WelcomePanel.tsx+++ b/app/components/WelcomePanel.tsx@@ -60,7 +60,7 @@ import HowToStart from '-/components/HowToStart';interface Props {theme: any;classes: any;- toggleCreateFileDialog: () => void;+ toggleNewEntryDialog: () => void;toggleLocationDialog: () => void;toggleOpenLinkDialog: () => void;toggleKeysDialog: () => void;@@ -101,7 +101,7 @@ function WelcomePanel(props: Props) {openFsEntry,openURLExternally,toggleKeysDialog,- toggleCreateFileDialog,+ toggleNewEntryDialog,toggleLocationDialog,toggleOpenLinkDialog,isDesktopMode@@ -240,7 +240,7 @@ function WelcomePanel(props: Props) {className={classes.listItem}/></ListItem> */}- <ListItem onClick={toggleCreateFileDialog}>+ <ListItem onClick={toggleNewEntryDialog}><ListItemIcon><CreateFileIcon /></ListItemIcon>@@ -460,7 +460,7 @@ function mapActionCreatorsToProps(dispatch) {return bindActionCreators({setFirstRun: SettingsActions.setFirstRun,- toggleCreateFileDialog: AppActions.toggleCreateFileDialog,+ toggleNewEntryDialog: AppActions.toggleNewEntryDialog,toggleLocationDialog: AppActions.toggleLocationDialog,toggleOpenLinkDialog: AppActions.toggleOpenLinkDialog,openURLExternally: AppActions.openURLExternally,diff --git a/app/components/dialogs/CreateDialog.tsx b/app/components/dialogs/CreateDialog.tsxdeleted file mode 100644index 3763d8e46..000000000--- a/app/components/dialogs/CreateDialog.tsx+++ /dev/null@@ -1,597 +0,0 @@-/**- * 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, { useReducer, useRef, useState } from 'react';-import { connect } from 'react-redux';-import { bindActionCreators } from 'redux';-import { saveAs } from 'file-saver';-import Button from '@mui/material/Button';-import ButtonGroup from '@mui/material/ButtonGroup';-import Typography from '@mui/material/Typography';-import DialogContent from '@mui/material/DialogContent';-import DialogTitle from '@mui/material/DialogTitle';-import Grid from '@mui/material/Grid';-import withStyles from '@mui/styles/withStyles';-import Dialog from '@mui/material/Dialog';-import Paper from '@mui/material/Paper';-import { Accordion, AccordionDetails, AccordionSummary } from '@mui/material';-import DraggablePaper from '-/components/DraggablePaper';-import { Progress } from 'aws-sdk/clients/s3';-import { formatDateTime4Tag } from '@tagspaces/tagspaces-common/misc';-import AppConfig from '-/AppConfig';-import i18n from '-/services/i18n';-import { getKeyBindingObject } from '-/reducers/settings';-import {- actions as AppActions,- getDirectoryPath,- getSelectedEntries,- getCurrentDirectoryPerspective,- NotificationTypes-} from '-/reducers/app';-import IOActions from '-/reducers/io-actions';-import { getFirstRWLocation, getCurrentLocation } from '-/reducers/locations';-import { TS } from '-/tagspaces.namespace';-import PlatformIO from '-/services/platform-facade';-import DialogCloseButton from '-/components/dialogs/DialogCloseButton';-import Tooltip from '-/components/Tooltip';-import useTheme from '@mui/styles/useTheme';-import useMediaQuery from '@mui/material/useMediaQuery';-import TextField from '@mui/material/TextField';-import FormHelperText from '@mui/material/FormHelperText';-import { FormControl } from '@mui/material';-import { fileNameValidation } from '-/services/utils-io';-import { PerspectiveIDs } from '-/perspectives';-import { ExpandIcon, InfoIcon } from '-/components/CommonIcons';--const styles: any = () => ({- createButton: {- width: '100%',- textAlign: 'center'- }-});--interface Props {- open: boolean;- classes: any;- firstRWLocation: TS.Location;- currentLocation: TS.Location;- selectedEntries: Array<TS.FileSystemEntry>;- currentDirectoryPath: string | null;- currentDirectoryPerspective: string;- openLocation: (location: TS.Location) => void;- showNotification: (- message: string,- notificationType?: string,- autohide?: boolean- ) => void;- toggleLocationDialog: () => void;- toggleCreateDirectoryDialog: () => void;- reflectCreateEntries: (fsEntries: Array<TS.FileSystemEntry>) => void;- createFileAdvanced: (- targetPath: string,- fileName: string,- content: string,- fileType: string- ) => void;- onClose: () => void;- uploadFilesAPI: (- files: Array<File>,- destination: string,- onUploadProgress?: (progress: Progress, response: any) => void- ) => any;- downloadFile: (- url: string,- destination: string,- onDownloadProgress?: (progress: Progress, response: any) => void- ) => any;- onUploadProgress: (progress: Progress, response: any) => void;- toggleUploadDialog: () => void;- resetProgress: () => void;- setProgress: (path: string, progress: number, abort?: string) => void;-}--function CreateDialog(props: Props) {- const {- classes,- open,- onClose,- createFileAdvanced,- openLocation,- currentDirectoryPath,- currentDirectoryPerspective,- selectedEntries,- showNotification,- currentLocation,- firstRWLocation,- toggleLocationDialog,- toggleCreateDirectoryDialog- } = props;- const fileUrl = useRef<string>();- const fileName = useRef<string>(- 'note' +- AppConfig.beginTagContainer +- formatDateTime4Tag(new Date(), true) +- AppConfig.endTagContainer- );- const [inputError, setInputError] = useState<boolean>(false);- const [invalidURL, setInvalidURL] = useState<boolean>(false);- const [ignored, forceUpdate] = useReducer(x => x + 1, 0);- let fileInput: HTMLInputElement;- const fileContent = '';-- let targetDirectoryPath = currentDirectoryPath;- if (- currentDirectoryPerspective === PerspectiveIDs.KANBAN &&- selectedEntries &&- selectedEntries.length === 1 &&- !selectedEntries[0].isFile- ) {- targetDirectoryPath = selectedEntries[0].path;- }-- if (!targetDirectoryPath && firstRWLocation) {- targetDirectoryPath = firstRWLocation.path;- }-- const noSuitableLocation = !targetDirectoryPath;-- function loadLocation() {- if (!currentDirectoryPath && firstRWLocation) {- openLocation(firstRWLocation);- }- }-- function createRichTextFile() {- if (targetDirectoryPath && !fileNameValidation(fileName.current)) {- loadLocation();- createFileAdvanced(- targetDirectoryPath,- fileName.current,- fileContent,- 'html'- );- onClose();- }- }-- function createTextFile() {- if (targetDirectoryPath && !fileNameValidation(fileName.current)) {- loadLocation();- createFileAdvanced(- targetDirectoryPath,- fileName.current,- fileContent,- 'txt'- );- onClose();- }- }-- function createMarkdownFile() {- if (targetDirectoryPath && !fileNameValidation(fileName.current)) {- loadLocation();- createFileAdvanced(- targetDirectoryPath,- fileName.current,- fileContent,- 'md'- );- onClose();- }- }-- function addFile() {- loadLocation();- fileInput.click();- }-- function handleFileInputChange(selection: any) {- // console.log("Selected File: "+JSON.stringify(selection.currentTarget.files[0]));- // const file = selection.currentTarget.files[0];- props.resetProgress();- props.toggleUploadDialog();- props- .uploadFilesAPI(- Array.from(selection.currentTarget.files),- targetDirectoryPath,- props.onUploadProgress- )- .then(fsEntries => {- props.reflectCreateEntries(fsEntries);- return true;- })- .catch(error => {- console.log('uploadFiles', error);- });- onClose();- }-- const onInputFocus = event => {- if (fileName.current) {- event.preventDefault();- const { target } = event;- target.focus();- const indexOfBracket = fileName.current.indexOf(- AppConfig.beginTagContainer- );- let endRange = fileName.current.length;- // if (indexOfBracket > 0) {- // endRange = indexOfBracket;- // }- target.setSelectionRange(0, endRange);- }- };-- const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {- fileName.current = event.target.value;- handleValidation();- };-- const handleValidation = () => {- let noValid = fileNameValidation(fileName.current);-- if (noValid) {- if (inputError !== noValid) {- setInputError(noValid);- } else {- forceUpdate();- }- } else {- setInputError(noValid);- }- };-- const handleUrlChange = (event: React.ChangeEvent<HTMLInputElement>) => {- fileUrl.current = event.target.value;- };-- function downloadURL() {- if (fileUrl.current) {- try {- const url = new URL(fileUrl.current);- if (invalidURL) {- setInvalidURL(false);- }- let fileName;- let pathParts;- if (url.pathname) {- const delimiterIndex = url.pathname.lastIndexOf('/');- if (delimiterIndex > -1) {- fileName = url.pathname.substring(delimiterIndex + 1);- if (!fileName) {- pathParts = url.pathname.split('/').filter(Boolean);- }- } else {- fileName = url.pathname;- }- }- if (!fileName) {- fileName =- url.hostname +- (pathParts && pathParts.length > 0 ? pathParts.join('-') : '') +- '.html';- } else if (fileName.indexOf('.') === -1) {- fileName = url.hostname + '-' + fileName + '.html';- }- if (PlatformIO.haveObjectStoreSupport() || AppConfig.isElectron) {- props.resetProgress();- props.toggleUploadDialog();- props- .downloadFile(- fileUrl.current,- targetDirectoryPath +- PlatformIO.getDirSeparator() +- decodeURIComponent(fileName),- props.onUploadProgress- )- .then(() => {- if (PlatformIO.haveObjectStoreSupport()) {- // currently objectStore location in downloadFile use saveFilePromise and this function not have progress handling- props.setProgress(fileUrl.current, 100);- }- })- .catch(e => {- console.log('downloadFile error:', e);- props.setProgress(fileUrl.current, -1, i18n.t('core:errorCORS'));- showNotification(- 'downloadFile error' + e.message,- NotificationTypes.error,- true- );- });- } else {- saveAs(fileUrl.current, decodeURIComponent(fileName));- }- onClose();- } catch (ex) {- setInvalidURL(true);- console.error('downloadURL', ex);- }- }- }-- const theme = useTheme();- const fullScreen = useMediaQuery(theme.breakpoints.down('md'));- return (- <Dialog- open={open}- onClose={onClose}- fullScreen={fullScreen}- keepMounted- aria-labelledby="draggable-dialog-title"- PaperComponent={fullScreen ? Paper : DraggablePaper}- scroll="paper"- >- <DialogTitle style={{ cursor: 'move' }} id="draggable-dialog-title">- {i18n.t('core:create') + '...'}- <DialogCloseButton testId="closeCreateDialogTID" onClose={onClose} />- </DialogTitle>- <DialogContent- style={{- minWidth: 200,- minHeight: 300,- marginBottom: 20,- overflow: 'overlay'- }}- data-tid="keyboardShortCutsDialog"- >- <Accordion style={{ marginTop: 5 }} defaultExpanded>- <AccordionDetails style={{ paddingTop: 16 }}>- <Grid style={{ flexGrow: 1, width: '100%' }} container spacing={1}>- <Grid item xs={12}>- <FormControl fullWidth={true} error={inputError}>- <TextField- autoFocus- error={inputError}- margin="dense"- name="entryName"- label={i18n.t('core:newFileName')}- onChange={handleInputChange}- onFocus={onInputFocus}- onKeyDown={event => {- if (event.key === 'Enter' || event.keyCode === 13) {- event.preventDefault();- event.stopPropagation();- createMarkdownFile();- }- }}- defaultValue={fileName.current}- disabled={noSuitableLocation}- fullWidth={true}- data-tid="newEntryDialogInputTID"- />- {inputError && (- <FormHelperText>- {i18n.t('core:fileNameHelp')}- </FormHelperText>- )}- </FormControl>- </Grid>- <Grid item xs={12}>- <ButtonGroup- style={{- textAlign: 'center',- width: '100%'- }}- >- <Button- // variant="contained"- onClick={createMarkdownFile}- className={classes.createButton}- data-tid="createMarkdownButton"- disabled={noSuitableLocation}- >- <Tooltip title={i18n.t('createMarkdownTitle')}>- <Typography- variant="button"- style={{ fontWeight: 'bold' }}- display="block"- gutterBottom- >- {i18n.t('createMarkdown')}- </Typography>- </Tooltip>- </Button>- <Button- // variant="contained"- onClick={createRichTextFile}- className={classes.createButton}- data-tid="createRichTextFileButton"- disabled={noSuitableLocation}- >- <Tooltip title={i18n.t('createNoteTitle')}>- <Typography variant="button" display="block" gutterBottom>- {i18n.t('createRichTextFile')}- </Typography>- </Tooltip>- </Button>- <Button- // variant="contained"- onClick={createTextFile}- className={classes.createButton}- data-tid="createTextFileButton"- disabled={noSuitableLocation}- >- <Tooltip title={i18n.t('createTextFileTitle')}>- <Typography variant="button" display="block" gutterBottom>- {i18n.t('createTextFile')}- </Typography>- </Tooltip>- </Button>- </ButtonGroup>- </Grid>- <Grid style={{ marginTop: 20 }} item xs={12}>- <Button- variant="outlined"- onClick={() => {- onClose();- toggleLocationDialog();- }}- className={classes.createButton}- data-tid="createLocationButton"- >- <Tooltip title={i18n.t('createLocationTitle')}>- <Typography variant="button" display="block" gutterBottom>- {i18n.t('core:createLocation')}- </Typography>- </Tooltip>- </Button>- </Grid>- </Grid>- </AccordionDetails>- </Accordion>- <Accordion>- <AccordionSummary- expandIcon={<ExpandIcon />}- aria-controls="panelGeneral-content"- id="panelGeneral-header"- >- <Typography>{i18n.t('core:moreOperations')}</Typography>- </AccordionSummary>- <AccordionDetails>- <Grid item xs={12}>- <Button- variant="outlined"- onClick={() => {- onClose();- toggleCreateDirectoryDialog();- }}- className={classes.createButton}- data-tid="newSubDirectory"- disabled={noSuitableLocation}- >- {i18n.t('core:newSubdirectory')}- </Button>- </Grid>- <Grid style={{ marginTop: 20 }} item xs={12}>- <Tooltip title={i18n.t('core:addFilesTitle')}>- <Button- variant="outlined"- onClick={addFile}- className={classes.createButton}- data-tid="addFilesButton"- disabled={noSuitableLocation}- >- {i18n.t('addFiles')}- </Button>- </Tooltip>- </Grid>- <Grid item xs={12}>- <TextField- error={invalidURL}- label={i18n.t('core:url')}- margin="dense"- name="name"- fullWidth={true}- data-tid="newUrlTID"- onKeyDown={event => {- if (event.key === 'Enter') {- downloadURL();- }- }}- onChange={handleUrlChange}- />- </Grid>- <Grid item xs={12}>- <ButtonGroup- style={{- textAlign: 'center',- width: '100%'- }}- >- <Button- data-tid="cancelRenameEntryTID"- className={classes.createButton}- onClick={() => downloadURL()}- >- {i18n.t('core:downloadFile')}- </Button>- </ButtonGroup>- </Grid>- {/* </Grid> */}- <input- style={{ display: 'none' }}- ref={input => {- fileInput = input;- }}- accept="*"- type="file"- multiple- onChange={handleFileInputChange}- />- </AccordionDetails>- </Accordion>- <Grid item style={{ marginTop: 20 }} xs={12}>- {noSuitableLocation ? (- <Typography variant="caption">- {i18n.t('noSuitableLocation')}- </Typography>- ) : (- <Typography- style={{ display: 'flex', alignItems: 'center' }}- variant="caption"- >- <InfoIcon style={{ paddingRight: 10 }} />- {i18n.t('core:entriesWillBeCreatedIn') +- ' ' +- (currentLocation ? currentLocation.name : '') +- ' ' +- targetDirectoryPath}- </Typography>- )}- </Grid>- </DialogContent>- </Dialog>- );-}--function mapStateToProps(state) {- return {- firstRWLocation: getFirstRWLocation(state),- keyBindings: getKeyBindingObject(state),- selectedEntries: getSelectedEntries(state),- currentDirectoryPath: getDirectoryPath(state),- currentDirectoryPerspective: getCurrentDirectoryPerspective(state),- currentLocation: getCurrentLocation(state)- };-}--function mapActionCreatorsToProps(dispatch) {- return bindActionCreators(- {- openLocation: AppActions.openLocation,- createFileAdvanced: AppActions.createFileAdvanced,- showNotification: AppActions.showNotification,- reflectCreateEntries: AppActions.reflectCreateEntries,- toggleLocationDialog: AppActions.toggleLocationDialog,- toggleCreateDirectoryDialog: AppActions.toggleCreateDirectoryDialog,- uploadFilesAPI: IOActions.uploadFilesAPI,- downloadFile: IOActions.downloadFile,- onUploadProgress: AppActions.onUploadProgress,- toggleUploadDialog: AppActions.toggleUploadDialog,- resetProgress: AppActions.resetProgress,- setProgress: AppActions.setProgress- },- dispatch- );-}--export default connect(- mapStateToProps,- mapActionCreatorsToProps-)(withStyles(styles)(CreateDialog));diff --git a/app/components/dialogs/NewEntryDialog.tsx b/app/components/dialogs/NewEntryDialog.tsxnew file mode 100644index 000000000..cddb4c1a7--- /dev/null+++ b/app/components/dialogs/NewEntryDialog.tsx@@ -0,0 +1,95 @@+/**+ * 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 from 'react';+import Typography from '@mui/material/Typography';+import DialogContent from '@mui/material/DialogContent';+import DialogTitle from '@mui/material/DialogTitle';+import Dialog from '@mui/material/Dialog';+import Paper from '@mui/material/Paper';+import { Accordion, AccordionDetails, AccordionSummary } from '@mui/material';+import DraggablePaper from '-/components/DraggablePaper';+import i18n from '-/services/i18n';+import DialogCloseButton from '-/components/dialogs/DialogCloseButton';+import useTheme from '@mui/styles/useTheme';+import useMediaQuery from '@mui/material/useMediaQuery';+import { ExpandIcon } from '-/components/CommonIcons';+import CreateDirectory from '-/components/dialogs/components/CreateDirectory';+import CreateFile from '-/components/dialogs/components/CreateFile';+import TargetPath from '-/components/dialogs/components/TargetPath';+import { TargetPathContextProvider } from '-/components/dialogs/hooks/TargetPathContextProvider';++interface Props {+ open: boolean;+ onClose: () => void;+}++function NewEntryDialog(props: Props) {+ const { open, onClose } = props;++ const theme = useTheme();+ const fullScreen = useMediaQuery(theme.breakpoints.down('md'));+ return (+ <TargetPathContextProvider>+ <Dialog+ open={open}+ onClose={onClose}+ fullScreen={fullScreen}+ keepMounted+ aria-labelledby="draggable-dialog-title"+ PaperComponent={fullScreen ? Paper : DraggablePaper}+ scroll="paper"+ >+ <DialogTitle style={{ cursor: 'move' }} id="draggable-dialog-title">+ {i18n.t('core:create') + '...'}+ <DialogCloseButton testId="closeCreateDialogTID" onClose={onClose} />+ </DialogTitle>+ <DialogContent+ style={{+ minWidth: 200,+ minHeight: 300,+ marginBottom: 20,+ overflow: 'overlay'+ }}+ data-tid="keyboardShortCutsDialog"+ >+ <Accordion style={{ marginTop: 5 }} defaultExpanded>+ <AccordionDetails style={{ paddingTop: 16 }}>+ <CreateFile onClose={onClose} />+ </AccordionDetails>+ </Accordion>+ <Accordion>+ <AccordionSummary+ expandIcon={<ExpandIcon />}+ aria-controls="panelGeneral-content"+ id="panelGeneral-header"+ >+ <Typography>{i18n.t('core:moreOperations')}</Typography>+ </AccordionSummary>+ <AccordionDetails>+ <CreateDirectory onClose={onClose} />+ </AccordionDetails>+ </Accordion>+ <TargetPath />+ </DialogContent>+ </Dialog>+ </TargetPathContextProvider>+ );+}++export default NewEntryDialog;diff --git a/app/components/dialogs/NewFileDialog.tsx b/app/components/dialogs/NewFileDialog.tsxnew file mode 100644index 000000000..b57844236--- /dev/null+++ b/app/components/dialogs/NewFileDialog.tsx@@ -0,0 +1,75 @@+/**+ * 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 from 'react';+import DialogContent from '@mui/material/DialogContent';+import DialogTitle from '@mui/material/DialogTitle';+import Dialog from '@mui/material/Dialog';+import Paper from '@mui/material/Paper';+import DraggablePaper from '-/components/DraggablePaper';+import i18n from '-/services/i18n';+import DialogCloseButton from '-/components/dialogs/DialogCloseButton';+import useTheme from '@mui/styles/useTheme';+import useMediaQuery from '@mui/material/useMediaQuery';+import CreateFile from '-/components/dialogs/components/CreateFile';+import TargetPath from '-/components/dialogs/components/TargetPath';+import { TargetPathContextProvider } from '-/components/dialogs/hooks/TargetPathContextProvider';++interface Props {+ open: boolean;+ onClose: () => void;+}++function NewFileDialog(props: Props) {+ const { open, onClose } = props;++ const theme = useTheme();+ const fullScreen = useMediaQuery(theme.breakpoints.down('md'));+ return (+ <TargetPathContextProvider>+ <Dialog+ open={open}+ onClose={onClose}+ fullScreen={fullScreen}+ keepMounted+ aria-labelledby="draggable-dialog-title"+ PaperComponent={fullScreen ? Paper : DraggablePaper}+ scroll="paper"+ >+ <DialogTitle style={{ cursor: 'move' }} id="draggable-dialog-title">+ {i18n.t('core:create') + '...'}+ <DialogCloseButton testId="closeCreateDialogTID" onClose={onClose} />+ </DialogTitle>+ <DialogContent+ style={{+ minWidth: 200,+ minHeight: 200,+ marginBottom: 20,+ overflow: 'overlay'+ }}+ data-tid="keyboardShortCutsDialog"+ >+ <CreateFile onClose={onClose} />+ <TargetPath />+ </DialogContent>+ </Dialog>+ </TargetPathContextProvider>+ );+}++export default NewFileDialog;diff --git a/app/components/dialogs/components/CreateDirectory.tsx b/app/components/dialogs/components/CreateDirectory.tsxnew file mode 100644index 000000000..2e4f6b44c--- /dev/null+++ b/app/components/dialogs/components/CreateDirectory.tsx@@ -0,0 +1,303 @@+/**+ * 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, { useRef, useState } from 'react';+import { connect } from 'react-redux';+import { bindActionCreators } from 'redux';+import { saveAs } from 'file-saver';+import Button from '@mui/material/Button';+import ButtonGroup from '@mui/material/ButtonGroup';+import Grid from '@mui/material/Grid';+import withStyles from '@mui/styles/withStyles';+import { Progress } from 'aws-sdk/clients/s3';+import AppConfig from '-/AppConfig';+import i18n from '-/services/i18n';+import { actions as AppActions, NotificationTypes } from '-/reducers/app';+import IOActions from '-/reducers/io-actions';+import { TS } from '-/tagspaces.namespace';+import PlatformIO from '-/services/platform-facade';+import Tooltip from '-/components/Tooltip';+import TextField from '@mui/material/TextField';+import { useTargetPathContext } from '-/components/dialogs/hooks/useTargetPathContext';+import Typography from '@mui/material/Typography';++const styles: any = () => ({+ createButton: {+ width: '100%',+ textAlign: 'center'+ }+});++interface Props {+ classes: any;+ onClose: () => void;+ onUploadProgress: (progress: Progress, response: any) => void;+ toggleUploadDialog: () => void;+ resetProgress: () => void;+ setProgress: (path: string, progress: number, abort?: string) => void;+ downloadFile: (+ url: string,+ destination: string,+ onDownloadProgress?: (progress: Progress, response: any) => void+ ) => any;+ uploadFilesAPI: (+ files: Array<File>,+ destination: string,+ onUploadProgress?: (progress: Progress, response: any) => void+ ) => any;+ toggleCreateDirectoryDialog: () => void;+ reflectCreateEntries: (fsEntries: Array<TS.FileSystemEntry>) => void;+ showNotification: (+ message: string,+ notificationType?: string,+ autohide?: boolean+ ) => void;+ toggleLocationDialog: () => void;+}++function CreateDirectory(props: Props) {+ const {+ classes,+ onClose,+ showNotification,+ toggleCreateDirectoryDialog,+ toggleLocationDialog+ } = props;++ const { targetDirectoryPath } = useTargetPathContext();+ const fileUrl = useRef<string>();+ const [invalidURL, setInvalidURL] = useState<boolean>(false);+ let fileInput: HTMLInputElement;++ const noSuitableLocation = !targetDirectoryPath;++ /*function loadLocation() {+ if (!currentDirectoryPath && firstRWLocation) {+ openLocation(firstRWLocation);+ }+ }*/++ function addFile() {+ // loadLocation();+ fileInput.click();+ }++ function handleFileInputChange(selection: any) {+ // console.log("Selected File: "+JSON.stringify(selection.currentTarget.files[0]));+ // const file = selection.currentTarget.files[0];+ props.resetProgress();+ props.toggleUploadDialog();+ props+ .uploadFilesAPI(+ Array.from(selection.currentTarget.files),+ targetDirectoryPath,+ props.onUploadProgress+ )+ .then(fsEntries => {+ props.reflectCreateEntries(fsEntries);+ return true;+ })+ .catch(error => {+ console.log('uploadFiles', error);+ });+ onClose();+ }++ const handleUrlChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ fileUrl.current = event.target.value;+ };++ function downloadURL() {+ if (fileUrl.current) {+ try {+ const url = new URL(fileUrl.current);+ if (invalidURL) {+ setInvalidURL(false);+ }+ let fileName;+ let pathParts;+ if (url.pathname) {+ const delimiterIndex = url.pathname.lastIndexOf('/');+ if (delimiterIndex > -1) {+ fileName = url.pathname.substring(delimiterIndex + 1);+ if (!fileName) {+ pathParts = url.pathname.split('/').filter(Boolean);+ }+ } else {+ fileName = url.pathname;+ }+ }+ if (!fileName) {+ fileName =+ url.hostname ++ (pathParts && pathParts.length > 0 ? pathParts.join('-') : '') ++ '.html';+ } else if (fileName.indexOf('.') === -1) {+ fileName = url.hostname + '-' + fileName + '.html';+ }+ if (PlatformIO.haveObjectStoreSupport() || AppConfig.isElectron) {+ props.resetProgress();+ props.toggleUploadDialog();+ props+ .downloadFile(+ fileUrl.current,+ targetDirectoryPath ++ PlatformIO.getDirSeparator() ++ decodeURIComponent(fileName),+ props.onUploadProgress+ )+ .then(() => {+ if (PlatformIO.haveObjectStoreSupport()) {+ // currently objectStore location in downloadFile use saveFilePromise and this function not have progress handling+ props.setProgress(fileUrl.current, 100);+ }+ })+ .catch(e => {+ console.log('downloadFile error:', e);+ props.setProgress(fileUrl.current, -1, i18n.t('core:errorCORS'));+ showNotification(+ 'downloadFile error' + e.message,+ NotificationTypes.error,+ true+ );+ });+ } else {+ saveAs(fileUrl.current, decodeURIComponent(fileName));+ }+ onClose();+ } catch (ex) {+ setInvalidURL(true);+ console.error('downloadURL', ex);+ }+ }+ }++ return (+ <>+ <Grid style={{ marginTop: 20 }} item xs={12}>+ <Button+ variant="outlined"+ onClick={() => {+ onClose();+ toggleLocationDialog();+ }}+ className={classes.createButton}+ data-tid="createLocationButton"+ >+ <Tooltip title={i18n.t('createLocationTitle')}>+ <Typography variant="button" display="block" gutterBottom>+ {i18n.t('core:createLocation')}+ </Typography>+ </Tooltip>+ </Button>+ </Grid>+ <Grid item xs={12}>+ <Button+ variant="outlined"+ onClick={() => {+ onClose();+ toggleCreateDirectoryDialog();+ }}+ className={classes.createButton}+ data-tid="newSubDirectory"+ disabled={noSuitableLocation}+ >+ {i18n.t('core:newSubdirectory')}+ </Button>+ </Grid>+ <Grid style={{ marginTop: 20 }} item xs={12}>+ <Tooltip title={i18n.t('core:addFilesTitle')}>+ <Button+ variant="outlined"+ onClick={addFile}+ className={classes.createButton}+ data-tid="addFilesButton"+ disabled={noSuitableLocation}+ >+ {i18n.t('addFiles')}+ </Button>+ </Tooltip>+ </Grid>+ <Grid item xs={12}>+ <TextField+ error={invalidURL}+ label={i18n.t('core:url')}+ margin="dense"+ name="name"+ fullWidth={true}+ data-tid="newUrlTID"+ onKeyDown={event => {+ if (event.key === 'Enter') {+ downloadURL();+ }+ }}+ onChange={handleUrlChange}+ />+ </Grid>+ <Grid item xs={12}>+ <ButtonGroup+ style={{+ textAlign: 'center',+ width: '100%'+ }}+ >+ <Button+ data-tid="cancelRenameEntryTID"+ className={classes.createButton}+ onClick={() => downloadURL()}+ >+ {i18n.t('core:downloadFile')}+ </Button>+ </ButtonGroup>+ </Grid>+ <input+ style={{ display: 'none' }}+ ref={input => {+ fileInput = input;+ }}+ accept="*"+ type="file"+ multiple+ onChange={handleFileInputChange}+ />+ </>+ );+}++function mapActionCreatorsToProps(dispatch) {+ return bindActionCreators(+ {+ showNotification: AppActions.showNotification,+ reflectCreateEntries: AppActions.reflectCreateEntries,+ toggleCreateDirectoryDialog: AppActions.toggleCreateDirectoryDialog,+ uploadFilesAPI: IOActions.uploadFilesAPI,+ downloadFile: IOActions.downloadFile,+ onUploadProgress: AppActions.onUploadProgress,+ toggleUploadDialog: AppActions.toggleUploadDialog,+ resetProgress: AppActions.resetProgress,+ setProgress: AppActions.setProgress,+ toggleLocationDialog: AppActions.toggleLocationDialog+ },+ dispatch+ );+}++export default connect(+ undefined,+ mapActionCreatorsToProps+)(withStyles(styles)(CreateDirectory));diff --git a/app/components/dialogs/components/CreateFile.tsx b/app/components/dialogs/components/CreateFile.tsxnew file mode 100644index 000000000..03761d9db--- /dev/null+++ b/app/components/dialogs/components/CreateFile.tsx@@ -0,0 +1,282 @@+/**+ * 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, { useReducer, useRef, useState } from 'react';+import { connect } from 'react-redux';+import { bindActionCreators } from 'redux';+import Button from '@mui/material/Button';+import ButtonGroup from '@mui/material/ButtonGroup';+import Typography from '@mui/material/Typography';+import Grid from '@mui/material/Grid';+import withStyles from '@mui/styles/withStyles';+import { formatDateTime4Tag } from '@tagspaces/tagspaces-common/misc';+import AppConfig from '-/AppConfig';+import i18n from '-/services/i18n';+import {+ actions as AppActions,+ getDirectoryPath,+ getSelectedEntries,+ getCurrentDirectoryPerspective+} from '-/reducers/app';+import { getFirstRWLocation } from '-/reducers/locations';+import { TS } from '-/tagspaces.namespace';+import Tooltip from '-/components/Tooltip';+import TextField from '@mui/material/TextField';+import FormHelperText from '@mui/material/FormHelperText';+import { FormControl } from '@mui/material';+import { fileNameValidation } from '-/services/utils-io';+import { useTargetPathContext } from '-/components/dialogs/hooks/useTargetPathContext';++const styles: any = () => ({+ createButton: {+ width: '100%',+ textAlign: 'center'+ }+});++interface Props {+ open: boolean;+ classes: any;+ firstRWLocation: TS.Location;+ selectedEntries: Array<TS.FileSystemEntry>;+ currentDirectoryPath: string | null;+ currentDirectoryPerspective: string;+ openLocation: (location: TS.Location) => void;+ createFileAdvanced: (+ targetPath: string,+ fileName: string,+ content: string,+ fileType: string+ ) => void;+ onClose: () => void;+}++function CreateFile(props: Props) {+ const {+ classes,+ onClose,+ createFileAdvanced,+ openLocation,+ currentDirectoryPath,+ firstRWLocation+ } = props;++ const { targetDirectoryPath } = useTargetPathContext();++ const fileName = useRef<string>(+ 'note' ++ AppConfig.beginTagContainer ++ formatDateTime4Tag(new Date(), true) ++ AppConfig.endTagContainer+ );+ const [inputError, setInputError] = useState<boolean>(false);+ const [ignored, forceUpdate] = useReducer(x => x + 1, 0);+ const fileContent = '';++ const noSuitableLocation = !targetDirectoryPath;++ function loadLocation() {+ if (!currentDirectoryPath && firstRWLocation) {+ openLocation(firstRWLocation);+ }+ }++ function createRichTextFile() {+ if (targetDirectoryPath && !fileNameValidation(fileName.current)) {+ loadLocation();+ createFileAdvanced(+ targetDirectoryPath,+ fileName.current,+ fileContent,+ 'html'+ );+ onClose();+ }+ }++ function createTextFile() {+ if (targetDirectoryPath && !fileNameValidation(fileName.current)) {+ loadLocation();+ createFileAdvanced(+ targetDirectoryPath,+ fileName.current,+ fileContent,+ 'txt'+ );+ onClose();+ }+ }++ function createMarkdownFile() {+ if (targetDirectoryPath && !fileNameValidation(fileName.current)) {+ loadLocation();+ createFileAdvanced(+ targetDirectoryPath,+ fileName.current,+ fileContent,+ 'md'+ );+ onClose();+ }+ }++ const onInputFocus = event => {+ if (fileName.current) {+ event.preventDefault();+ const { target } = event;+ target.focus();+ /*const indexOfBracket = fileName.current.indexOf(+ AppConfig.beginTagContainer+ );*/+ let endRange = fileName.current.length;+ // if (indexOfBracket > 0) {+ // endRange = indexOfBracket;+ // }+ target.setSelectionRange(0, endRange);+ }+ };++ const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ fileName.current = event.target.value;+ handleValidation();+ };++ const handleValidation = () => {+ let noValid = fileNameValidation(fileName.current);++ if (noValid) {+ if (inputError !== noValid) {+ setInputError(noValid);+ } else {+ forceUpdate();+ }+ } else {+ setInputError(noValid);+ }+ };++ return (+ <Grid style={{ flexGrow: 1, width: '100%' }} container spacing={1}>+ <Grid item xs={12}>+ <FormControl fullWidth={true} error={inputError}>+ <TextField+ autoFocus+ error={inputError}+ margin="dense"+ name="entryName"+ label={i18n.t('core:newFileName')}+ onChange={handleInputChange}+ onFocus={onInputFocus}+ onKeyDown={event => {+ if (event.key === 'Enter' || event.keyCode === 13) {+ event.preventDefault();+ event.stopPropagation();+ createMarkdownFile();+ }+ }}+ defaultValue={fileName.current}+ disabled={noSuitableLocation}+ fullWidth={true}+ data-tid="newEntryDialogInputTID"+ />+ {inputError && (+ <FormHelperText>{i18n.t('core:fileNameHelp')}</FormHelperText>+ )}+ </FormControl>+ </Grid>+ <Grid item xs={12}>+ <ButtonGroup+ style={{+ textAlign: 'center',+ width: '100%'+ }}+ >+ <Button+ // variant="contained"+ onClick={createMarkdownFile}+ className={classes.createButton}+ data-tid="createMarkdownButton"+ disabled={noSuitableLocation}+ >+ <Tooltip title={i18n.t('createMarkdownTitle')}>+ <Typography+ variant="button"+ style={{ fontWeight: 'bold' }}+ display="block"+ gutterBottom+ >+ {i18n.t('createMarkdown')}+ </Typography>+ </Tooltip>+ </Button>+ <Button+ // variant="contained"+ onClick={createRichTextFile}+ className={classes.createButton}+ data-tid="createRichTextFileButton"+ disabled={noSuitableLocation}+ >+ <Tooltip title={i18n.t('createNoteTitle')}>+ <Typography variant="button" display="block" gutterBottom>+ {i18n.t('createRichTextFile')}+ </Typography>+ </Tooltip>+ </Button>+ <Button+ // variant="contained"+ onClick={createTextFile}+ className={classes.createButton}+ data-tid="createTextFileButton"+ disabled={noSuitableLocation}+ >+ <Tooltip title={i18n.t('createTextFileTitle')}>+ <Typography variant="button" display="block" gutterBottom>+ {i18n.t('createTextFile')}+ </Typography>+ </Tooltip>+ </Button>+ </ButtonGroup>+ </Grid>+ </Grid>+ );+}++function mapStateToProps(state) {+ return {+ firstRWLocation: getFirstRWLocation(state),+ //keyBindings: getKeyBindingObject(state),+ selectedEntries: getSelectedEntries(state),+ currentDirectoryPath: getDirectoryPath(state),+ currentDirectoryPerspective: getCurrentDirectoryPerspective(state)+ };+}++function mapActionCreatorsToProps(dispatch) {+ return bindActionCreators(+ {+ openLocation: AppActions.openLocation,+ createFileAdvanced: AppActions.createFileAdvanced+ },+ dispatch+ );+}++export default connect(+ mapStateToProps,+ mapActionCreatorsToProps+)(withStyles(styles)(CreateFile));diff --git a/app/components/dialogs/components/TargetPath.tsx b/app/components/dialogs/components/TargetPath.tsxnew file mode 100644index 000000000..fb20823df--- /dev/null+++ b/app/components/dialogs/components/TargetPath.tsx@@ -0,0 +1,55 @@+/**+ * 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 from 'react';+import { useSelector } from 'react-redux';+import Typography from '@mui/material/Typography';+import Grid from '@mui/material/Grid';+import i18n from '-/services/i18n';+import { getCurrentLocation } from '-/reducers/locations';+import { InfoIcon } from '-/components/CommonIcons';+import { useTargetPathContext } from '-/components/dialogs/hooks/useTargetPathContext';++function TargetPath() {+ const currentLocation = useSelector(getCurrentLocation);+ const { targetDirectoryPath } = useTargetPathContext();++ return (+ <Grid item style={{ marginTop: 20 }} xs={12}>+ {targetDirectoryPath ? (+ <Typography+ style={{ display: 'flex', alignItems: 'center' }}+ variant="caption"+ >+ <InfoIcon style={{ paddingRight: 10 }} />+ {i18n.t('core:entriesWillBeCreatedIn') ++ ' ' ++ (currentLocation ? currentLocation.name : '') ++ ' ' ++ targetDirectoryPath}+ </Typography>+ ) : (+ <Typography variant="caption">+ {i18n.t('noSuitableLocation')}+ </Typography>+ )}+ </Grid>+ );+}++export default TargetPath;diff --git a/app/components/dialogs/hooks/TargetPathContextProvider.tsx b/app/components/dialogs/hooks/TargetPathContextProvider.tsxnew file mode 100644index 000000000..f8a8e6a76--- /dev/null+++ b/app/components/dialogs/hooks/TargetPathContextProvider.tsx@@ -0,0 +1,80 @@+/**+ * 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, { createContext, useMemo } from 'react';+import { useSelector } from 'react-redux';+import {+ getDirectoryPath,+ getSelectedEntries,+ getCurrentDirectoryPerspective+} from '-/reducers/app';+import { getFirstRWLocation } from '-/reducers/locations';+import { PerspectiveIDs } from '-/perspectives';++type TargetPathContextData = {+ targetDirectoryPath: string;+};++export const TargetPathContext = createContext<TargetPathContextData>({+ targetDirectoryPath: undefined+});++export type TargetPathContextProviderProps = {+ children: React.ReactNode;+};++export const TargetPathContextProvider = ({+ children+}: TargetPathContextProviderProps) => {+ const firstRWLocation = useSelector(getFirstRWLocation);+ const selectedEntries = useSelector(getSelectedEntries);+ const currentDirectoryPath = useSelector(getDirectoryPath);+ const currentDirectoryPerspective = useSelector(+ getCurrentDirectoryPerspective+ );++ const context = useMemo(() => {+ let targetDirectoryPath = currentDirectoryPath;+ if (+ currentDirectoryPerspective === PerspectiveIDs.KANBAN &&+ selectedEntries &&+ selectedEntries.length === 1 &&+ !selectedEntries[0].isFile+ ) {+ targetDirectoryPath = selectedEntries[0].path;+ }++ if (!targetDirectoryPath && firstRWLocation) {+ targetDirectoryPath = firstRWLocation.path;+ }+ return {+ targetDirectoryPath+ };+ }, [+ firstRWLocation,+ selectedEntries,+ currentDirectoryPath,+ currentDirectoryPerspective+ ]);++ return (+ <TargetPathContext.Provider value={context}>+ {children}+ </TargetPathContext.Provider>+ );+};diff --git a/app/components/dialogs/hooks/useTargetPathContext.tsx b/app/components/dialogs/hooks/useTargetPathContext.tsxnew file mode 100644index 000000000..85d72fab0--- /dev/null+++ b/app/components/dialogs/hooks/useTargetPathContext.tsx@@ -0,0 +1,5 @@+import { useContext } from 'react';++import { TargetPathContext } from '-/components/dialogs/hooks/TargetPathContextProvider';++export const useTargetPathContext = () => useContext(TargetPathContext);diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsxindex 948feab62..cc7f8c2b8 100644--- a/app/components/menus/DirectoryMenu.tsx+++ b/app/components/menus/DirectoryMenu.tsx@@ -67,7 +67,7 @@ interface Props {openFsEntry: (fsEntry: TS.FileSystemEntry) => void;openAddRemoveTagsDialog?: () => void;reflectCreateEntry?: (path: string, isFile: boolean) => void;- toggleCreateFileDialog?: () => void;+ toggleNewEntryDialog?: () => void;uploadFilesAPI: (files: Array<File>,destination: string,@@ -242,7 +242,7 @@ function DirectoryMenu(props: Props) {}*/function createNewFile() {- props.toggleCreateFileDialog();+ props.toggleNewEntryDialog();}function showInFileManager() {@@ -493,7 +493,7 @@ function mapDispatchToProps(dispatch) {onUploadProgress: AppActions.onUploadProgress,toggleUploadDialog: AppActions.toggleUploadDialog,toggleProgressDialog: AppActions.toggleProgressDialog,- toggleCreateFileDialog: AppActions.toggleCreateFileDialog,+ toggleNewEntryDialog: AppActions.toggleNewEntryDialog,toggleCreateDirectoryDialog: AppActions.toggleCreateDirectoryDialog,toggleProTeaser: AppActions.toggleProTeaser,resetProgress: AppActions.resetProgress,diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsxindex b2c9f1e61..5abceeb32 100644--- a/app/containers/MainPage.tsx+++ b/app/containers/MainPage.tsx@@ -36,7 +36,7 @@ import FolderContainer from '../components/FolderContainer';import EntryContainer from '../components/EntryContainer';import SettingsDialog from '../components/dialogs/settings/SettingsDialog';import CreateDirectoryDialog from '../components/dialogs/CreateDirectoryDialog';-import CreateDialog from '../components/dialogs/CreateDialog';+import NewEntryDialog from '../components/dialogs/NewEntryDialog';import {getDesktopMode,getKeyBindingObject,@@ -60,7 +60,8 @@ import {isEditTagDialogOpened,isCreateDirectoryOpened,isUploadDialogOpened,- isCreateFileDialogOpened,+ isNewEntryDialogOpened,+ isNewFileDialogOpened,isSettingsDialogOpened,isOpenLinkDialogOpened,isReadOnlyMode,@@ -91,6 +92,7 @@ import { actions as LocationIndexActions } from '-/reducers/location-index';import MoveOrCopyFilesDialog from '-/components/dialogs/MoveOrCopyFilesDialog';import PlatformIO from '-/services/platform-facade';import { Pro } from '-/pro';+import NewFileDialog from '-/components/dialogs/NewFileDialog';const drawerWidth = 320;const body = document.getElementsByTagName('body')[0];@@ -135,7 +137,8 @@ interface Props {theme: any;isReadOnlyMode: boolean;isSettingsDialogOpened: boolean;- isCreateFileDialogOpened: boolean;+ isNewEntryDialogOpened: boolean;+ isNewFileDialogOpened: boolean;isCreateDirectoryOpened: any;toggleCreateDirectoryDialog: () => void;isAboutDialogOpened: boolean;@@ -161,7 +164,8 @@ interface Props {setZoomResetApp: () => void; // needed by electron-menussetZoomInApp: () => void; // needed by electron-menussetZoomOutApp: () => void; // needed by electron-menus- toggleCreateFileDialog: () => void; // needed by electron-menus+ toggleNewEntryDialog: () => void; // needed by electron-menus+ toggleNewFileDialog: () => void; // needed by electron-menusshowCreateDirectoryDialog: () => void; // needed by electron-menustoggleSettingsDialog: () => void; // needed by electron-menustoggleKeysDialog: () => void; // needed by electron-menus@@ -582,7 +586,8 @@ function MainPage(props: Props) {toggleAboutDialog,toggleLocationDialog,toggleCreateDirectoryDialog,- toggleCreateFileDialog,+ toggleNewEntryDialog,+ toggleNewFileDialog,toggleUploadDialog,toggleProgressDialog,toggleEditTagDialog,@@ -783,14 +788,16 @@ function MainPage(props: Props) {reflect={props.isCreateDirectoryOpened?.reflect}/>)}- {props.isCreateFileDialogOpened && (- <CreateDialog- open={props.isCreateFileDialogOpened}- onClose={toggleCreateFileDialog}- // selectedDirectoryPath={selectedDirectoryPath.current || directoryPath}- /*chooseDirectoryPath={currentPath =>- setSelectedDirectoryPath(currentPath)- }*/+ {props.isNewEntryDialogOpened && (+ <NewEntryDialog+ open={props.isNewEntryDialogOpened}+ onClose={toggleNewEntryDialog}+ />+ )}+ {props.isNewFileDialogOpened && (+ <NewFileDialog+ open={props.isNewFileDialogOpened}+ onClose={toggleNewFileDialog}/>)}<SettingsDialog@@ -914,7 +921,8 @@ function mapStateToProps(state) {return {isEditTagDialogOpened: isEditTagDialogOpened(state),isCreateDirectoryOpened: isCreateDirectoryOpened(state),- isCreateFileDialogOpened: isCreateFileDialogOpened(state),+ isNewEntryDialogOpened: isNewEntryDialogOpened(state),+ isNewFileDialogOpened: isNewFileDialogOpened(state),isSettingsDialogOpened: isSettingsDialogOpened(state),isAboutDialogOpened: isAboutDialogOpened(state),isLocationDialogOpened: isLocationDialogOpened(state),@@ -962,7 +970,8 @@ function mapDispatchToProps(dispatch) {setZoomResetApp: SettingsActions.setZoomResetApp,setZoomInApp: SettingsActions.setZoomInApp,setZoomOutApp: SettingsActions.setZoomOutApp,- toggleCreateFileDialog: AppActions.toggleCreateFileDialog,+ toggleNewEntryDialog: AppActions.toggleNewEntryDialog,+ toggleNewFileDialog: AppActions.toggleNewFileDialog,showCreateDirectoryDialog: AppActions.showCreateDirectoryDialog,toggleSettingsDialog: AppActions.toggleSettingsDialog,toggleKeysDialog: AppActions.toggleKeysDialog,@@ -1012,7 +1021,8 @@ const areEqual = (prevProp, nextProp) =>nextProp.isAboutDialogOpened === prevProp.isAboutDialogOpened &&JSON.stringify(nextProp.isCreateDirectoryOpened) ===JSON.stringify(prevProp.isCreateDirectoryOpened) &&- nextProp.isCreateFileDialogOpened === prevProp.isCreateFileDialogOpened &&+ nextProp.isNewEntryDialogOpened === prevProp.isNewEntryDialogOpened &&+ nextProp.isNewFileDialogOpened === prevProp.isNewFileDialogOpened &&nextProp.isDeleteMultipleEntriesDialogOpened ===prevProp.isDeleteMultipleEntriesDialogOpened &&nextProp.isDesktopMode === prevProp.isDesktopMode &&diff --git a/app/containers/RendererListener.ts b/app/containers/RendererListener.tsindex 15dd356c1..8f419f4ec 100644--- a/app/containers/RendererListener.ts+++ b/app/containers/RendererListener.ts@@ -29,7 +29,7 @@ export default function listen(props) {// console.log('Global events: ' + arg);switch (arg) {case 'new-text-file':- props.toggleCreateFileDialog();+ props.toggleNewEntryDialog();break;case 'open-search':props.setSearchQuery({ textQuery: '' });diff --git a/app/electron-tray-menu.ts b/app/electron-tray-menu.tsindex 327d60765..2da6ed5e4 100644--- a/app/electron-tray-menu.ts+++ b/app/electron-tray-menu.ts@@ -65,7 +65,7 @@ export default function buildTrayIconMenu(mainPageProps: any, i18n, isMacLike) {},{label: i18n.t('newFileNote') + cKey + '+Shift+N',- click: mainPageProps.toggleCreateFileDialog+ click: mainPageProps.toggleNewEntryDialog},{type: 'separator'diff --git a/app/main.dev.ts b/app/main.dev.tsindex 28f62936c..6883fcc35 100644--- a/app/main.dev.ts+++ b/app/main.dev.ts@@ -359,7 +359,7 @@ function buildTrayMenu() {resumePlayback,createNewWindowInstance,openSearch: showSearch,- toggleCreateFileDialog: newTextFile,+ toggleNewEntryDialog: newTextFile,openNextFile: getNextFile,openPrevFile: getPreviousFile,quitApp: reloadApp@@ -374,7 +374,7 @@ function buildAppMenu() {{showTagSpaces,openSearch: showSearch,- toggleCreateFileDialog: newTextFile,+ toggleNewEntryDialog: newTextFile,openNextFile: getNextFile,openPrevFile: getPreviousFile,quitApp: reloadApp,diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 83c6718fc..f3a7c25ca 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -135,7 +135,8 @@ export const types = {TOGGLE_THIRD_PARTY_LIBS_DIALOG: 'APP/TOGGLE_THIRD_PARTY_LIBS_DIALOG',TOGGLE_SETTINGS_DIALOG: 'APP/TOGGLE_SETTINGS_DIALOG',TOGGLE_CREATE_DIRECTORY_DIALOG: 'APP/TOGGLE_CREATE_DIRECTORY_DIALOG',- TOGGLE_CREATE_FILE_DIALOG: 'APP/TOGGLE_CREATE_FILE_DIALOG',+ TOGGLE_NEW_ENTRY_DIALOG: 'APP/TOGGLE_NEW_ENTRY_DIALOG',+ TOGGLE_NEW_FILE_DIALOG: 'APP/TOGGLE_NEW_FILE_DIALOG',TOGGLE_DELETE_MULTIPLE_ENTRIES_DIALOG:'APP/TOGGLE_DELETE_MULTIPLE_ENTRIES_DIALOG',TOGGLE_IMPORT_KANBAN_DIALOG: 'APP/TOGGLE_IMPORT_KANBAN_DIALOG',@@ -250,7 +251,8 @@ export const initialState = {proTeaserIndex: -1,onboardingDialogOpened: false,keysDialogOpened: false,- createFileDialogOpened: false,+ isNewEntryDialogOpened: false,+ isNewFileDialogOpened: false,licenseDialogOpened: false,thirdPartyLibsDialogOpened: false,settingsDialogOpened: false,@@ -482,10 +484,16 @@ export default (state: any = initialState, action: any) => {case types.TOGGLE_KEYBOARD_DIALOG: {return { ...state, keysDialogOpened: !state.keysDialogOpened };}- case types.TOGGLE_CREATE_FILE_DIALOG: {+ case types.TOGGLE_NEW_ENTRY_DIALOG: {return {...state,- createFileDialogOpened: !state.createFileDialogOpened+ isNewEntryDialogOpened: !state.isNewEntryDialogOpened+ };+ }+ case types.TOGGLE_NEW_FILE_DIALOG: {+ return {+ ...state,+ isNewFileDialogOpened: !state.isNewFileDialogOpened};}case types.TOGGLE_DELETE_MULTIPLE_ENTRIES_DIALOG: {@@ -1229,7 +1237,7 @@ export const actions = {));} else {- dispatch(actions.toggleCreateFileDialog());+ dispatch(actions.toggleNewEntryDialog());}},toggleEditTagDialog: (tag: TS.Tag) => ({@@ -1254,7 +1262,8 @@ export const actions = {type: types.TOGGLE_CREATE_DIRECTORY_DIALOG,props}),- toggleCreateFileDialog: () => ({ type: types.TOGGLE_CREATE_FILE_DIALOG }),+ toggleNewEntryDialog: () => ({ type: types.TOGGLE_NEW_ENTRY_DIALOG }),+ toggleNewFileDialog: () => ({ type: types.TOGGLE_NEW_FILE_DIALOG }),toggleDeleteMultipleEntriesDialog: () => ({type: types.TOGGLE_DELETE_MULTIPLE_ENTRIES_DIALOG}),@@ -3071,8 +3080,10 @@ export const isSettingsDialogOpened = (state: any) =>state.app.settingsDialogOpened;export const isCreateDirectoryOpened = (state: any) =>state.app.createDirectoryDialogOpened;-export const isCreateFileDialogOpened = (state: any) =>- state.app.createFileDialogOpened;+export const isNewEntryDialogOpened = (state: any) =>+ state.app.isNewEntryDialogOpened;+export const isNewFileDialogOpened = (state: any) =>+ state.app.isNewFileDialogOpened;export const isDeleteMultipleEntriesDialogOpened = (state: any) =>state.app.deleteMultipleEntriesDialogOpened;export const isImportKanBanDialogOpened = (state: any) =>diff --git a/app/reducers/locations.ts b/app/reducers/locations.tsindex d930e4ec3..f1107d051 100644--- a/app/reducers/locations.ts+++ b/app/reducers/locations.ts@@ -305,7 +305,7 @@ export const getCurrentLocation = (state: any): TS.Location | undefined => {);return foundLocation ? foundLocation : undefined;};-export const getFirstRWLocation = (state: any): string | undefined => {+export const getFirstRWLocation = (state: any): TS.Location | undefined => {let foundLocation = state.locations.find(location => location.isDefault && !location.isReadOnly);diff --git a/app/services/electron-menus.ts b/app/services/electron-menus.tsindex 09184de43..465ee557d 100644--- a/app/services/electron-menus.ts+++ b/app/services/electron-menus.ts@@ -39,7 +39,7 @@ export default function buildDesktopMenu(props: any, i18n) {{label: i18n.t('newFileNote'),accelerator: 'CommandOrControl+Shift+n',- click: props.toggleCreateFileDialog+ click: props.toggleNewEntryDialog},{label: i18n.t('createDirectory'),