2023-12-05 05:19:00 -05:00
|
|
|
import React, { FC, useState } from 'react'
|
|
|
|
import { Panel, PanelGroup } from 'react-resizable-panels'
|
|
|
|
import NoSelectionPane from '@/features/ide-react/components/editor/no-selection-pane'
|
|
|
|
import FileView from '@/features/file-view/components/file-view'
|
|
|
|
import MultipleSelectionPane from '@/features/ide-react/components/editor/multiple-selection-pane'
|
2023-10-26 04:57:00 -04:00
|
|
|
import { HorizontalResizeHandle } from '@/features/ide-react/components/resize/horizontal-resize-handle'
|
|
|
|
import { HorizontalToggler } from '@/features/ide-react/components/resize/horizontal-toggler'
|
2023-11-02 07:36:04 -04:00
|
|
|
import { DefaultSynctexControl } from '@/features/pdf-preview/components/detach-synctex-control'
|
2023-12-05 05:19:00 -05:00
|
|
|
import PdfPreview from '@/features/pdf-preview/components/pdf-preview'
|
|
|
|
import { usePdfPane } from '@/features/ide-react/hooks/use-pdf-pane'
|
|
|
|
import { useLayoutContext } from '@/shared/context/layout-context'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import classNames from 'classnames'
|
2023-12-15 04:19:42 -05:00
|
|
|
import { fileViewFile } from '@/features/ide-react/util/file-view'
|
|
|
|
import { useFileTreeOpenContext } from '@/features/ide-react/context/file-tree-open-context'
|
2024-02-22 08:20:37 -05:00
|
|
|
import { EditorPane } from '@/features/ide-react/components/editor/editor-pane'
|
2023-10-26 04:57:00 -04:00
|
|
|
|
2024-02-22 08:20:37 -05:00
|
|
|
export const EditorAndPdf: FC = () => {
|
2023-11-15 06:55:05 -05:00
|
|
|
const [resizing, setResizing] = useState(false)
|
2023-10-26 04:57:00 -04:00
|
|
|
|
2023-12-05 05:19:00 -05:00
|
|
|
const { t } = useTranslation()
|
2023-10-26 04:57:00 -04:00
|
|
|
|
2023-12-05 05:19:00 -05:00
|
|
|
const {
|
|
|
|
togglePdfPane,
|
|
|
|
handlePdfPaneExpand,
|
|
|
|
handlePdfPaneCollapse,
|
|
|
|
setPdfIsOpen,
|
|
|
|
pdfIsOpen,
|
|
|
|
pdfPanelRef,
|
|
|
|
} = usePdfPane()
|
2023-10-26 04:57:00 -04:00
|
|
|
|
2023-12-05 05:19:00 -05:00
|
|
|
const { view, pdfLayout } = useLayoutContext()
|
2023-10-26 04:57:00 -04:00
|
|
|
|
2023-12-15 04:19:42 -05:00
|
|
|
const { selectedEntityCount, openEntity } = useFileTreeOpenContext()
|
|
|
|
|
2023-12-05 05:19:00 -05:00
|
|
|
const editorIsOpen =
|
|
|
|
view === 'editor' || view === 'file' || pdfLayout === 'sideBySide'
|
2023-10-26 04:57:00 -04:00
|
|
|
|
|
|
|
return (
|
2023-12-08 04:37:19 -05:00
|
|
|
<PanelGroup
|
|
|
|
autoSaveId="ide-editor-pdf-layout"
|
|
|
|
direction="horizontal"
|
|
|
|
className={classNames({
|
|
|
|
'ide-panel-group-resizing': resizing,
|
2024-02-22 08:20:37 -05:00
|
|
|
hidden: view === 'history',
|
2023-12-08 04:37:19 -05:00
|
|
|
})}
|
|
|
|
>
|
2023-12-05 05:19:00 -05:00
|
|
|
{/* main */}
|
2024-02-22 08:20:37 -05:00
|
|
|
<Panel
|
|
|
|
id="panel-main"
|
|
|
|
order={1}
|
|
|
|
defaultSize={50}
|
|
|
|
minSize={5}
|
|
|
|
className={classNames('ide-react-panel', {
|
|
|
|
'ide-panel-group-resizing': resizing,
|
|
|
|
hidden: !editorIsOpen,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{selectedEntityCount === 0 && <NoSelectionPane />}
|
|
|
|
{selectedEntityCount === 1 && openEntity?.type === 'fileRef' && (
|
|
|
|
<FileView file={fileViewFile(openEntity.entity)} />
|
|
|
|
)}
|
|
|
|
{selectedEntityCount > 1 && (
|
|
|
|
<MultipleSelectionPane selectedEntityCount={selectedEntityCount} />
|
|
|
|
)}
|
|
|
|
<EditorPane />
|
|
|
|
</Panel>
|
2023-12-05 05:19:00 -05:00
|
|
|
|
2024-02-22 08:20:37 -05:00
|
|
|
<HorizontalResizeHandle
|
|
|
|
resizable={pdfLayout === 'sideBySide'}
|
|
|
|
onDoubleClick={togglePdfPane}
|
|
|
|
onDragging={setResizing}
|
|
|
|
className={classNames({
|
|
|
|
hidden: !editorIsOpen,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<HorizontalToggler
|
|
|
|
id="editor-pdf"
|
|
|
|
togglerType="east"
|
|
|
|
isOpen={pdfIsOpen}
|
|
|
|
setIsOpen={setPdfIsOpen}
|
|
|
|
tooltipWhenOpen={t('tooltip_hide_pdf')}
|
|
|
|
tooltipWhenClosed={t('tooltip_show_pdf')}
|
|
|
|
/>
|
2023-12-05 05:19:00 -05:00
|
|
|
|
2024-02-22 08:20:37 -05:00
|
|
|
{pdfLayout === 'sideBySide' && (
|
|
|
|
<div className="synctex-controls">
|
|
|
|
<DefaultSynctexControl />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</HorizontalResizeHandle>
|
2023-12-05 05:19:00 -05:00
|
|
|
|
|
|
|
{/* pdf */}
|
2023-11-17 07:31:57 -05:00
|
|
|
<Panel
|
|
|
|
ref={pdfPanelRef}
|
2023-12-05 05:19:00 -05:00
|
|
|
id="panel-pdf"
|
2023-11-17 07:31:57 -05:00
|
|
|
order={2}
|
2023-12-15 04:19:42 -05:00
|
|
|
defaultSize={50}
|
2024-01-18 07:53:10 -05:00
|
|
|
minSize={5}
|
2023-11-17 07:31:57 -05:00
|
|
|
collapsible
|
2023-12-05 05:19:00 -05:00
|
|
|
onCollapse={handlePdfPaneCollapse}
|
|
|
|
onExpand={handlePdfPaneExpand}
|
2023-11-17 07:31:57 -05:00
|
|
|
className="ide-react-panel"
|
|
|
|
>
|
2023-12-05 05:19:00 -05:00
|
|
|
{pdfIsOpen && <PdfPreview />}
|
2024-02-05 06:58:32 -05:00
|
|
|
{/* ensure that "sync to code" is available in PDF only layout */}
|
|
|
|
{pdfLayout === 'flat' && view === 'pdf' && (
|
|
|
|
<div className="synctex-controls" hidden>
|
|
|
|
<DefaultSynctexControl />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-11-17 07:31:57 -05:00
|
|
|
</Panel>
|
2023-10-26 04:57:00 -04:00
|
|
|
</PanelGroup>
|
|
|
|
)
|
|
|
|
}
|