fix default open action when opening multiple

fixes #2894
pull/2774/head
Mikael Finstad 2 months ago
parent 2605292763
commit 260529b5bc
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -84,7 +84,7 @@ import {
import getSwal, { errorToast, showPlaybackFailedMessage } from './swal';
import { adjustRate } from './util/rate-calculator';
import { askExtractFramesAsImages } from './dialogs/extractFrames';
import type { CleanupChoicesType } from './dialogs';
import type { CleanupChoicesType, OpenFileResponse } from './dialogs';
import { askForOutDir, askForImportChapters, askForFileOpenAction, showDiskFull, showExportFailedDialog, showConcatFailedDialog, openYouTubeChaptersDialog, showRefuseToOverwrite, showOpenDialog, showMuxNotSupported, promptDownloadMediaUrl, showOutputNotWritable, deleteFiles, mustDisallowVob, toastError } from './dialogs';
import { openSendReportDialog } from './reporting';
import { sortSegments, convertSegmentsToChaptersWithGaps, hasAnySegmentOverlap, isDurationValid, getPlaybackAction, getSegmentTags, filterNonMarkers, isInitialSegment } from './segments';
@ -1843,11 +1843,12 @@ function App() {
if (isFileOpened) inputOptions.mergeWithCurrentFile = i18n.t('Merge/concatenate with current file');
if (batchFiles.length > 0 || newFilePaths.length > 1) inputOptions.addToBatch = i18n.t('Add the file to the batch list');
const inputOptionsKeys = Object.keys(inputOptions);
const inputOptionsKeys = Object.keys(inputOptions) as (keyof typeof inputOptions)[];
let openFileResponse: string | undefined;
let openFileResponse: OpenFileResponse | undefined;
if (inputOptionsKeys.length === 1) [openFileResponse] = inputOptionsKeys;
if (enableAskForFileOpenAction && inputOptionsKeys.length > 1) openFileResponse = await askForFileOpenAction(inputOptions);
if (!enableAskForFileOpenAction && inputOptionsKeys.length > 1) openFileResponse = 'addToBatch';
if (enableAskForFileOpenAction && inputOptionsKeys.length > 1) openFileResponse = await askForFileOpenAction(Object.entries(inputOptions) as [OpenFileResponse, string][]);
else if (newFilePaths.length === 1) openFileResponse = 'open';
if (openFileResponse === 'open') {

@ -99,10 +99,12 @@ export async function askForFfPath(defaultPath?: string | undefined) {
return (filePaths && filePaths.length === 1) ? filePaths[0] : undefined;
}
export async function askForFileOpenAction(inputOptions: Record<string, string>) {
let value: string | undefined;
export type OpenFileResponse = 'open' | 'project' | 'tracks' | 'subtitles' | 'addToBatch' | 'mergeWithCurrentFile';
function onClick(key?: string) {
export async function askForFileOpenAction(inputOptions: [OpenFileResponse, string][]) {
let value: OpenFileResponse | undefined;
function onClick(key?: OpenFileResponse) {
value = key;
getSwal().Swal.close();
}
@ -112,7 +114,7 @@ export async function askForFileOpenAction(inputOptions: Record<string, string>)
<div style={{ textAlign: 'left' }}>
<div style={{ marginBottom: '1em' }}>{i18n.t('You opened a new file. What do you want to do?')}</div>
{Object.entries(inputOptions).map(([key, text]) => (
{inputOptions.map(([key, text]) => (
<button type="button" key={key} onClick={() => onClick(key)} className="button-unstyled" style={{ display: 'block', marginBottom: '.5em' }}>
<FaArrowRight style={{ color: 'var(--gray-10)', verticalAlign: 'middle' }} /> {text}
</button>

Loading…
Cancel
Save