Skip to content

The swiss army knife of lossless video/audio editing

use Dialog for concat files

Mikael Finstad25111311f5bb
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index a1c3c83b..ad4462e5 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -40,7 +40,7 @@ import ValueTuners from './components/ValueTuners';
import VolumeControl from './components/VolumeControl';
import PlaybackStreamSelector from './components/PlaybackStreamSelector';
import BatchFilesList from './components/BatchFilesList';
-import ConcatSheet from './components/ConcatSheet';
+import ConcatDialog from './components/ConcatDialog';
import KeyboardShortcuts from './components/KeyboardShortcuts';
import Working from './components/Working';
import OutputFormatSelect from './components/OutputFormatSelect';
@@ -133,7 +133,7 @@ function App() {
const [detectedFps, setDetectedFps] = useState<number>();
const [mainFileMeta, setMainFileMeta] = useState<{ streams: FileMeta['streams'], formatData: FFprobeFormat, chapters: FFprobeChapter[] }>();
const [streamsSelectorShown, setStreamsSelectorShown] = useState(false);
- const [concatSheetOpen, setConcatSheetOpen] = useState(false);
+ const [concatDialogOpen, setConcatDialogOpen] = useState(false);
const [zoomUnrounded, setZoom] = useState(1);
const [shortestFlag, setShortestFlag] = useState(false);
const [zoomWindowStartTime, setZoomWindowStartTime] = useState(0);
@@ -880,7 +880,7 @@ function App() {
}
// only after ensuring out dir access, we can close the concat dialog
- setConcatSheetOpen(false);
+ setConcatDialogOpen(false);
setWorking({ text: i18n.t('Merging') });
const warnings = new Set<string>();
@@ -1749,7 +1749,7 @@ function App() {
if (newFilePaths.length > 1 && alwaysConcatMultipleFiles) {
batchLoadPaths(newFilePaths);
- setConcatSheetOpen(true);
+ setConcatDialogOpen(true);
return;
}
@@ -1826,7 +1826,7 @@ function App() {
if (filePath) batchPaths.add(filePath);
newFilePaths.forEach((path) => batchPaths.add(path));
batchLoadPaths([...batchPaths]);
- if (batchPaths.size > 1) setConcatSheetOpen(true);
+ if (batchPaths.size > 1) setConcatDialogOpen(true);
}
// else: no match means dialog canceled or nothing useful to do:
} finally {
@@ -1854,7 +1854,7 @@ function App() {
return;
}
- setConcatSheetOpen(true);
+ setConcatDialogOpen(true);
}, [batchFiles.length, openFilesDialog]);
const togglePlaySelectedSegments = useCallback(() => togglePlay({ resetPlaybackRate: true, requestPlaybackMode: 'play-selected-segments' }), [togglePlay]);
@@ -2090,7 +2090,7 @@ function App() {
};
}, []);
- const { keyboardLayoutMap, updateKeyboardLayout } = useKeyboard({ keyBindings, keyUpActions, getKeyboardAction, closeExportConfirm, exportConfirmOpen, concatSheetOpen, setConcatSheetOpen });
+ const { keyboardLayoutMap, updateKeyboardLayout } = useKeyboard({ keyBindings, keyUpActions, getKeyboardAction, closeExportConfirm, exportConfirmOpen });
useEffect(() => {
// eslint-disable-next-line unicorn/prefer-add-event-listener
@@ -2704,7 +2704,7 @@ function App() {
</Dialog.Portal>
</Dialog.Root>
- <ConcatSheet isShown={batchFiles.length > 0 && concatSheetOpen} onHide={() => setConcatSheetOpen(false)} paths={batchFilePaths} mergedFileTemplate={mergedFileTemplateOrDefault} generateMergedFileNames={generateMergedFileNames} onConcat={userConcatFiles} setAlwaysConcatMultipleFiles={setAlwaysConcatMultipleFiles} alwaysConcatMultipleFiles={alwaysConcatMultipleFiles} fileFormat={fileFormat} setFileFormat={setFileFormat} detectedFileFormat={detectedFileFormat} setDetectedFileFormat={setDetectedFileFormat} onOutputFormatUserChange={onOutputFormatUserChange} />
+ <ConcatDialog isShown={batchFiles.length > 0 && concatDialogOpen} onHide={() => setConcatDialogOpen(false)} paths={batchFilePaths} mergedFileTemplate={mergedFileTemplateOrDefault} generateMergedFileNames={generateMergedFileNames} onConcat={userConcatFiles} setAlwaysConcatMultipleFiles={setAlwaysConcatMultipleFiles} alwaysConcatMultipleFiles={alwaysConcatMultipleFiles} fileFormat={fileFormat} setFileFormat={setFileFormat} detectedFileFormat={detectedFileFormat} setDetectedFileFormat={setDetectedFileFormat} onOutputFormatUserChange={onOutputFormatUserChange} />
<KeyboardShortcuts isShown={keyboardShortcutsVisible} onHide={() => setKeyboardShortcutsVisible(false)} keyBindings={keyBindings} setKeyBindings={setKeyBindings} currentCutSeg={currentCutSeg} resetKeyBindings={resetKeyBindings} />
diff --git a/src/renderer/src/components/ConcatSheet.tsx b/src/renderer/src/components/ConcatDialog.tsx
similarity index 53%
rename from src/renderer/src/components/ConcatSheet.tsx
rename to src/renderer/src/components/ConcatDialog.tsx
index 1474d773..598c2bde 100644
--- a/src/renderer/src/components/ConcatSheet.tsx
+++ b/src/renderer/src/components/ConcatDialog.tsx
@@ -15,7 +15,6 @@ import { FFprobeChapter, FFprobeFormat, FFprobeStream } from '../../../common/ff
import Button, { DialogButton } from './Button';
import { defaultMergedFileTemplate, GeneratedOutFileNames, GenerateMergedOutFileNames } from '../util/outputNameTemplate';
import { primaryColor, saveColor, warningColor } from '../colors';
-import ExportSheet from './ExportSheet';
import * as Dialog from './Dialog';
import FileNameTemplateEditor from './FileNameTemplateEditor';
import HighlightedText from './HighlightedText';
@@ -33,7 +32,7 @@ function Alert({ text }: { text: string }) {
);
}
-function ConcatSheet({ isShown, onHide, paths, mergedFileTemplate, generateMergedFileNames, onConcat, alwaysConcatMultipleFiles, setAlwaysConcatMultipleFiles, fileFormat, setFileFormat, detectedFileFormat, setDetectedFileFormat, onOutputFormatUserChange }: {
+function ConcatDialog({ isShown, onHide, paths, mergedFileTemplate, generateMergedFileNames, onConcat, alwaysConcatMultipleFiles, setAlwaysConcatMultipleFiles, fileFormat, setFileFormat, detectedFileFormat, setDetectedFileFormat, onOutputFormatUserChange }: {
isShown: boolean,
onHide: () => void,
paths: string[],
@@ -189,123 +188,128 @@ function ConcatSheet({ isShown, onHide, paths, mergedFileTemplate, generateMerge
}, []);
return (
- <ExportSheet
- visible={isShown}
- title={t('Merge/concatenate files')}
- onClosePress={onHide}
- renderButton={() => (
- <Button className={simpleMode ? 'export-animation' : undefined} disabled={fileFormat == null} onClick={onConcatClick} style={{ fontSize: '1.3em', padding: '0 .3em', marginLeft: '1em', background: primaryColor, color: 'white', border: 'none' }}>
- <AiOutlineMergeCells style={{ fontSize: '1.4em', verticalAlign: 'middle' }} /> {t('Merge!')}
- </Button>
- )}
- width="70em"
- >
- <div style={{ marginBottom: '1em' }}>
- <div style={{ whiteSpace: 'pre-wrap', marginBottom: '1em' }}>
- {t('This dialog can be used to concatenate files in series, e.g. one after the other:\n[file1][file2][file3]\nIt can NOT be used for merging tracks in parallell (like adding an audio track to a video).\nMake sure all files are of the exact same codecs & codec parameters (fps, resolution etc).')}
- </div>
-
- <div>
- {paths.map((path, index) => (
- <div key={path} style={rowStyle} title={path}>
- <div>
- <span style={{ opacity: 0.7, marginRight: '.4em' }}>{`${index + 1}.`}</span>
- <span>{basename(path)}</span>
-
- {allFilesMetaCache[path] ? (
- problemsByFile[path] ? (
- <Dialog.Root>
- <Dialog.Trigger asChild>
- <Button title={i18n.t('Mismatches detected')} style={{ color: warningColor, marginLeft: '1em', padding: '.2em .4em' }}><FaExclamationTriangle /></Button>
- </Dialog.Trigger>
-
- <Dialog.Portal>
- <Dialog.Overlay />
- <Dialog.Content aria-describedby={undefined}>
- <Dialog.Title>{t('Mismatches detected')}</Dialog.Title>
-
- <ul style={{ margin: '10px 0', textAlign: 'left' }}>
- {(problemsByFile[path] || []).map((problem) => <li key={problem}>{problem}</li>)}
- </ul>
-
- <Dialog.CloseButton />
- </Dialog.Content>
- </Dialog.Portal>
- </Dialog.Root>
- ) : (
- <FaCheck style={{ color: saveColor, verticalAlign: 'middle', marginLeft: '1em' }} />
- )
- ) : (
- <FaQuestionCircle style={{ color: warningColor, verticalAlign: 'middle', marginLeft: '1em' }} />
- )}
- </div>
+ <Dialog.Root open={isShown} onOpenChange={(open) => !open && onHide()}>
+ <Dialog.Portal>
+ <Dialog.Overlay />
+ <Dialog.Content style={{ width: '60em' }}>
+ <Dialog.Title>{t('Merge/concatenate files')}</Dialog.Title>
+ <Dialog.Description style={{ whiteSpace: 'pre-wrap' }}>{t('This dialog can be used to concatenate files in series, e.g. one after the other:\n[file1][file2][file3]\nIt can NOT be used for merging tracks in parallell (like adding an audio track to a video).\nMake sure all files are of the exact same codecs & codec parameters (fps, resolution etc).')}</Dialog.Description>
+
+ <div style={{ marginBottom: '1em' }}>
+ <div>
+ {paths.map((path, index) => (
+ <div key={path} style={rowStyle} title={path}>
+ <div>
+ <span style={{ opacity: 0.7, marginRight: '.4em' }}>{`${index + 1}.`}</span>
+ <span>{basename(path)}</span>
+
+ {allFilesMetaCache[path] ? (
+ problemsByFile[path] ? (
+ <Dialog.Root>
+ <Dialog.Trigger asChild>
+ <Button title={i18n.t('Mismatches detected')} style={{ color: warningColor, marginLeft: '1em', padding: '.2em .4em' }}><FaExclamationTriangle /></Button>
+ </Dialog.Trigger>
+
+ <Dialog.Portal>
+ <Dialog.Overlay />
+ <Dialog.Content aria-describedby={undefined}>
+ <Dialog.Title>{t('Mismatches detected')}</Dialog.Title>
+
+ <ul style={{ margin: '10px 0', textAlign: 'left' }}>
+ {(problemsByFile[path] || []).map((problem) => <li key={problem}>{problem}</li>)}
+ </ul>
+
+ <Dialog.CloseButton />
+ </Dialog.Content>
+ </Dialog.Portal>
+ </Dialog.Root>
+ ) : (
+ <FaCheck style={{ color: saveColor, verticalAlign: 'middle', marginLeft: '1em' }} />
+ )
+ ) : (
+ <FaQuestionCircle style={{ color: warningColor, verticalAlign: 'middle', marginLeft: '1em' }} />
+ )}
+ </div>
+ </div>
+ ))}
</div>
- ))}
- </div>
- </div>
+ </div>
- <div style={{ display: 'flex', alignItems: 'center', gap: '1em', marginBottom: '1em', flexWrap: 'wrap' }}>
- <Checkbox checked={enableReadFileMeta} onCheckedChange={handleReadFileMetaCheckedChange} label={t('Check compatibility')} />
+ <div style={{ marginBottom: '1em' }}>
+ {t('Save output to path:')}<br />
+ <HighlightedText role="button" onClick={changeOutDir} style={{ wordBreak: 'break-all', cursor: 'pointer' }}>{outputDir}</HighlightedText>
+ </div>
- <Dialog.Root>
- <Dialog.Trigger asChild>
- <Button style={{ padding: '.3em .5em' }}><FaCog style={{ verticalAlign: 'middle', fontSize: '1.4em', marginRight: '.2em' }} /> {t('Options')}</Button>
- </Dialog.Trigger>
+ {fileFormat != null && (
+ <div style={{ marginBottom: '1em' }}>
+ <FileNameTemplateEditor mode="merge-files" template={mergedFileTemplate} setTemplate={setMergedFileTemplate} defaultTemplate={defaultMergedFileTemplate} generateFileNames={generateFileNames} />
+ </div>
+ )}
+
+ {enableReadFileMeta && (!allFilesMeta || Object.values(problemsByFile).length > 0) && (
+ <Alert text={t('A mismatch was detected in at least one file. You may proceed, but the resulting file might not be playable.')} />
+ )}
+ {!enableReadFileMeta && (
+ <Alert text={t('File compatibility check is not enabled, so the merge operation might not produce a valid output. Enable "Check compatibility" below to check file compatibility before merging.')} />
+ )}
+
+ <Dialog.ButtonRow>
+ <Checkbox checked={enableReadFileMeta} onCheckedChange={handleReadFileMetaCheckedChange} label={t('Check compatibility')} />
+
+ <Dialog.Close asChild>
+ <DialogButton>{t('Cancel')}</DialogButton>
+ </Dialog.Close>
- <Dialog.Portal>
- <Dialog.Overlay />
- <Dialog.Content style={{ width: '40em' }} aria-describedby={undefined}>
- <Dialog.Title>{t('Merge options')}</Dialog.Title>
+ <Dialog.Root>
+ <Dialog.Trigger asChild>
+ <Button style={{ padding: '.3em .5em' }}><FaCog style={{ verticalAlign: 'middle', fontSize: '1.4em', marginRight: '.2em' }} /> {t('Options')}</Button>
+ </Dialog.Trigger>
- <Checkbox checked={includeAllStreams} onCheckedChange={(checked) => setIncludeAllStreams(checked === true)} label={`${t('Include all tracks?')} - ${t('If this is checked, all audio/video/subtitle/data tracks will be included. This may not always work for all file types. If not checked, only default streams will be included.')}`} />
+ <Dialog.Portal>
+ <Dialog.Overlay />
+ <Dialog.Content style={{ width: '40em' }} aria-describedby={undefined}>
+ <Dialog.Title>{t('Merge options')}</Dialog.Title>
- <Checkbox checked={preserveMetadataOnMerge} onCheckedChange={(checked) => setPreserveMetadataOnMerge(checked === true)} label={t('Preserve original metadata when merging? (slow)')} />
+ <Checkbox checked={includeAllStreams} onCheckedChange={(checked) => setIncludeAllStreams(checked === true)} label={`${t('Include all tracks?')} - ${t('If this is checked, all audio/video/subtitle/data tracks will be included. This may not always work for all file types. If not checked, only default streams will be included.')}`} />
- {fileFormat != null && isMov(fileFormat) && <Checkbox checked={preserveMovData} onCheckedChange={(checked) => setPreserveMovData(checked === true)} label={t('Preserve all MP4/MOV metadata?')} />}
+ <Checkbox checked={preserveMetadataOnMerge} onCheckedChange={(checked) => setPreserveMetadataOnMerge(checked === true)} label={t('Preserve original metadata when merging? (slow)')} />
- <Checkbox checked={segmentsToChapters} onCheckedChange={(checked) => setSegmentsToChapters(checked === true)} label={t('Create chapters from merged segments? (slow)')} />
+ {fileFormat != null && isMov(fileFormat) && <Checkbox checked={preserveMovData} onCheckedChange={(checked) => setPreserveMovData(checked === true)} label={t('Preserve all MP4/MOV metadata?')} />}
- <Checkbox checked={alwaysConcatMultipleFiles} onCheckedChange={(checked) => setAlwaysConcatMultipleFiles(checked === true)} label={t('Always open this dialog when opening multiple files')} />
+ <Checkbox checked={segmentsToChapters} onCheckedChange={(checked) => setSegmentsToChapters(checked === true)} label={t('Create chapters from merged segments? (slow)')} />
- <Checkbox checked={clearBatchFilesAfterConcat} onCheckedChange={(checked) => setClearBatchFilesAfterConcat(checked === true)} label={t('Clear batch file list after merge')} />
+ <Checkbox checked={alwaysConcatMultipleFiles} onCheckedChange={(checked) => setAlwaysConcatMultipleFiles(checked === true)} label={t('Always open this dialog when opening multiple files')} />
- <p>{t('Note that also other settings from the normal export dialog apply to this merge function. For more information about all options, see the export dialog.')}</p>
+ <Checkbox checked={clearBatchFilesAfterConcat} onCheckedChange={(checked) => setClearBatchFilesAfterConcat(checked === true)} label={t('Clear batch file list after merge')} />
- <Dialog.ButtonRow>
- <Dialog.Close asChild>
- <DialogButton primary>{t('Close')}</DialogButton>
- </Dialog.Close>
- </Dialog.ButtonRow>
+ <p>{t('Note that also other settings from the normal export dialog apply to this merge function. For more information about all options, see the export dialog.')}</p>
- <Dialog.CloseButton />
- </Dialog.Content>
- </Dialog.Portal>
- </Dialog.Root>
+ <Dialog.ButtonRow>
+ <Dialog.Close asChild>
+ <DialogButton primary>{t('Close')}</DialogButton>
+ </Dialog.Close>
+ </Dialog.ButtonRow>
- {fileFormat != null && detectedFileFormat != null && (
- <OutputFormatSelect style={{ height: '2.1em', maxWidth: '20em' }} detectedFileFormat={detectedFileFormat} fileFormat={fileFormat} onOutputFormatUserChange={onOutputFormatUserChange} />
- )}
- </div>
+ <Dialog.CloseButton />
+ </Dialog.Content>
+ </Dialog.Portal>
+ </Dialog.Root>
- <div style={{ marginBottom: '1em' }}>
- {t('Save output to path:')}<br />
- <HighlightedText role="button" onClick={changeOutDir} style={{ wordBreak: 'break-all', cursor: 'pointer' }}>{outputDir}</HighlightedText>
- </div>
+ {fileFormat != null && detectedFileFormat != null && (
+ <OutputFormatSelect style={{ height: '2.1em', maxWidth: '20em' }} detectedFileFormat={detectedFileFormat} fileFormat={fileFormat} onOutputFormatUserChange={onOutputFormatUserChange} />
+ )}
- {fileFormat != null && (
- <div style={{ marginBottom: '1em' }}>
- <FileNameTemplateEditor mode="merge-files" template={mergedFileTemplate} setTemplate={setMergedFileTemplate} defaultTemplate={defaultMergedFileTemplate} generateFileNames={generateFileNames} />
- </div>
- )}
+ <DialogButton disabled={fileFormat == null} onClick={onConcatClick} primary style={{ backgroundColor: primaryColor }}>
+ <AiOutlineMergeCells style={{ fontSize: '1.4em', verticalAlign: 'middle' }} />
+ {t('Merge files')}
+ </DialogButton>
+ </Dialog.ButtonRow>
- {enableReadFileMeta && (!allFilesMeta || Object.values(problemsByFile).length > 0) && (
- <Alert text={t('A mismatch was detected in at least one file. You may proceed, but the resulting file might not be playable.')} />
- )}
- {!enableReadFileMeta && (
- <Alert text={t('File compatibility check is not enabled, so the merge operation might not produce a valid output. Enable "Check compatibility" below to check file compatibility before merging.')} />
- )}
- </ExportSheet>
+ <Dialog.CloseButton />
+ </Dialog.Content>
+ </Dialog.Portal>
+ </Dialog.Root>
);
}
-export default memo(ConcatSheet);
+export default memo(ConcatDialog);
diff --git a/src/renderer/src/components/ExportSheet.tsx b/src/renderer/src/components/ExportSheet.tsx
index b8c2fc44..b1e34e2c 100644
--- a/src/renderer/src/components/ExportSheet.tsx
+++ b/src/renderer/src/components/ExportSheet.tsx
@@ -4,7 +4,7 @@ import { motion, AnimatePresence } from 'framer-motion';
import styles from './ExportSheet.module.css';
import CloseButton from './CloseButton';
-// TODO use Dialog component instead, but we need to first remove usage of sweetalert2 inside export confirm and concat dialog because they don't play well together
+// TODO use Dialog component instead, but we need to first remove usage of sweetalert2 inside export confirm because they don't play well together
function ExportSheet({
visible,
children,
diff --git a/src/renderer/src/hooks/useKeyboard.ts b/src/renderer/src/hooks/useKeyboard.ts
index 03aab750..4c55d083 100644
--- a/src/renderer/src/hooks/useKeyboard.ts
+++ b/src/renderer/src/hooks/useKeyboard.ts
@@ -21,14 +21,12 @@ See also https://github.com/mifi/lossless-cut/issues/2515
interface KeyEventParams { e: KeyboardEvent, action: KeyboardAction | undefined }
-export default ({ keyBindings, keyUpActions, getKeyboardAction, closeExportConfirm, exportConfirmOpen, concatSheetOpen, setConcatSheetOpen }: {
+export default ({ keyBindings, keyUpActions, getKeyboardAction, closeExportConfirm, exportConfirmOpen }: {
keyBindings: KeyBinding[],
keyUpActions: Record<string, () => void>,
getKeyboardAction: (action: KeyboardAction) => (() => boolean) | (() => void),
exportConfirmOpen: boolean,
closeExportConfirm: () => void,
- concatSheetOpen: boolean,
- setConcatSheetOpen: (open: boolean) => void,
}) => {
const [keyboardLayoutMap, setKeyboardLayoutMap] = useState<KeyboardLayoutMap | undefined>();
@@ -54,14 +52,6 @@ export default ({ keyBindings, keyUpActions, getKeyboardAction, closeExportConfi
return; // stop here, don't allow other key actions than export while dialog is open
}
}
- if (concatSheetOpen) {
- if (isEscape) {
- setConcatSheetOpen(false);
- e.preventDefault();
- e.stopPropagation();
- }
- return; // don't allow any other key actions while dialog is open
- }
// From now on, only handle key events when focus is on document body
// because we don't allow focus to anything else
@@ -94,7 +84,7 @@ export default ({ keyBindings, keyUpActions, getKeyboardAction, closeExportConfi
}
if (isDev) console.log('key event', e.code, action, { defaultPrevented: e.defaultPrevented });
- }, [closeExportConfirm, concatSheetOpen, exportConfirmOpen, getKeyboardAction, setConcatSheetOpen]);
+ }, [closeExportConfirm, exportConfirmOpen, getKeyboardAction]);
// optimization to prevent re-binding all the time: