2021-10-12 04:47:46 -04:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Dropdown,
|
|
|
|
MenuItem,
|
|
|
|
OverlayTrigger,
|
|
|
|
Tooltip,
|
|
|
|
} from 'react-bootstrap'
|
2021-09-30 07:29:25 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
import ControlledDropdown from '../../../shared/components/controlled-dropdown'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2021-10-08 05:23:33 -04:00
|
|
|
import { memo } from 'react'
|
2021-09-30 07:29:25 -04:00
|
|
|
import classnames from 'classnames'
|
2021-10-15 05:39:56 -04:00
|
|
|
import { useCompileContext } from '../../../shared/context/compile-context'
|
2021-09-30 07:29:25 -04:00
|
|
|
|
2021-10-12 04:47:46 -04:00
|
|
|
const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl'
|
|
|
|
|
2021-09-30 07:29:25 -04:00
|
|
|
function PdfCompileButton() {
|
|
|
|
const {
|
|
|
|
autoCompile,
|
|
|
|
compiling,
|
|
|
|
draft,
|
|
|
|
hasChanges,
|
|
|
|
setAutoCompile,
|
|
|
|
setDraft,
|
|
|
|
setStopOnValidationError,
|
2021-10-15 05:39:56 -04:00
|
|
|
stopOnValidationError,
|
2021-10-08 05:23:33 -04:00
|
|
|
startCompile,
|
2021-09-30 07:29:25 -04:00
|
|
|
stopCompile,
|
|
|
|
recompileFromScratch,
|
2021-10-15 05:39:56 -04:00
|
|
|
} = useCompileContext()
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const compileButtonLabel = compiling ? t('compiling') + '…' : t('recompile')
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ControlledDropdown
|
|
|
|
className={classnames({
|
|
|
|
'toolbar-item': true,
|
|
|
|
'btn-recompile-group': true,
|
|
|
|
'btn-recompile-group-has-changes': hasChanges,
|
|
|
|
})}
|
|
|
|
id="pdf-recompile-dropdown"
|
|
|
|
>
|
2021-10-12 04:47:46 -04:00
|
|
|
<OverlayTrigger
|
|
|
|
placement="bottom"
|
|
|
|
delayShow={500}
|
|
|
|
overlay={
|
|
|
|
<Tooltip id="tooltip-logs-toggle" className="keyboard-tooltip">
|
|
|
|
{t('recompile_pdf')}{' '}
|
|
|
|
<span className="keyboard-shortcut">({modifierKey} + Enter)</span>
|
|
|
|
</Tooltip>
|
|
|
|
}
|
2021-09-30 07:29:25 -04:00
|
|
|
>
|
2021-10-12 04:47:46 -04:00
|
|
|
<Button
|
|
|
|
className="btn-recompile"
|
|
|
|
bsStyle="success"
|
2021-10-21 04:09:45 -04:00
|
|
|
onClick={startCompile}
|
2021-10-12 04:47:46 -04:00
|
|
|
aria-label={compileButtonLabel}
|
|
|
|
>
|
|
|
|
<Icon type="refresh" spin={compiling} />
|
|
|
|
<span className="toolbar-hide-medium toolbar-hide-small btn-recompile-label">
|
|
|
|
{compileButtonLabel}
|
|
|
|
</span>
|
|
|
|
</Button>
|
|
|
|
</OverlayTrigger>
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
<Dropdown.Toggle
|
|
|
|
aria-label={t('toggle_compile_options_menu')}
|
|
|
|
className="btn-recompile"
|
|
|
|
bsStyle="success"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Dropdown.Menu>
|
|
|
|
<MenuItem header>{t('auto_compile')}</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem onSelect={() => setAutoCompile(true)}>
|
|
|
|
<Icon type={autoCompile ? 'check' : ''} modifier="fw" />
|
|
|
|
{t('on')}
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem onSelect={() => setAutoCompile(false)}>
|
|
|
|
<Icon type={!autoCompile ? 'check' : ''} modifier="fw" />
|
|
|
|
{t('off')}
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem header>{t('compile_mode')}</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem onSelect={() => setDraft(false)}>
|
|
|
|
<Icon type={!draft ? 'check' : ''} modifier="fw" />
|
|
|
|
{t('normal')}
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem onSelect={() => setDraft(true)}>
|
|
|
|
<Icon type={draft ? 'check' : ''} modifier="fw" />
|
|
|
|
{t('fast')} <span className="subdued">[draft]</span>
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem header>Syntax Checks</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem onSelect={() => setStopOnValidationError(true)}>
|
|
|
|
<Icon type={stopOnValidationError ? 'check' : ''} modifier="fw" />
|
|
|
|
{t('stop_on_validation_error')}
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem onSelect={() => setStopOnValidationError(false)}>
|
|
|
|
<Icon type={!stopOnValidationError ? 'check' : ''} modifier="fw" />
|
|
|
|
{t('ignore_validation_errors')}
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem divider />
|
|
|
|
|
|
|
|
<MenuItem
|
|
|
|
onSelect={stopCompile}
|
|
|
|
disabled={!compiling}
|
|
|
|
aria-disabled={!compiling}
|
|
|
|
>
|
|
|
|
{t('stop_compile')}
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem
|
|
|
|
onSelect={recompileFromScratch}
|
|
|
|
disabled={compiling}
|
|
|
|
aria-disabled={compiling}
|
|
|
|
>
|
|
|
|
{t('recompile_from_scratch')}
|
|
|
|
</MenuItem>
|
|
|
|
</Dropdown.Menu>
|
|
|
|
</ControlledDropdown>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfCompileButton)
|