Skip to content

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

refactoring the editing functionaliy, enabling editing of file by double click

Ilian Sapundshieva5f3f10d42f3
diff --git a/app/components/EntryContainer.js b/app/components/EntryContainer.js
index 4b8908e2d..f3d45f8f0 100644
--- a/app/components/EntryContainer.js
+++ b/app/components/EntryContainer.js
@@ -24,10 +24,10 @@ import { HotKeys } from 'react-hotkeys';
import Button from '@material-ui/core/Button';
import IconButton from '@material-ui/core/IconButton';
import EditIcon from '@material-ui/icons/Edit';
-import moment from 'moment';
import uuidv1 from 'uuid';
import SaveIcon from '@material-ui/icons/Save';
import CloseIcon from '@material-ui/icons/Close';
+import BackIcon from '@material-ui/icons/RemoveRedEye';
import FullScreenIcon from '@material-ui/icons/ZoomOutMap';
import OpenNativelyIcon from '@material-ui/icons/Launch';
import ArrowLeftIcon from '@material-ui/icons/KeyboardArrowLeft';
@@ -176,6 +176,7 @@ type State = {
entryProps?: Object | null,
editingSupported?: boolean,
isSaveBeforeCloseConfirmDialogOpened?: boolean,
+ isSaveBeforeReloadConfirmDialogOpened?: boolean,
openedSplitSize?: number,
isEditTagsModalOpened?: boolean,
selectedItem?: Object,
@@ -191,6 +192,7 @@ class EntryContainer extends React.Component<Props, State> {
isFullscreen: false,
editingSupported: false,
isSaveBeforeCloseConfirmDialogOpened: false,
+ isSaveBeforeReloadConfirmDialogOpened: false,
openedSplitSize,
isEditTagsModalOpened: false,
isDeleteEntryModalOpened: false,
@@ -337,6 +339,9 @@ class EntryContainer extends React.Component<Props, State> {
case 'saveDocument':
this.startSavingFile();
break;
+ case 'editDocument':
+ this.editFile();
+ break;
case 'playbackEnded':
this.props.openFile(this.props.getNextFile(this.state.currentEntry.path));
break;
@@ -412,11 +417,35 @@ class EntryContainer extends React.Component<Props, State> {
};
reloadDocument = () => {
- const { currentEntry } = this.state;
+ if (
+ this.state.currentEntry &&
+ this.state.currentEntry.changed
+ ) {
+ this.setState({ isSaveBeforeReloadConfirmDialogOpened: true });
+ return true;
+ }
+ this.setState({
+ currentEntry: {
+ ...this.state.currentEntry,
+ shouldReload: true,
+ editMode: false
+ }
+ });
+ }
+
+ cancelEditing = () => {
+ if (
+ this.state.currentEntry &&
+ this.state.currentEntry.changed
+ ) {
+ this.props.showNotification(i18n.t('core:currentlyFileChangedSaveOrClose'));
+ return true;
+ }
this.setState({
currentEntry: {
- ...currentEntry,
- shouldReload: true
+ ...this.state.currentEntry,
+ shouldReload: true,
+ editMode: false
}
});
}
@@ -851,6 +880,31 @@ class EntryContainer extends React.Component<Props, State> {
confirmDialogTID={'confirmSaveBeforeCloseDialog'}
confirmDialogContent={'confirmDialogContent'}
/>
+ <ConfirmDialog
+ open={this.state.isSaveBeforeReloadConfirmDialogOpened}
+ onClose={() => {
+ this.setState({ isSaveBeforeReloadConfirmDialogOpened: false });
+ }}
+ title={i18n.t('core:confirm')}
+ content={'File was modified, do you want to save the changes?'}
+ confirmCallback={result => {
+ if (result) {
+ this.startSavingFile();
+ }
+ this.setState({
+ isSaveBeforeReloadConfirmDialogOpened: false,
+ currentEntry: {
+ ...this.state.currentEntry,
+ shouldReload: true,
+ editMode: false,
+ changed: false
+ }
+ });
+ }}
+ cancelDialogTID={'cancelSaveBeforeCloseDialog'}
+ confirmDialogTID={'confirmSaveBeforeCloseDialog'}
+ confirmDialogContent={'confirmDialogContent'}
+ />
<ConfirmDialog
open={this.state.isDeleteEntryModalOpened}
onClose={() => {
@@ -936,35 +990,64 @@ class EntryContainer extends React.Component<Props, State> {
)}
</div>
{(this.state.editingSupported && currentEntry.editMode) && (
- <IconButton
- disabled={false}
- onClick={this.startSavingFile}
- title={i18n.t('core:saveFile')}
- aria-label={i18n.t('core:saveFile')}
- data-tid="fileContainerSaveFile"
- >
- <SaveIcon />
- </IconButton>
+ <div>
+ <IconButton
+ disabled={false}
+ onClick={this.startSavingFile}
+ title={i18n.t('core:saveFile')}
+ aria-label={i18n.t('core:saveFile')}
+ data-tid="fileContainerSaveFile"
+ >
+ <SaveIcon />
+ </IconButton>
+ <IconButton
+ onClick={this.reloadDocument}
+ title="Preview"
+ aria-label={i18n.t('core:cancelEditing')}
+ >
+ <BackIcon />
+ </IconButton>
+ <IconButton
+ onClick={this.startClosingFile}
+ title={i18n.t('core:closeEntry')}
+ aria-label={i18n.t('core:closeEntry')}
+ data-tid="fileContainerCloseOpenedFile"
+ >
+ <CloseIcon />
+ </IconButton>
+ </div>
)}
{(this.state.editingSupported && !currentEntry.editMode) && (
+ <div>
+ <IconButton
+ disabled={false}
+ onClick={this.editFile}
+ title={i18n.t('core:editFile')}
+ aria-label={i18n.t('core:editFile')}
+ data-tid="fileContainerEditFile"
+ >
+ <EditIcon />
+ </IconButton>
+ <IconButton
+ onClick={this.startClosingFile}
+ title={i18n.t('core:closeEntry')}
+ aria-label={i18n.t('core:closeEntry')}
+ data-tid="fileContainerCloseOpenedFile"
+ >
+ <CloseIcon />
+ </IconButton>
+ </div>
+ )}
+ {(!this.state.editingSupported) && (
<IconButton
- disabled={false}
- onClick={this.editFile}
- title={i18n.t('core:editFile')}
- aria-label={i18n.t('core:editFile')}
- data-tid="fileContainerEditFile"
+ onClick={this.startClosingFile}
+ title={i18n.t('core:closeEntry')}
+ aria-label={i18n.t('core:closeEntry')}
+ data-tid="fileContainerCloseOpenedFile"
>
- <EditIcon />
+ <CloseIcon />
</IconButton>
)}
- <IconButton
- onClick={this.startClosingFile}
- title={i18n.t('core:closeEntry')}
- aria-label={i18n.t('core:closeEntry')}
- data-tid="fileContainerCloseOpenedFile"
- >
- <CloseIcon />
- </IconButton>
</div>
<div className={classes.entryProperties}>
{ currentEntry.isFile ?