TagSpaces is an offline, open source, document manager with tagging support
implementing readonly support for file container
Ilian Sapundshievd4aa79dc4627
diff --git a/app/components/EntryContainer.js b/app/components/EntryContainer.jsindex c49527fa4..635fb021b 100644--- a/app/components/EntryContainer.js+++ b/app/components/EntryContainer.js@@ -262,10 +262,14 @@ class EntryContainer extends React.Component<Props, State> {this.setState({ currentEntry: nextEntry });- if (nextEntry.editingExtensionId && nextEntry.editingExtensionId.length > 3) {- this.setState({ editingSupported: true });- } else {+ if (nextProps.isReadOnlyMode) {this.setState({ editingSupported: false });+ } else {+ if (nextEntry.editingExtensionId && nextEntry.editingExtensionId.length > 3) {+ this.setState({ editingSupported: true });+ } else {+ this.setState({ editingSupported: false });+ }}const { settings } = nextProps;@@ -674,7 +678,7 @@ class EntryContainer extends React.Component<Props, State> {><ExpandIcon /></IconButton>- {!PlatformIO.haveObjectStoreSupport() && (+ {!(PlatformIO.haveObjectStoreSupport() || AppConfig.isWeb) && (<IconButtontitle={i18n.t('core:openFileExternally')}aria-label={i18n.t('core:openFileExternally')}@@ -718,22 +722,26 @@ class EntryContainer extends React.Component<Props, State> {><RefreshIcon /></IconButton>- <IconButton- aria-label={i18n.t('core:duplicateFile')}- title={i18n.t('core:duplicateFile')}- onClick={() => {- this.setState({ shouldCopyFile: true });- }}- >- <CopyContentIcon />- </IconButton>- <IconButton- title={i18n.t('core:deleteEntry')}- aria-label={i18n.t('core:deleteEntry')}- onClick={() => this.setState({ isDeleteEntryModalOpened: true })}- >- <DeleteIcon />- </IconButton>+ { !this.props.isReadOnlyMode && (+ <div>+ <IconButton+ aria-label={i18n.t('core:duplicateFile')}+ title={i18n.t('core:duplicateFile')}+ onClick={() => {+ this.setState({ shouldCopyFile: true });+ }}+ >+ <CopyContentIcon />+ </IconButton>+ <IconButton+ title={i18n.t('core:deleteEntry')}+ aria-label={i18n.t('core:deleteEntry')}+ onClick={() => this.setState({ isDeleteEntryModalOpened: true })}+ >+ <DeleteIcon />+ </IconButton>+ </div>+ )}</div><IconButtontitle={i18n.t('core:openPrevFileTooltip')}@@ -768,7 +776,7 @@ class EntryContainer extends React.Component<Props, State> {color={this.state.isPropertiesPanelVisible ? 'primary' : 'action'}/></IconButton>- {!PlatformIO.haveObjectStoreSupport() && (+ {!(PlatformIO.haveObjectStoreSupport() || AppConfig.isWeb) && (<IconButtontitle={i18n.t('core:openDirectoryExternally')}aria-label={i18n.t('core:openDirectoryExternally')}@@ -784,13 +792,17 @@ class EntryContainer extends React.Component<Props, State> {><RefreshIcon /></IconButton>- <IconButton- title={i18n.t('core:deleteDirectory')}- aria-label={i18n.t('core:deleteDirectory')}- onClick={() => this.setState({ isDeleteEntryModalOpened: true })}- >- <DeleteIcon />- </IconButton>+ { !this.props.isReadOnlyMode && (+ <div>+ <IconButton+ title={i18n.t('core:deleteDirectory')}+ aria-label={i18n.t('core:deleteDirectory')}+ onClick={() => this.setState({ isDeleteEntryModalOpened: true })}+ >+ <DeleteIcon />+ </IconButton>+ </div>+ )}</div></div>);@@ -1121,6 +1133,7 @@ class EntryContainer extends React.Component<Props, State> {removeAllTags={this.props.removeAllTags}reflectUpdateSidecarMeta={this.props.reflectUpdateSidecarMeta}showNotification={this.props.showNotification}+ isReadOnlyMode={this.props.isReadOnlyMode}/></div></div>diff --git a/app/components/EntryProperties.js b/app/components/EntryProperties.jsindex 58ff2be7b..c999d8a39 100644--- a/app/components/EntryProperties.js+++ b/app/components/EntryProperties.js@@ -163,6 +163,7 @@ type Props = {removeTags: () => void,removeAllTags: () => void,resetState: () => void,+ isReadOnlyMode: boolean,setPropertiesEditMode: (editMode: boolean) => void};@@ -178,6 +179,7 @@ type State = {isDeleteTagDialogOpened?: boolean | null,isEditName?: boolean | null,isEditDescription?: boolean | null,+ displayColorPicker?: boolean | null,isFile?: boolean};@@ -197,6 +199,7 @@ class EntryProperties extends Component<Props, State> {isEditName: false,isEditDescription: false,isMoveCopyFilesDialogOpened: false,+ displayColorPicker: false,isFile: false};@@ -285,6 +288,12 @@ class EntryProperties extends Component<Props, State> {};toggleEditNameField = () => {+ if (this.props.isReadOnlyMode) {+ this.setState({+ isEditName: false+ });+ return;+ }if (this.state.isEditName) {this.setState({isEditName: false,@@ -316,6 +325,12 @@ class EntryProperties extends Component<Props, State> {};toggleEditDescriptionField = () => {+ if (this.props.isReadOnlyMode) {+ this.setState({+ isEditDescription: false+ });+ return;+ }if (!Pro) {this.props.showNotification(i18n.t('core:thisFunctionalityIsAvailableInPro'));return;@@ -366,6 +381,9 @@ class EntryProperties extends Component<Props, State> {};toggleBackgroundColorPicker = () => {+ if (this.props.isReadOnlyMode) {+ return;+ }if (!Pro) {this.props.showNotification(i18n.t('core:thisFunctionalityIsAvailableInPro'));return;@@ -374,9 +392,9 @@ class EntryProperties extends Component<Props, State> {this.props.showNotification(i18n.t('Saving color not supported'));return;}- this.setState(prevState => ({- displayColorPicker: !prevState.displayColorPicker- }));+ this.setState({+ displayColorPicker: !this.state.displayColorPicker+ });};handleChangeColor = color => {@@ -436,6 +454,7 @@ class EntryProperties extends Component<Props, State> {entryPath,removeTags,editTagForEntry,+ isReadOnlyMode} = this.props;const {path,@@ -468,34 +487,38 @@ class EntryProperties extends Component<Props, State> {{i18n.t('core:editTagMasterName')}</Typography></div>- {isEditName ? (- <div className="grid-item">- <Button- color="primary"- className={classes.button}- onClick={this.toggleEditNameField}- >- {i18n.t('core:cancel')}- </Button>- <Button- color="primary"- disabled={isEditDescription}- className={classes.button}- onClick={this.renameEntry}- >- {i18n.t('core:confirmSaveButton')}- </Button>- </div>- ) : (- <div className="grid-item">- <Button- color="primary"- disabled={isEditDescription}- className={classes.button}- onClick={this.toggleEditNameField}- >- {i18n.t('core:rename')}- </Button>+ {!isReadOnlyMode && (+ <div>+ {isEditName ? (+ <div className="grid-item">+ <Button+ color="primary"+ className={classes.button}+ onClick={this.toggleEditNameField}+ >+ {i18n.t('core:cancel')}+ </Button>+ <Button+ color="primary"+ disabled={isEditDescription}+ className={classes.button}+ onClick={this.renameEntry}+ >+ {i18n.t('core:confirmSaveButton')}+ </Button>+ </div>+ ) : (+ <div className="grid-item">+ <Button+ color="primary"+ disabled={isEditDescription}+ className={classes.button}+ onClick={this.toggleEditNameField}+ >+ {i18n.t('core:rename')}+ </Button>+ </div>+ )}</div>)}</div>@@ -537,7 +560,7 @@ class EntryProperties extends Component<Props, State> {</div><Paper className={classes.tags}><TagDropContainer entryPath={path}>- <TagsSelect tags={tags} handleChange={this.handleChange} />+ <TagsSelect isReadOnlyMode={isReadOnlyMode} tags={tags} handleChange={this.handleChange} /></TagDropContainer></Paper></div>@@ -550,25 +573,29 @@ class EntryProperties extends Component<Props, State> {</Typography></div><div className="grid-item">- {isEditDescription && (- <Button- color="primary"- className={classes.button}- onClick={this.toggleEditDescriptionField}- >- {i18n.t('core:cancel')}- </Button>+ {!isReadOnlyMode && (+ <div>+ {isEditDescription && (+ <Button+ color="primary"+ className={classes.button}+ onClick={this.toggleEditDescriptionField}+ >+ {i18n.t('core:cancel')}+ </Button>+ )}+ <Button+ color="primary"+ disabled={isEditName}+ className={classes.button}+ onClick={this.toggleEditDescriptionField}+ >+ {isEditDescription+ ? i18n.t('core:confirmSaveButton')+ : i18n.t('core:edit')}+ </Button>+ </div>)}- <Button- color="primary"- disabled={isEditName}- className={classes.button}- onClick={this.toggleEditDescriptionField}- >- {isEditDescription- ? i18n.t('core:confirmSaveButton')- : i18n.t('core:edit')}- </Button></div></div><FormControl fullWidth={true} className={classes.formControl}>@@ -704,15 +731,17 @@ class EntryProperties extends Component<Props, State> {<Typography variant="caption" className={classes.entryLabel}>{i18n.t('core:filePath')}</Typography>- <Button- color="primary"- styles={{ paddingBottom: 0 }}- disabled={isEditDescription || isEditName}- className={classes.button}- onClick={this.toggleMoveCopyFilesDialog}- >- {i18n.t('core:move')}- </Button>+ {!isReadOnlyMode && (+ <Button+ color="primary"+ styles={{ paddingBottom: 0 }}+ disabled={isEditDescription || isEditName}+ className={classes.button}+ onClick={this.toggleMoveCopyFilesDialog}+ >+ {i18n.t('core:move')}+ </Button>+ )}</div><FormControl fullWidth={true} className={classes.formControl}><TextField@@ -726,8 +755,6 @@ class EntryProperties extends Component<Props, State> {/></FormControl></div>--</Grid><EntryTagMenudiff --git a/app/components/TagsSelect.js b/app/components/TagsSelect.jsindex 75755f459..5f7d67735 100644--- a/app/components/TagsSelect.js+++ b/app/components/TagsSelect.js@@ -181,7 +181,8 @@ type Props = {tags: Array<tag>,tagSearchType: string,handleChange: () => void,- allTags: Array<Tag>+ allTags: Array<Tag>,+ isReadOnlyMode?: boolean};const TagsSelect = (props: Props) => {@@ -215,7 +216,8 @@ const TagsSelect = (props: Props) => {allTags,tags,defaultBackgroundColor,- defaultTextColor+ defaultTextColor,+ isReadOnlyMode = false} = props;const selectStyles = {@@ -233,6 +235,7 @@ const TagsSelect = (props: Props) => {<NoSsr><CreatableSelectisClearable={false}+ isDisabled={isReadOnlyMode}classes={classes}options={allTags}getOptionLabel={(option) => option.title}