TagSpaces is an offline, open source, document manager with tagging support
chore: improvement in the file creation process, adding app name and creation date in the file content
Ilian Sapundshiev9cbd4e62688c
diff --git a/app/components/dialogs/CreateDialog.tsx b/app/components/dialogs/CreateDialog.tsxindex a319c8f43..34eae831c 100644--- a/app/components/dialogs/CreateDialog.tsx+++ b/app/components/dialogs/CreateDialog.tsx@@ -50,17 +50,6 @@ import { FormControl } from '@mui/material';import { fileNameValidation } from '-/services/utils-io';const styles: any = () => ({- root: {- dispatch: 'flex',- minWidth: 200,- minHeight: 300,- overflow: 'overlay',- alignSelf: 'center'- },- grid: {- flexGrow: 1,- width: '100%'- },createButton: {minHeight: 100,width: '100%',@@ -96,30 +85,32 @@ interface Props {function CreateDialog(props: Props) {const { classes, selectedDirectoryPath, open, onClose } = props;- const fileName = useRef<string>('note' +- AppConfig.beginTagContainer +- formatDateTime4Tag(new Date(), true) +- AppConfig.endTagContainer);+ 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);let fileInput: HTMLInputElement;const fileContent = '';- 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 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 && !fileNameValidation(fileName.current)) {@@ -187,11 +178,13 @@ function CreateDialog(props: Props) {event.preventDefault();const { target } = event;target.focus();- const indexOfBracket = fileName.current.indexOf(AppConfig.beginTagContainer);+ const indexOfBracket = fileName.current.indexOf(+ AppConfig.beginTagContainer+ );let endRange = fileName.current.length;- if (indexOfBracket > 0) {- endRange = indexOfBracket;- }+ // if (indexOfBracket > 0) {+ // endRange = indexOfBracket;+ // }target.setSelectionRange(0, endRange);}};@@ -225,15 +218,16 @@ function CreateDialog(props: Props) {keepMountedscroll="paper"onKeyDown={event => {- if (event.key === 'N' || event.key === 'n') {- createRichTextFile();- } else if (event.key === 'T' || event.key === 't') {- createTextFile();- } else if (event.key === 'M' || event.key === 'm') {- createMarkdownFile();- } else if (event.key === 'A' || event.key === 'a') {- addFile();- } else if (event.key === 'Escape') {+ // if (event.key === 'N' || event.key === 'n') {+ // createRichTextFile();+ // } else if (event.key === 'T' || event.key === 't') {+ // createTextFile();+ // } else if (event.key === 'M' || event.key === 'm') {+ // createMarkdownFile();+ // } else if (event.key === 'A' || event.key === 'a') {+ // addFile();+ // } else+ if (event.key === 'Escape') {onClose();}}}@@ -243,11 +237,17 @@ function CreateDialog(props: Props) {<DialogCloseButton onClose={onClose} /></DialogTitle><DialogContent- onKeyPress={handleKeyPress}- className={classes.root}+ // onKeyPress={handleKeyPress}+ style={{+ display: 'flex',+ minWidth: 200,+ minHeight: 300,+ overflow: 'overlay',+ alignSelf: 'center'+ }}data-tid="keyboardShortCutsDialog">- <Grid className={classes.grid} container spacing={1}>+ <Grid style={{ flexGrow: 1, width: '100%' }} container spacing={1}><Grid item xs={12}><FormControl fullWidth={true} error={inputError}><TextField@@ -262,7 +262,9 @@ function CreateDialog(props: Props) {fullWidth={true}data-tid="newEntryDialogInputTID"/>- <FormHelperText>{i18n.t('core:fileNameHelp')}</FormHelperText>+ {inputError && (+ <FormHelperText>{i18n.t('core:fileNameHelp')}</FormHelperText>+ )}</FormControl></Grid><Grid item xs={12}>@@ -331,7 +333,7 @@ function CreateDialog(props: Props) {</Container></Button></Grid>- <Grid item xs={12}>+ <Grid style={{ marginTop: 40 }} item xs={12}><Buttonvariant="outlined"onClick={addFile}diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 60714aee2..93b7eeb93 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -246,18 +246,18 @@"searchSubFolder": "Search in subfolders","file": "File","newFileNote": "New File / Note",- "createNewContent": "Create...",+ "createNewContent": "Create or add new files","createFileTitle": "Create File / Note","createNote": "Create Note",- "createNoteTitle": "Use it to create documents with rich text formatting. Press 'N' to proceed",+ "createNoteTitle": "Use to create a document with rich text formatting.","createTextFile": "Create Text File",- "createTextFileTitle": "Use it to create plain text files with no formatting. Press 'T' to proceed.",+ "createTextFileTitle": "Use to create a plain text file with no formatting.","createMarkdown": "Create Markdown File",- "createMarkdownTitle": "Use it to create notes or other documents with simple formatting. Press 'M' to proceed.",+ "createMarkdownTitle": "Use to create a digital note or just a text file with simple formatting.","createRichTextFile": "Create HTML File","createDirectory": "New Directory","addFiles": "Add Files",- "addFilesTitle": "Add or upload files from your computer. Press 'A' to proceed.",+ "addFilesTitle": "Add or upload files from your computer.","exitApp": "Exit","closeWin": "Close Window","openNewInstance": "New Application Window",diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex aa4fbaa70..540911517 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -65,6 +65,7 @@ import {} from '-/reducers/settings';import { TS } from '-/tagspaces.namespace';import { PerspectiveIDs } from '-/perspectives';+import versionMeta from '-/version.json';export const types = {DEVICE_ONLINE: 'APP/DEVICE_ONLINE',@@ -1578,7 +1579,14 @@ export const actions = {content: string,fileType: 'md' | 'txt' | 'html') => (dispatch: (action) => void, getState: () => any) => {+ const creationDate = new Date().toISOString();const fileNameAndExt = fileName + '.' + fileType;+ const creationMeta =+ 'Created by ' ++ versionMeta.name ++ ' on ' ++ creationDate.substring(0, 10) ++ '.';const filePath =normalizePath(targetPath) + PlatformIO.getDirSeparator() + fileNameAndExt;let fileContent = content;@@ -1586,12 +1594,20 @@ export const actions = {const { newHTMLFileContent } = getState().settings;fileContent =newHTMLFileContent.split('<body></body>')[0] +- '<body>' ++ '<body data-createdwith="' ++ versionMeta.name ++ '" data-createdon="' ++ creationDate ++ '" >' +content +- '</body>' +- newHTMLFileContent.split('<body></body>')[1];- }- PlatformIO.saveFilePromise(filePath, fileContent, true)+ '\n<br />\n' ++ creationMeta ++ '\n';+ '</body>' + newHTMLFileContent.split('<body></body>')[1];+ } else if (fileType === 'md') {+ fileContent = content + ' \n\n*' + creationMeta + '*\n';+ }+ PlatformIO.saveFilePromise(filePath, fileContent, false).then((fsEntry: TS.FileSystemEntry) => {dispatch(actions.reflectCreateEntry(filePath, true));dispatch(actions.openFsEntry(fsEntry)); // TODO return fsEntry from saveFilePromise and simplify