lossless-cut/src/renderer/src/TopMenu.tsx

118 wiersze
3.9 KiB
TypeScript
Czysty Zwykły widok Historia

import { CSSProperties, ReactNode, memo, useCallback } from 'react';
import { IoIosSettings } from 'react-icons/io';
2021-04-07 16:33:54 +00:00
import { FaLock, FaUnlock } from 'react-icons/fa';
2024-02-20 14:48:40 +00:00
import { CrossIcon, ListIcon, VolumeUpIcon, VolumeOffIcon } from 'evergreen-ui';
import { useTranslation } from 'react-i18next';
2024-02-10 10:22:05 +00:00
import Button from './components/Button';
import ExportModeButton from './components/ExportModeButton';
import { withBlur } from './util';
import { primaryTextColor, controlsBackground, darkModeTransition } from './colors';
import useUserSettings from './hooks/useUserSettings';
2024-02-10 10:22:05 +00:00
const outFmtStyle = { height: 20, maxWidth: 100 };
const exportModeStyle = { flexGrow: 0, flexBasis: 140 };
const TopMenu = memo(({
filePath,
fileFormat,
copyAnyAudioTrack,
toggleStripAudio,
renderOutFmt,
numStreamsToCopy,
numStreamsTotal,
setStreamsSelectorShown,
toggleSettings,
selectedSegments,
isCustomFormatSelected,
clearOutDir,
}: {
filePath: string | undefined,
fileFormat: string | undefined,
copyAnyAudioTrack: boolean,
toggleStripAudio: () => void,
renderOutFmt: (style: CSSProperties) => ReactNode,
numStreamsToCopy: number,
numStreamsTotal: number,
setStreamsSelectorShown: (v: boolean) => void,
toggleSettings: () => void,
selectedSegments,
isCustomFormatSelected,
clearOutDir,
}) => {
const { t } = useTranslation();
const { customOutDir, changeOutDir, simpleMode, outFormatLocked, setOutFormatLocked } = useUserSettings();
const onOutFormatLockedClick = useCallback(() => setOutFormatLocked((v) => (v ? undefined : fileFormat)), [fileFormat, setOutFormatLocked]);
const showClearWorkingDirButton = !!customOutDir;
2021-04-07 16:33:54 +00:00
function renderFormatLock() {
const Icon = outFormatLocked ? FaLock : FaUnlock;
return <Icon onClick={onOutFormatLockedClick} title={t('Lock/unlock output format')} size={14} style={{ marginRight: 7, marginLeft: 2, color: outFormatLocked ? primaryTextColor : undefined }} />;
}
return (
2022-02-13 07:33:50 +00:00
<div
className="no-user-select"
style={{ background: controlsBackground, transition: darkModeTransition, display: 'flex', alignItems: 'center', padding: '3px 5px', justifyContent: 'space-between', flexWrap: 'wrap' }}
2022-02-13 07:33:50 +00:00
>
{filePath && (
2021-03-30 15:01:25 +00:00
<>
2024-02-10 10:22:05 +00:00
<Button onClick={withBlur(() => setStreamsSelectorShown(true))}>
<ListIcon size={'1em' as unknown as number} verticalAlign="middle" marginRight=".3em" />
{t('Tracks')} ({numStreamsToCopy}/{numStreamsTotal})
</Button>
<Button
2023-03-10 06:22:24 +00:00
title={copyAnyAudioTrack ? t('Keep audio tracks') : t('Discard audio tracks')}
onClick={withBlur(toggleStripAudio)}
>
2024-02-10 10:22:05 +00:00
{copyAnyAudioTrack ? (
<><VolumeUpIcon size={'1em' as unknown as number} verticalAlign="middle" marginRight=".3em" />{t('Keep audio')}</>
2024-02-10 10:22:05 +00:00
) : (
<><VolumeOffIcon size={'1em' as unknown as number} verticalAlign="middle" marginRight=".3em" />{t('Discard audio')}</>
2024-02-10 10:22:05 +00:00
)}
</Button>
2021-03-30 15:01:25 +00:00
</>
)}
<div style={{ flexGrow: 1 }} />
{showClearWorkingDirButton && (
2024-02-10 10:22:05 +00:00
<CrossIcon
role="button"
tabIndex={0}
style={{ width: 20 }}
onClick={withBlur(clearOutDir)}
title={t('Clear working directory')}
/>
)}
2020-04-07 08:55:45 +00:00
<Button
onClick={withBlur(changeOutDir)}
title={customOutDir}
2024-02-10 10:22:05 +00:00
style={{ paddingLeft: showClearWorkingDirButton ? 4 : undefined }}
2020-04-07 08:55:45 +00:00
>
{customOutDir ? t('Working dir set') : t('Working dir unset')}
</Button>
2021-04-07 16:33:54 +00:00
{filePath && (
<>
2024-02-10 10:22:05 +00:00
{renderOutFmt(outFmtStyle)}
2021-04-07 16:33:54 +00:00
{!simpleMode && (isCustomFormatSelected || outFormatLocked) && renderFormatLock()}
2024-02-10 10:22:05 +00:00
<ExportModeButton selectedSegments={selectedSegments} style={exportModeStyle} />
2021-04-07 16:33:54 +00:00
</>
)}
2024-02-10 10:22:05 +00:00
<IoIosSettings size={24} role="button" onClick={toggleSettings} style={{ marginLeft: 5 }} />
2022-02-13 07:33:50 +00:00
</div>
);
});
export default TopMenu;