1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 13:50:07 +00:00

[markdown file view] toolbar: added 'download' & 'open via client', and etc.

This commit is contained in:
llj
2021-04-19 16:14:59 +08:00
parent 866e84e692
commit 372be49ae1
3 changed files with 40 additions and 10 deletions

View File

@@ -54,10 +54,6 @@ class FileToolbar extends React.Component {
}); });
} }
openFileViaClient = () => {
location.href = `seafile://openfile?repo_id=${encodeURIComponent(repoID)}&path=${encodeURIComponent(filePath)}`;
}
render() { render() {
const { isLocked, lockedByMe } = this.props; const { isLocked, lockedByMe } = this.props;
const { moreDropdownOpen } = this.state; const { moreDropdownOpen } = this.state;

View File

@@ -6,6 +6,7 @@ import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem, Tooltip } from 'r
import FileInfo from '@seafile/seafile-editor/dist/components/topbar-component/file-info'; import FileInfo from '@seafile/seafile-editor/dist/components/topbar-component/file-info';
const { seafileCollabServer } = window.app.config; const { seafileCollabServer } = window.app.config;
const { canDownloadFile } = window.app.pageOptions;
const propTypes = { const propTypes = {
isDocs: PropTypes.bool.isRequired, isDocs: PropTypes.bool.isRequired,
@@ -62,6 +63,10 @@ class MoreMenu extends React.PureComponent {
this.setState({ dropdownOpen:!this.state.dropdownOpen }); this.setState({ dropdownOpen:!this.state.dropdownOpen });
} }
downloadFile = () => {
location.href = '?dl=1';
}
render() { render() {
const editorMode = this.props.editorMode; const editorMode = this.props.editorMode;
const isSmall = this.props.isSmallScreen; const isSmall = this.props.isSmallScreen;
@@ -77,13 +82,18 @@ class MoreMenu extends React.PureComponent {
<DropdownItem onMouseDown={this.props.onEdit.bind(this, 'plain')}>{gettext('Switch to plain text editor')}</DropdownItem>} <DropdownItem onMouseDown={this.props.onEdit.bind(this, 'plain')}>{gettext('Switch to plain text editor')}</DropdownItem>}
{(!this.props.readOnly && editorMode === 'plain') && {(!this.props.readOnly && editorMode === 'plain') &&
<DropdownItem onMouseDown={this.props.onEdit.bind(this, 'rich')}>{gettext('Switch to rich text editor')}</DropdownItem>} <DropdownItem onMouseDown={this.props.onEdit.bind(this, 'rich')}>{gettext('Switch to rich text editor')}</DropdownItem>}
{!isSmall && this.props.showFileHistory &&
<DropdownItem onMouseDown={this.props.toggleHistory}>{gettext('History')}</DropdownItem>}
{(this.props.openDialogs && editorMode === 'rich') && {(this.props.openDialogs && editorMode === 'rich') &&
<DropdownItem onMouseDown={this.props.openDialogs.bind(this, 'help')}>{gettext('Help')}</DropdownItem> <DropdownItem onMouseDown={this.props.openDialogs.bind(this, 'help')}>{gettext('Help')}</DropdownItem>
} }
{isSmall && canGenerateShareLink && <DropdownItem onMouseDown={this.props.toggleShareLinkDialog}>{gettext('Share')}</DropdownItem>}
{isSmall && <DropdownItem onMouseDown={this.props.openParentDirectory}>{gettext('Open parent directory')}</DropdownItem>} {isSmall && <DropdownItem onMouseDown={this.props.openParentDirectory}>{gettext('Open parent directory')}</DropdownItem>}
{isSmall && canGenerateShareLink && <DropdownItem onMouseDown={this.props.toggleShareLinkDialog}>{gettext('Share')}</DropdownItem>}
{(isSmall && this.props.showFileHistory) && {(isSmall && this.props.showFileHistory) &&
<DropdownItem onMouseDown={this.props.toggleHistory}>{gettext('File History')}</DropdownItem> <DropdownItem onMouseDown={this.props.toggleHistory}>{gettext('History')}</DropdownItem>
}
{isSmall && canDownloadFile &&
<DropdownItem onClick={this.downloadFile}>{gettext('Download')}</DropdownItem>
} }
</DropdownMenu> </DropdownMenu>
</Dropdown> </Dropdown>
@@ -100,6 +110,15 @@ class MarkdownViewerToolbar extends React.Component {
super(props); super(props);
} }
downloadFile = () => {
location.href = '?dl=1';
}
openFileViaClient = () => {
const { repoID, path } = this.props.fileInfo;
location.href = `seafile://openfile?repo_id=${encodeURIComponent(repoID)}&path=${encodeURIComponent(path)}`;
}
render() { render() {
let { contentChanged, saving, isLocked, lockedByMe } = this.props; let { contentChanged, saving, isLocked, lockedByMe } = this.props;
let canPublishDraft = this.props.fileInfo.permission == 'rw'; let canPublishDraft = this.props.fileInfo.permission == 'rw';
@@ -160,10 +179,6 @@ class MarkdownViewerToolbar extends React.Component {
<IconButton id={'shareBtn'} text={gettext('Share')} icon={'fa fa-share-alt'} <IconButton id={'shareBtn'} text={gettext('Share')} icon={'fa fa-share-alt'}
onMouseDown={this.props.toggleShareLinkDialog}/> onMouseDown={this.props.toggleShareLinkDialog}/>
} }
{
this.props.showFileHistory && <IconButton id={'historyButton'}
text={gettext('File History')} onMouseDown={this.props.toggleHistory} icon={'fa fa-history'}/>
}
{ saving ? { saving ?
<button type={'button'} className={'btn btn-icon btn-secondary btn-active'}> <button type={'button'} className={'btn btn-icon btn-secondary btn-active'}>
<i className={'fa fa-spin fa-spinner'}/></button> <i className={'fa fa-spin fa-spinner'}/></button>
@@ -171,12 +186,30 @@ class MarkdownViewerToolbar extends React.Component {
<IconButton text={gettext('Save')} id={'saveButton'} icon={'fa fa-save'} disabled={!contentChanged} <IconButton text={gettext('Save')} id={'saveButton'} icon={'fa fa-save'} disabled={!contentChanged}
onMouseDown={window.seafileEditor && window.seafileEditor.onRichEditorSave} isActive={contentChanged}/> onMouseDown={window.seafileEditor && window.seafileEditor.onRichEditorSave} isActive={contentChanged}/>
} }
{canDownloadFile && (
<IconButton
id="download-file"
icon="fa fa-download"
text={gettext('Download')}
onClick={this.downloadFile}
/>
)}
{this.props.fileInfo.permission == 'rw' &&
<IconButton
id="open-via-client"
icon="sf3-font sf3-font-desktop"
text={gettext('Open via Client')}
onClick={this.openFileViaClient}
/>
}
</ButtonGroup> </ButtonGroup>
<MoreMenu <MoreMenu
readOnly={this.props.readOnly} readOnly={this.props.readOnly}
openDialogs={this.props.openDialogs} openDialogs={this.props.openDialogs}
editorMode={this.props.editorMode} editorMode={this.props.editorMode}
onEdit={this.props.onEdit} onEdit={this.props.onEdit}
showFileHistory={this.props.showFileHistory}
toggleHistory={this.props.toggleHistory}
isSmallScreen={false} isSmallScreen={false}
/> />
</div> </div>

View File

@@ -56,6 +56,7 @@
isLocked: {% if file_locked %}true{% else %}false{% endif %}, isLocked: {% if file_locked %}true{% else %}false{% endif %},
lockedByMe: {% if locked_by_me %}true{% else %}false{% endif %}, lockedByMe: {% if locked_by_me %}true{% else %}false{% endif %},
canLockUnlockFile: {% if can_lock_unlock_file %}true{% else %}false{% endif %}, canLockUnlockFile: {% if can_lock_unlock_file %}true{% else %}false{% endif %},
canDownloadFile: {% if can_download_file %}true{% else %}false{% endif %},
}, },
userInfo: { userInfo: {
username: '{{ user.username }}', username: '{{ user.username }}',