TagSpaces is an offline, open source, document manager with tagging support
improving file creation process
Ilian Sapundshiev2f8917d319a3
diff --git a/app/components/MobileNavigation.js b/app/components/MobileNavigation.jsindex bc9511317..3d27b8c26 100644--- a/app/components/MobileNavigation.js+++ b/app/components/MobileNavigation.js@@ -51,6 +51,7 @@ import {isPerspectivesPanelOpened,isHelpFeedbackPanelOpened,isReadOnlyMode,+ getDirectoryPath} from '../reducers/app';import { actions as SettingsActions, isFirstRun } from '../reducers/settings';@@ -94,7 +95,9 @@ type Props = {openURLExternally: (url: string) => void,switchTheme: () => void,hideDrawer: () => void,- isReadOnlyMode: boolean+ isReadOnlyMode: boolean,+ showNotification: (message: string) => void,+ directoryPath: string};type State = {@@ -133,9 +136,11 @@ class MobileNavigation extends React.Component<Props, State> {openHelpFeedbackPanel,closeAllVerticalPanels,switchTheme,+ showNotification,hideDrawer,openFileNatively,openURLExternally,+ directoryPath} = this.props;return (<div style={{ height: '100%' }}>@@ -213,20 +218,22 @@ class MobileNavigation extends React.Component<Props, State> {<SearchIcon className={classes.buttonIcon} /></ToggleButton></ToggleButtonGroup>- {!isReadOnlyMode && (- <IconButton- id="verticalNavButton"- onClick={() => {+ <IconButton+ id="verticalNavButton"+ onClick={() => {+ if (isReadOnlyMode || !directoryPath) {+ showNotification('You are in read-only mode or there is no opened location');+ } else {toggleCreateFileDialog();hideDrawer();- }}- style={{ marginTop: -15, marginLeft: 10 }}- title={i18n.t('core:createFileTitle')}- data-tid="locationManager"- >- <NewFileIcon color="primary" />- </IconButton>- )}+ }+ }}+ style={{ marginTop: -15, marginLeft: 10 }}+ title={i18n.t('core:createFileTitle')}+ data-tid="locationManager"+ >+ <NewFileIcon color="primary" />+ </IconButton></div></div>);@@ -242,7 +249,8 @@ function mapStateToProps(state) {isSearchPanelOpened: isSearchPanelOpened(state),isPerspectivesPanelOpened: isPerspectivesPanelOpened(state),isHelpFeedbackPanelOpened: isHelpFeedbackPanelOpened(state),- isReadOnlyMode: isReadOnlyMode(state)+ isReadOnlyMode: isReadOnlyMode(state),+ directoryPath: getDirectoryPath(state),};}@@ -261,6 +269,7 @@ function mapActionCreatorsToProps(dispatch) {openHelpFeedbackPanel: AppActions.openHelpFeedbackPanel,openFileNatively: AppActions.openFileNatively,openURLExternally: AppActions.openURLExternally,+ showNotification: AppActions.showNotification,closeAllVerticalPanels: AppActions.closeAllVerticalPanels,switchTheme: SettingsActions.switchTheme,setFirstRun: SettingsActions.setFirstRun,diff --git a/app/components/VerticalNavigation.js b/app/components/VerticalNavigation.jsindex 883f37164..c510db54f 100644--- a/app/components/VerticalNavigation.js+++ b/app/components/VerticalNavigation.js@@ -66,6 +66,7 @@ const ProTeaserDialogAsync = props => (type Props = {theme: Object,isFirstRun: boolean,+ directoryPath: string,setFirstRun: (isFirstRun: boolean) => void,toggleOnboardingDialog: () => void,toggleCreateFileDialog: () => void,@@ -80,14 +81,14 @@ type Props = {isSearchPanelOpened: boolean,openSearchPanel: () => void,isPerspectivesPanelOpened: boolean,- openPerspectivesPanel: () => void,+ // openPerspectivesPanel: () => void,isHelpFeedbackPanelOpened: boolean,openHelpFeedbackPanel: () => void,closeAllVerticalPanels: () => void,openFileNatively: (url: string) => void,openURLExternally: (url: string) => void,switchTheme: () => void,- shouldTogglePanel: string,+ showNotification: (message: string) => void,isReadOnlyMode: boolean};@@ -163,6 +164,8 @@ class VerticalNavigation extends React.Component<Props, State> {switchTheme,openFileNatively,openURLExternally,+ showNotification,+ directoryPath,setFirstRun,theme} = this.props;@@ -207,17 +210,21 @@ class VerticalNavigation extends React.Component<Props, State> {alt="TagSpaces Logo"/></IconButton>- { !isReadOnlyMode && (- <IconButton- id="verticalNavButton"- onClick={toggleCreateFileDialog}- style={{ ...this.styles.button, marginBottom: 20 }}- title={i18n.t('core:createFileTitle')}- data-tid="locationManager"- >- <NewFileIcon style={this.styles.buttonIcon} />- </IconButton>- )}+ <IconButton+ id="verticalNavButton"+ onClick={() => {+ if (isReadOnlyMode || !directoryPath) {+ showNotification('You are in read-only mode or there is no opened location');+ } else {+ toggleCreateFileDialog();+ }+ }}+ style={{ ...this.styles.button, marginBottom: 20 }}+ title={i18n.t('core:createFileTitle')}+ data-tid="locationManager"+ >+ <NewFileIcon style={this.styles.buttonIcon} />+ </IconButton><IconButtonid="verticalNavButton"onClick={() => {@@ -386,7 +393,8 @@ function mapStateToProps(state) {isSearchPanelOpened: isSearchPanelOpened(state),isPerspectivesPanelOpened: isPerspectivesPanelOpened(state),isHelpFeedbackPanelOpened: isHelpFeedbackPanelOpened(state),- isReadOnlyMode: isReadOnlyMode(state)+ isReadOnlyMode: isReadOnlyMode(state),+ directoryPath: getDirectoryPath(state),};}@@ -406,6 +414,7 @@ function mapActionCreatorsToProps(dispatch) {openFileNatively: AppActions.openFileNatively,openURLExternally: AppActions.openURLExternally,closeAllVerticalPanels: AppActions.closeAllVerticalPanels,+ showNotification: AppActions.showNotification,switchTheme: SettingsActions.switchTheme,setFirstRun: SettingsActions.setFirstRun,},diff --git a/app/components/dialogs/CreateDialog.js b/app/components/dialogs/CreateDialog.jsindex 04a2b249f..244489d89 100644--- a/app/components/dialogs/CreateDialog.js+++ b/app/components/dialogs/CreateDialog.js@@ -21,7 +21,11 @@ import React from 'react';import { connect } from 'react-redux';import { bindActionCreators } from 'redux';import Button from '@material-ui/core/Button';-import NewFileIcon from '@material-ui/icons/AddCircle';+import Container from '@material-ui/core/Container';+import NoteFileIcon from '@material-ui/icons/DescriptionOutlined';+import TextFileIcon from '@material-ui/icons/InsertDriveFileOutlined';+import MarkdownFileIcon from '@material-ui/icons/GetAppOutlined';+import AddFileIcon from '@material-ui/icons/NoteAddOutlined';import DialogActions from '@material-ui/core/DialogActions';import DialogContent from '@material-ui/core/DialogContent';import DialogTitle from '@material-ui/core/DialogTitle';@@ -32,16 +36,16 @@ import i18n from '../../services/i18n';import { getKeyBindingObject } from '../../reducers/settings';import { actions as AppActions } from '../../reducers/app';import AppConfig from '../../config';-import { extractFileName, normalizePath } from '../../utils/paths'; // extractFileExtension+import { normalizePath } from '../../utils/paths';import PlatformIO from '../../services/platform-io';import { formatDateTime4Tag } from '../../utils/misc';const styles = theme => ({root: {dispatch: 'flex',- minWidth: 300,+ minWidth: 200,minHeight: 300,- overflow: 'hidden',+ overflow: 'overlay',alignSelf: 'center'},grid: {@@ -50,6 +54,7 @@ const styles = theme => ({height: '100%'},creatButton: {+ minHeight: 150,textAlign: 'center'}});@@ -57,7 +62,8 @@ const styles = theme => ({type Props = {open: boolean,classes: Object,- selectedDirectoryPath: string | null,+ selectedDirectoryPath: string,+ showNotification: (message: string) => void,createFileAdvanced: (targetPath: string, fileName: string, content: string, fileType: string) => void,onClose: () => void};@@ -65,8 +71,24 @@ type Props = {const CreateDialog = (props: Props) => {let fileInput; // Object | null;const fileName = 'note' + AppConfig.beginTagContainer + formatDateTime4Tag(new Date(), true) + AppConfig.endTagContainer;- const fileContent = ''- const { classes, selectedDirectoryPath } = props;+ const fileContent = '';+ const { classes, selectedDirectoryPath, showNotification } = props;++ function handleKeyPress(event: any) {+ if (event.key === 'n') {+ event.stopPropagation();+ createRichTextFile();+ } else if (event.key === 't') {+ event.stopPropagation();+ createTextFile();+ } else if (event.key === 'm') {+ event.stopPropagation();+ createMarkdownFile();+ } else if (event.key === 'a') {+ event.stopPropagation();+ addFile();+ }+ }function createRichTextFile() {if (selectedDirectoryPath) {@@ -116,7 +138,7 @@ const CreateDialog = (props: Props) => {// console.log("Selected File: "+JSON.stringify(selection.currentTarget.files[0]));const file = selection.currentTarget.files[0];const filePath =- normalizePath(props.directoryPath) ++ normalizePath(selectedDirectoryPath) +AppConfig.dirSeparator +decodeURIComponent(file.name);@@ -124,7 +146,7 @@ const CreateDialog = (props: Props) => {reader.onload = event => {PlatformIO.getPropertiesPromise(filePath).then((entryProps) => {if (entryProps) {- props.showNotification(+ showNotification('File with the same name already exist, importing skipped!','warning',true@@ -136,7 +158,7 @@ const CreateDialog = (props: Props) => {true).then(() => {- props.showNotification(+ showNotification('File ' + filePath + ' successfully imported.','default',true@@ -147,7 +169,7 @@ const CreateDialog = (props: Props) => {.catch(error => {// TODO showAlertDialog("Saving " + filePath + " failed.");console.error('Save to file ' + filePath + ' failed ' + error);- props.showNotification(+ showNotification('Importing file ' + filePath + ' failed.','error',true@@ -177,45 +199,43 @@ const CreateDialog = (props: Props) => {return (<DialogContent className={classes.root} data-tid="keyboardShortCutsDialog"><Grid className={classes.grid} container spacing={1}>- <Grid container item xs={12} spacing={3}>- <Grid item xs={4}>- <Button- onClick={createRichTextFile}- className={classes.creatButton}- >- <NewFileIcon /><br /><br /><br />- Create Note- </Button>- </Grid>- <Grid item xs={4}>- <Button- onClick={createTextFile}- className={classes.creatButton}- >- <NewFileIcon /><br />- Create Text File- </Button>- </Grid>+ <Grid item xs>+ <Button+ onClick={createRichTextFile}+ className={classes.creatButton}+ >+ <div><NoteFileIcon /></div>+ <div><Container>Create Note</Container></div>+ </Button>+ </Grid>+ <Grid item xs>+ <Button+ onClick={createTextFile}+ className={classes.creatButton}+ >+ <TextFileIcon />+ <Container>Create Text File</Container>+ </Button>+ </Grid>+ </Grid>+ <Grid className={classes.grid} container spacing={1}>+ <Grid item xs>+ <Button+ onClick={createMarkdownFile}+ className={classes.creatButton}+ >+ <MarkdownFileIcon />+ <Container>Create Markdown File</Container>+ </Button></Grid>- <Grid container item xs={12} spacing={3}>- <Grid item xs={4}>- <Button- onClick={createMarkdownFile}- className={classes.creatButton}- >- <NewFileIcon /><br />- Create Markdown File- </Button>- </Grid>- <Grid item xs={4}>- <Button- onClick={addFile}- className={classes.creatButton}- >- <NewFileIcon /><br />- Add file- </Button>- </Grid>+ <Grid item xs>+ <Button+ onClick={addFile}+ className={classes.creatButton}+ >+ <AddFileIcon />+ <Container>Add file</Container>+ </Button></Grid></Grid><input@@ -247,6 +267,7 @@ const CreateDialog = (props: Props) => {return (<GenericDialog+ onKeyDown={handleKeyPress}open={props.open}onClose={props.onClose}renderTitle={renderTitle}@@ -265,6 +286,7 @@ function mapStateToProps(state) {function mapActionCreatorsToProps(dispatch) {return bindActionCreators({createFileAdvanced: AppActions.createFileAdvanced,+ showNotification: AppActions.showNotification,}, dispatch);}