Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Extend create new file dialog to support templates (#2372)

Stanimirea43efb96fae
diff --git a/src/renderer/components/CommonIcons.tsx b/src/renderer/components/CommonIcons.tsx
index 9ab4d4ee8..9427ea6de 100644
--- a/src/renderer/components/CommonIcons.tsx
+++ b/src/renderer/components/CommonIcons.tsx
@@ -162,6 +162,8 @@ export { default as HTMLFileIcon } from '@mui/icons-material/DescriptionOutlined
export { default as LinkFileIcon } from '@mui/icons-material/FileOpenOutlined';
+export { default as TemplateFileIcon } from '@mui/icons-material/TaskOutlined'; // TaskOutlined InsertPageBreakOutlined
+
export { default as AccountIcon } from '@mui/icons-material/AccountCircle';
export { default as PreviewIcon } from '@mui/icons-material/Preview';
diff --git a/src/renderer/components/MobileNavigation.tsx b/src/renderer/components/MobileNavigation.tsx
index 399b12fa8..b935eb499 100644
--- a/src/renderer/components/MobileNavigation.tsx
+++ b/src/renderer/components/MobileNavigation.tsx
@@ -35,6 +35,7 @@ import {
RecentThingsIcon,
SettingsIcon,
TagLibraryIcon,
+ TemplateFileIcon,
ThemingIcon,
WorkspacesIcon,
} from '-/components/CommonIcons';
@@ -500,6 +501,24 @@ function MobileNavigation(props: Props) {
}
/>
</MenuItem>
+ <MenuItem
+ key="navCreateFileFromTemplate"
+ data-tid="navCreateFileFromTemplateTID"
+ disabled={!Pro}
+ onClick={() => {
+ openNewFileDialog();
+ setOpenCreateMenu(false);
+ if (hideDrawer) {
+ hideDrawer();
+ }
+ }}
+ >
+ <ListItemIcon>
+ <TemplateFileIcon />
+ </ListItemIcon>
+ <ListItemText primary={t('core:createNewFromTemplate')} />
+ {/* <InfoIcon tooltip={t('core:createNoteTitle')} /> */}
+ </MenuItem>
<Divider />
<MenuItem
key="addUploadFiles"
diff --git a/src/renderer/components/dialogs/NewFileDialog.tsx b/src/renderer/components/dialogs/NewFileDialog.tsx
index 5e6431121..70af8e0ee 100644
--- a/src/renderer/components/dialogs/NewFileDialog.tsx
+++ b/src/renderer/components/dialogs/NewFileDialog.tsx
@@ -22,7 +22,6 @@ import TsButton from '-/components/TsButton';
import CreateFile from '-/components/dialogs/components/CreateFile';
import CreateLink from '-/components/dialogs/components/CreateLink';
import TargetPath from '-/components/dialogs/components/TargetPath';
-import TemplatesDropDown from '-/components/dialogs/components/TemplatesDropDown';
import TsDialogActions from '-/components/dialogs/components/TsDialogActions';
import TsDialogTitle from '-/components/dialogs/components/TsDialogTitle';
import { useTargetPathContext } from '-/components/dialogs/hooks/useTargetPathContext';
@@ -106,9 +105,7 @@ function NewFileDialog(props: Props) {
}
const template = fileTemplate ?? window.ExtDefaultFileTemplate;
if (template && template.fileNameTmpl !== undefined) {
- return template.fileNameTmpl
- .replace('{timestamp}', formatDateTime4Tag(new Date(), true))
- .replace('{uuid}', getUuid());
+ return getFileNameFromTemplate(template);
}
return (
(fileType === 'url' ? 'link' : 'note') +
@@ -118,23 +115,17 @@ function NewFileDialog(props: Props) {
);
}
+ function getFileNameFromTemplate(template: TS.FileTemplate) {
+ return template.fileNameTmpl
+ .replace('{timestamp}', formatDateTime4Tag(new Date(), true))
+ .replace('{uuid}', getUuid());
+ }
+
function getFileContent() {
if (fileType === 'url') return '';
const template = fileTemplate ?? window.ExtDefaultFileTemplate;
if (template && template.content) {
- const creationDate = new Date().toISOString();
- const dateTimeArray = creationDate.split('T');
- return (
- (fileType === 'html' ? '\n<br />\n' : ' \n\n') +
- template.content
- .replace(
- '{createdInApp}',
- `${t('core:createdIn')} ${versionMeta.name}`,
- )
- .replace('{date}', dateTimeArray[0])
- .replace('{author}', author)
- .replace('{time}', dateTimeArray[1].split('.')[0])
- );
+ return getFileContentFromTemplate(template);
}
return (
`${t('core:createdIn')} ${versionMeta.name}` +
@@ -144,6 +135,17 @@ function NewFileDialog(props: Props) {
);
}
+ function getFileContentFromTemplate(template: TS.FileTemplate) {
+ const creationDate = new Date().toISOString();
+ const dateTimeArray = creationDate.split('T');
+ const fileContent = template.content
+ .replace('{createdInApp}', `${t('core:createdIn')} ${versionMeta.name}`)
+ .replace('{date}', dateTimeArray[0])
+ .replace('{author}', author)
+ .replace('{time}', dateTimeArray[1].split('.')[0]);
+ return fileType === 'html' ? `\n<p>${fileContent}</p>` : `${fileContent}`;
+ }
+
function getFileType() {
if (fileType === 'txt') {
return t('createTXTFile');
@@ -170,7 +172,7 @@ function NewFileDialog(props: Props) {
}
}
- function createFile(fileType, targetPath) {
+ function createFile(fileType, targetPath, template?: TS.FileTemplate) {
if (targetPath) {
if (fileType === 'url' && !fileContentRef.current) {
haveError.current = true;
@@ -180,8 +182,10 @@ function NewFileDialog(props: Props) {
loadLocation();
createFileAdvanced(
targetPath,
- fileNameRef.current,
- fileContentRef.current,
+ template ? getFileNameFromTemplate(template) : fileNameRef.current,
+ template
+ ? getFileContentFromTemplate(template)
+ : fileContentRef.current,
fileType,
);
onClose();
@@ -250,7 +254,9 @@ function NewFileDialog(props: Props) {
) : (
<CreateFile
fileType={fileType}
- createFile={(type) => createFile(type, targetDirectoryPath)}
+ createFile={(type, template) =>
+ createFile(type, targetDirectoryPath, template)
+ }
handleFileNameChange={(name) => (fileNameRef.current = name)}
handleFileContentChange={(content) =>
(fileContentRef.current = content)
@@ -263,7 +269,6 @@ function NewFileDialog(props: Props) {
fileContent={fileContentRef.current}
/>
)}
- <TemplatesDropDown fileType={fileType} label={t('templatesTab')} />
<TargetPath />
</DialogContent>
{!smallScreen && fileType && (
diff --git a/src/renderer/components/dialogs/SettingsDialog.tsx b/src/renderer/components/dialogs/SettingsDialog.tsx
index 78a46f5ff..e875b4ba1 100644
--- a/src/renderer/components/dialogs/SettingsDialog.tsx
+++ b/src/renderer/components/dialogs/SettingsDialog.tsx
@@ -120,6 +120,20 @@ function SettingsDialog(props: Props) {
data-tid="fileTypeSettingsDialog"
label={t('core:fileTypeTab')}
/>
+ <Tab
+ style={{
+ textTransform: 'unset',
+ justifyContent: 'flex-start',
+ }}
+ data-tid="templatesDialogTID"
+ iconPosition="start"
+ icon={smallScreen ? '' : <ArticleIcon />}
+ label={
+ <span style={{ whiteSpace: 'nowrap' }}>
+ {t('core:templatesTab')}
+ </span>
+ }
+ />
<Tab
style={{
textTransform: 'unset',
@@ -165,20 +179,6 @@ function SettingsDialog(props: Props) {
</span>
}
/>
- <Tab
- style={{
- textTransform: 'unset',
- justifyContent: 'flex-start',
- }}
- data-tid="templatesDialogTID"
- iconPosition="start"
- icon={smallScreen ? '' : <ArticleIcon />}
- label={
- <span style={{ whiteSpace: 'nowrap' }}>
- {t('core:templatesTab')}
- </span>
- }
- />
</Tabs>
<div
data-tid="settingsDialog"
@@ -190,11 +190,11 @@ function SettingsDialog(props: Props) {
>
{currentTab === 0 && <SettingsGeneral />}
{currentTab === 1 && <SettingsFileTypes />}
- {currentTab === 2 && <SettingsKeyBindings />}
- {currentTab === 3 && <SettingsExtensions />}
- {currentTab === 4 && <SettingsAdvanced />}
- {currentTab === 5 && <SettingsAI closeSettings={onClose} />}
- {currentTab === 6 && <SettingsTemplates />}
+ {currentTab === 2 && <SettingsTemplates />}
+ {currentTab === 3 && <SettingsKeyBindings />}
+ {currentTab === 4 && <SettingsExtensions />}
+ {currentTab === 5 && <SettingsAdvanced />}
+ {currentTab === 6 && <SettingsAI closeSettings={onClose} />}
</div>
</DialogContent>
);
diff --git a/src/renderer/components/dialogs/components/CreateFile.tsx b/src/renderer/components/dialogs/components/CreateFile.tsx
index 2f6cf525e..efd00b505 100644
--- a/src/renderer/components/dialogs/components/CreateFile.tsx
+++ b/src/renderer/components/dialogs/components/CreateFile.tsx
@@ -15,17 +15,31 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
-
import TsButton from '-/components/TsButton';
import TsTextField from '-/components/TsTextField';
+import TemplatesDropDown from '-/components/dialogs/components/TemplatesDropDown';
import { useTargetPathContext } from '-/components/dialogs/hooks/useTargetPathContext';
+import { Pro } from '-/pro';
import { fileNameValidation } from '-/services/utils-io';
import { TS } from '-/tagspaces.namespace';
import useFirstRender from '-/utils/useFirstRender';
-import { ButtonGroup, FormControl } from '@mui/material';
+import {
+ Box,
+ Card,
+ CardActions,
+ CardContent,
+ FormControl,
+ Typography,
+} from '@mui/material';
import FormHelperText from '@mui/material/FormHelperText';
import Grid from '@mui/material/Grid';
-import React, { useEffect, useReducer, useRef, useState } from 'react';
+import React, {
+ useContext,
+ useEffect,
+ useReducer,
+ useRef,
+ useState,
+} from 'react';
import { useTranslation } from 'react-i18next';
interface Props {
@@ -33,7 +47,7 @@ interface Props {
fileContent: string;
handleFileNameChange: (fileName: string) => void;
handleFileContentChange: (fileContent: string) => void;
- createFile: (fileType: TS.FileType) => void;
+ createFile: (fileType: TS.FileType, template?: TS.FileTemplate) => void;
haveError: (error: boolean) => void;
tidPrefix?: string;
fileType?: TS.FileType;
@@ -60,6 +74,13 @@ function CreateFile(props: Props) {
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
const noSuitableLocation = !targetDirectoryPath;
+ const fileTemplatesContext = Pro?.contextProviders?.FileTemplatesContext
+ ? useContext<TS.FileTemplatesContextData>(
+ Pro.contextProviders.FileTemplatesContext,
+ )
+ : undefined;
+ const templatesArray = fileTemplatesContext?.getTemplates();
+
useEffect(() => {
if (!firstRender && fileNameRef.current && fileContentRef.current) {
fileNameRef.current.value = fileName;
@@ -118,82 +139,95 @@ function CreateFile(props: Props) {
return (
<Grid container spacing={1}>
- <FormControl fullWidth={true} error={inputError}>
- <TsTextField
- inputRef={fileNameRef}
- error={inputError}
- name="entryName"
- label={t('core:fileName')}
- onChange={handleInputChange}
- onFocus={onInputFocus}
- onKeyDown={(event) => {
- if (event.key === 'Enter' || event.code === 'Enter') {
- event.preventDefault();
- event.stopPropagation();
- createFile(fileType);
- }
- }}
- defaultValue={fileName}
- disabled={noSuitableLocation}
- autoFocus
- data-tid={tid('newEntryDialogInputTID')}
- />
- {inputError && (
- <FormHelperText>{t('core:fileNameHelp')}</FormHelperText>
- )}
- </FormControl>
{fileType ? (
- <FormControl fullWidth={true}>
- <TsTextField
- autoFocus
- id="fileContentID"
- label={t('core:fileContent')}
- multiline
- rows={5}
- inputRef={fileContentRef}
- defaultValue={fileContent}
- onChange={handleContentChange}
- />
- </FormControl>
+ <>
+ <FormControl fullWidth={true} error={inputError}>
+ <TsTextField
+ inputRef={fileNameRef}
+ error={inputError}
+ name="entryName"
+ label={t('core:fileName')}
+ onChange={handleInputChange}
+ onFocus={onInputFocus}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter' || event.code === 'Enter') {
+ event.preventDefault();
+ event.stopPropagation();
+ createFile(fileType);
+ }
+ }}
+ defaultValue={fileName}
+ disabled={noSuitableLocation}
+ autoFocus
+ data-tid={tid('newEntryDialogInputTID')}
+ />
+ {inputError && (
+ <FormHelperText>{t('core:fileNameHelp')}</FormHelperText>
+ )}
+ </FormControl>
+ <FormControl fullWidth={true}>
+ <TsTextField
+ autoFocus
+ id="fileContentID"
+ label={t('core:fileContent')}
+ multiline
+ rows={5}
+ inputRef={fileContentRef}
+ defaultValue={fileContent}
+ onChange={handleContentChange}
+ />
+ </FormControl>
+ <TemplatesDropDown fileType={fileType} label={t('templatesTab')} />
+ </>
) : (
- <ButtonGroup style={{ margin: '0 auto' }}>
- <TsButton
- tooltip={t('createMarkdownTitle')}
- onClick={() => createFile('md')}
- data-tid={tid('createMarkdownButton')}
- disabled={noSuitableLocation}
- style={{
- borderTopRightRadius: 0,
- borderBottomRightRadius: 0,
- fontWeight: 'bold',
- }}
- >
- {t('createMarkdown')}
- </TsButton>
- <TsButton
- tooltip={t('createNoteTitle')}
- onClick={() => createFile('html')}
- data-tid={tid('createRichTextFileButton')}
- disabled={noSuitableLocation}
- style={{
- borderRadius: 0,
- }}
- >
- {t('createRichTextFile')}
- </TsButton>
- <TsButton
- tooltip={t('createTextFileTitle')}
- onClick={() => createFile('txt')}
- data-tid={tid('createTextFileButton')}
- disabled={noSuitableLocation}
- style={{
- borderTopLeftRadius: 0,
- borderBottomLeftRadius: 0,
- }}
- >
- {t('createTextFile')}
- </TsButton>
- </ButtonGroup>
+ <Box sx={{ flexGrow: 1 }}>
+ <Grid container spacing={2}>
+ {templatesArray?.map((template: TS.FileTemplate, index) => (
+ <Grid key={index} size={6}>
+ <Card variant="outlined">
+ <CardContent>
+ <Typography variant="h6" component="div">
+ {template.name}
+ <span
+ style={{
+ marginLeft: 5,
+ padding: 2,
+ fontSize: 12,
+ textTransform: 'uppercase',
+ border: '1px solid gray',
+ borderRadius: '3px',
+ }}
+ >
+ {template.type}
+ </span>
+ </Typography>
+ <Typography
+ variant="body2"
+ title={template.content}
+ style={{ maxHeight: 75, height: 75, overflowY: 'auto' }}
+ >
+ {template.description || template.content}
+ </Typography>
+ </CardContent>
+ <CardActions>
+ <TsButton
+ size="small"
+ onClick={() => createFile(template.type, template)}
+ data-tid={
+ 'create' +
+ (template.type === 'md' ? 'Markdown' : template.type) +
+ 'Button'
+ }
+ disabled={noSuitableLocation}
+ >
+ {t('useTemplate')}
+ </TsButton>
+ </CardActions>
+ </Card>
+ </Grid>
+ ))}
+ </Grid>
+ </Box>
)}
</Grid>
);
diff --git a/src/renderer/components/dialogs/components/SettingsTemplates.tsx b/src/renderer/components/dialogs/components/SettingsTemplates.tsx
index 269613135..820ab6203 100644
--- a/src/renderer/components/dialogs/components/SettingsTemplates.tsx
+++ b/src/renderer/components/dialogs/components/SettingsTemplates.tsx
@@ -20,6 +20,7 @@ import AppConfig from '-/AppConfig';
import {
CreateFileIcon,
ExpandIcon,
+ ReloadIcon,
RemoveIcon,
} from '-/components/CommonIcons';
import { ProLabel } from '-/components/HelperComponents';
@@ -194,6 +195,21 @@ function SettingsTemplates(props: Props) {
>
{t('addTemplate')}
</TsButton>
+ <TsButton
+ disabled={!!window.ExtFileTemplates}
+ variant="text"
+ onClick={() => {
+ fileTemplatesContext.resetTemplates();
+ forceUpdate();
+ }}
+ style={{
+ marginBottom: 10,
+ marginLeft: AppConfig.defaultSpaceBetweenButtons,
+ }}
+ startIcon={<ReloadIcon />}
+ >
+ {t('resetTemplates')}
+ </TsButton>
<TemplatesDropDown disabled={!!window.ExtFileTemplates} />
<TemplatesDropDown
disabled={!!window.ExtFileTemplates}
@@ -243,10 +259,12 @@ function SettingsTemplates(props: Props) {
) : (
''
)}
- {fileTemplatesContext?.getTemplate(template.type)?.id ===
- template.id
- ? ' - ' + t('defaultTemplate')
- : ''}
+ <small>
+ {fileTemplatesContext?.getTemplate(template.type)?.id ===
+ template.id
+ ? ' - ' + t('defaultTemplate')
+ : ''}
+ </small>
</Typography>
<TsIconButton
disabled={!Pro || !!window.ExtFileTemplates}
@@ -271,7 +289,7 @@ function SettingsTemplates(props: Props) {
{editedTemplate.current.name &&
editedTemplate.current.fileNameTmpl && (
<TsButton
- variant="text"
+ size="small"
data-tid={'save' + template.id + 'TID'}
onClick={() => saveTemplate(template.id)}
>
@@ -280,6 +298,7 @@ function SettingsTemplates(props: Props) {
)}
<TsButton
variant="text"
+ size="small"
data-tid={'cancel' + template.id + 'TID'}
onClick={() => cancelSavingTemplate()}
>
diff --git a/src/renderer/components/dialogs/hooks/NewFileDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/NewFileDialogContextProvider.tsx
index bbad73524..aa8b422fe 100644
--- a/src/renderer/components/dialogs/hooks/NewFileDialogContextProvider.tsx
+++ b/src/renderer/components/dialogs/hooks/NewFileDialogContextProvider.tsx
@@ -16,6 +16,10 @@
*
*/
+import AppConfig from '-/AppConfig';
+import LoadingLazy from '-/components/LoadingLazy';
+import { TargetPathContextProvider } from '-/components/dialogs/hooks/TargetPathContextProvider';
+import { TS } from '-/tagspaces.namespace';
import React, {
createContext,
useEffect,
@@ -23,10 +27,6 @@ import React, {
useReducer,
useRef,
} from 'react';
-import LoadingLazy from '-/components/LoadingLazy';
-import AppConfig from '-/AppConfig';
-import { TargetPathContextProvider } from '-/components/dialogs/hooks/TargetPathContextProvider';
-import { TS } from '-/tagspaces.namespace';
type NewFileDialogContextData = {
openNewFileDialog: (entryType?: TS.FileType, fName?: string) => void;
@@ -104,9 +104,9 @@ export const NewFileDialogContextProvider = ({
<NewFileDialogAsync
open={open.current}
onClose={(event, reason) => {
- if (reason !== 'backdropClick') {
- closeDialog();
- }
+ //if (reason !== 'backdropClick') {
+ closeDialog();
+ //}
}}
fileType={fileType.current}
fileName={fileName.current}
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index 4541da5d0..41ef769ea 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -71,7 +71,6 @@ import React, {
} from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
-import { Pro } from '-/pro';
type OpenedEntryContextData = {
haveOpenedEntry: boolean;
@@ -428,69 +427,6 @@ export const OpenedEntryContextProvider = ({
}
}
- /*function setSharedLinks(openedFile?) {
- if (openedFile) {
- if (window.location.href.indexOf('?') > 0) {
- const sharingURL = new URL(window.location.href);
- const params = new URLSearchParams(sharingURL.search);
- if (params.has('tslid')) {
- const locationId = params.get('tslid');
- //if (params.has('tsdpath')) {
- // const folderPath2 = params.get('tsdpath');
- const folderLocation = findLocation(locationId);
- const folderPath = extractContainingDirectoryPath(openedFile.path);
- if (
- folderPath.indexOf(
- cleanTrailingDirSeparator(folderLocation.path),
- ) === 0
- ) {
- sharingParentFolderLink.current = generateSharingLink(
- locationId,
- undefined,
- cleanRootPath(
- folderPath,
- folderLocation.path,
- folderLocation?.getDirSeparator(),
- ),
- );
- }
-
- //}
- if (params.has('tsepath')) {
- const entryPath = params.get('tsepath');
- if (openedFile.isFile) {
- const dirPath = params.has('tsdpath')
- ? params.get('tsdpath')
- : undefined;
- sharingLink.current = generateSharingLink(
- locationId,
- entryPath,
- dirPath,
- );
- } else {
- sharingLink.current = generateSharingLink(
- locationId,
- undefined,
- entryPath,
- );
- }
- } else if (params.has('tsdpath')) {
- sharingLink.current = generateSharingLink(
- locationId,
- undefined,
- params.get('tsdpath'),
- );
- } else {
- sharingLink.current = generateSharingLink(locationId);
- }
- }
- }
- } else {
- sharingLink.current = undefined;
- sharingParentFolderLink.current = undefined;
- }
- }*/
-
function addToEntryContainer(fsEntry: TS.OpenedEntry) {
setSharedLinks(fsEntry).then(() => {
currentEntry.current = { ...fsEntry };
@@ -749,34 +685,6 @@ export const OpenedEntryContextProvider = ({
}
}
- /*function goForward() {
- window.history.forward();
- window.addEventListener(
- 'popstate',
- () => {
- openLink(window.location.href, { fullWidth: false });
- },
- { once: true },
- );
- }*/
-
- /*function goBack() {
- // console.log(
- // '>>> current href: ' + decodeURIComponent(window.location.href)
- // );
- window.history.back(); // window.history.go(-1);
- window.addEventListener(
- 'popstate',
- () => {
- openLink(window.location.href, { fullWidth: false });
- // console.log(
- // '>>> last href: ' + decodeURIComponent(window.location.href)
- // );
- },
- { once: true },
- );
- }*/
-
function openLink(url: string, options = { fullWidth: true }) {
try {
const decodedURI = decodeURI(url);
@@ -998,16 +906,11 @@ export const OpenedEntryContextProvider = ({
fileNameAndExt;
let fileContent = content;
if (fileType === 'html') {
- fileContent =
- newHTMLFileContent.split('<body></body>')[0] +
- '<body data-createdwith="' +
- versionMeta.name +
- '" data-createdon="' +
- creationDate +
- '" >' +
- content +
- '\n';
- '</body>' + newHTMLFileContent.split('<body></body>')[1];
+ fileContent = `${newHTMLFileContent.split('<body></body>')[0]}
+<body data-createdwith="${versionMeta.name}" data-createdon="${creationDate}">
+${content}
+</body>
+${newHTMLFileContent.split('<body></body>')[1]}`;
} else if (fileType === 'md') {
fileContent = content;
} else if (fileType === 'url') {
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index cb23351f7..3c1d919ce 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -272,6 +272,7 @@
"createMarkdownTitle": "Creates a text file with simple (markdown based) formatting, recommended for digital notes",
"createRichTextFile": "New HTML File",
"createLinkFile": "New Link File",
+ "createNewFromTemplate": "New From Template",
"createDirectory": "New Folder",
"addFiles": "New From Device",
"addFilesTitle": "Add or upload files from your computer.",
@@ -990,8 +991,10 @@
"defaultTemplatetxt": "Default template for text files (.txt)",
"defaultTemplatehtml": "Default template for HTML files (.html)",
"addTemplate": "Create New Template",
+ "resetTemplates": "Reset Templates",
"templateContent": "Template Content",
"fileNameTmpl": "File Name Template",
+ "useTemplate": "Use this template",
"templateNameEmptyError": "Template name can't be empty",
"fileNameEmptyError": "Filename template can't be empty",
"loadDefaultAuthor": "Load username from operating system",
diff --git a/src/renderer/perspectives/common/DirectoryMenuItems.tsx b/src/renderer/perspectives/common/DirectoryMenuItems.tsx
index 0532c0123..194ef7ef9 100644
--- a/src/renderer/perspectives/common/DirectoryMenuItems.tsx
+++ b/src/renderer/perspectives/common/DirectoryMenuItems.tsx
@@ -21,6 +21,7 @@ import {
ReloadIcon,
RenameIcon,
TagIcon,
+ TemplateFileIcon,
} from '-/components/CommonIcons';
import { ProLabel } from '-/components/HelperComponents';
import InfoIcon from '-/components/InfoIcon';
@@ -282,6 +283,21 @@ export function getDirectoryMenuItems(
<ListItemText primary={t('core:createLinkFile')} />
</MenuItem>,
);
+ menuItems.push(
+ <MenuItem
+ key="createNewFromTemplate"
+ data-tid="createNewFromTempateTID"
+ onClick={() => {
+ onClose();
+ createNewFile();
+ }}
+ >
+ <ListItemIcon>
+ <TemplateFileIcon />
+ </ListItemIcon>
+ <ListItemText primary={t('core:createNewFromTemplate')} />
+ </MenuItem>,
+ );
}
if (createNewAudio) {
menuItems.push(
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index 1e879b3bc..bcce8e8f4 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -336,7 +336,8 @@ export namespace TS {
interface FileTemplate {
id: string;
content: string; // e.g: Created with TagSpaces on 20250605'
- name?: string; // 'Template Name'
+ name?: string;
+ description?: string;
type?: 'md' | 'txt' | 'html';
fileNameTmpl?: string; // e.g. note, issue, task
screenshotUrl?: string; //'dataURL'
@@ -347,6 +348,7 @@ export namespace TS {
setTemplate: (id: string, value: FileTemplate) => void;
setTemplateActive: (id: string) => void;
getTemplates: () => TS.FileTemplate[];
+ resetTemplates: () => void;
delTemplate: (id: string) => void;
};