Only ask confirm if file opened #261

pull/276/head
Mikael Finstad 6 years ago
parent 146f24e8a4
commit 78a8064e35

@ -261,6 +261,8 @@ const App = memo(() => {
setThumbnails([]); setThumbnails([]);
}, [cutSegmentsHistory, cancelCutSegmentsDebounce, setCutSegments, cancelWaveformDataDebounce, cancelReadKeyframeDataDebounce]); }, [cutSegmentsHistory, cancelCutSegmentsDebounce, setCutSegments, cancelWaveformDataDebounce, cancelReadKeyframeDataDebounce]);
const isFileOpened = !!filePath;
function setTimelineMode(newMode) { function setTimelineMode(newMode) {
if (newMode === 'waveform') { if (newMode === 'waveform') {
setWaveformEnabled(v => !v); setWaveformEnabled(v => !v);
@ -1094,8 +1096,8 @@ const App = memo(() => {
}, []); }, []);
useEffect(() => { useEffect(() => {
electron.ipcRenderer.send('setAskBeforeClose', askBeforeClose); electron.ipcRenderer.send('setAskBeforeClose', askBeforeClose && isFileOpened);
}, [askBeforeClose]); }, [askBeforeClose, isFileOpened]);
const extractAllStreams = useCallback(async () => { const extractAllStreams = useCallback(async () => {
if (!filePath) return; if (!filePath) return;
@ -1134,7 +1136,7 @@ const App = memo(() => {
const firstFile = filePaths[0]; const firstFile = filePaths[0];
if (!filePath) { if (!isFileOpened) {
load(firstFile); load(firstFile);
return; return;
} }
@ -1157,7 +1159,7 @@ const App = memo(() => {
addStreamSourceFile(firstFile); addStreamSourceFile(firstFile);
setStreamsSelectorShown(true); setStreamsSelectorShown(true);
} }
}, [addStreamSourceFile, filePath, load, mergeFiles]); }, [addStreamSourceFile, isFileOpened, load, mergeFiles]);
const onDrop = useCallback(async (ev) => { const onDrop = useCallback(async (ev) => {
ev.preventDefault(); ev.preventDefault();
@ -1177,6 +1179,7 @@ const App = memo(() => {
} }
function closeFile() { function closeFile() {
if (!isFileOpened) return;
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
if (askBeforeClose && !window.confirm('Are you sure you want to close the current file? You will lose all unsaved work')) return; if (askBeforeClose && !window.confirm('Are you sure you want to close the current file? You will lose all unsaved work')) return;
@ -1247,7 +1250,7 @@ const App = memo(() => {
} }
async function importEdlFile() { async function importEdlFile() {
if (!filePath) return; if (!isFileOpened) return;
const { canceled, filePaths } = await dialog.showOpenDialog({ properties: ['openFile'], filters: [{ name: 'CSV files', extensions: ['csv'] }] }); const { canceled, filePaths } = await dialog.showOpenDialog({ properties: ['openFile'], filters: [{ name: 'CSV files', extensions: ['csv'] }] });
if (canceled || filePaths.length < 1) return; if (canceled || filePaths.length < 1) return;
await loadEdlFile(filePaths[0]); await loadEdlFile(filePaths[0]);
@ -1283,7 +1286,7 @@ const App = memo(() => {
electron.ipcRenderer.removeListener('openHelp', openHelp); electron.ipcRenderer.removeListener('openHelp', openHelp);
}; };
}, [ }, [
load, mergeFiles, outputDir, filePath, customOutDir, startTimeOffset, getHtml5ifiedPath, load, mergeFiles, outputDir, filePath, isFileOpened, customOutDir, startTimeOffset, getHtml5ifiedPath,
createDummyVideo, resetState, extractAllStreams, userOpenFiles, cutSegmentsHistory, createDummyVideo, resetState, extractAllStreams, userOpenFiles, cutSegmentsHistory,
loadEdlFile, cutSegments, edlFilePath, askBeforeClose, toggleHelp, loadEdlFile, cutSegments, edlFilePath, askBeforeClose, toggleHelp,
]); ]);
@ -1456,7 +1459,7 @@ const App = memo(() => {
/> />
</div> </div>
{!filePath && ( {!isFileOpened && (
<div className="no-user-select" style={{ position: 'fixed', left: 0, right: 0, top: topBarHeight, bottom: bottomBarHeight, border: '2vmin dashed #252525', color: '#505050', margin: '5vmin', display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center', whiteSpace: 'nowrap' }}> <div className="no-user-select" style={{ position: 'fixed', left: 0, right: 0, top: topBarHeight, bottom: bottomBarHeight, border: '2vmin dashed #252525', color: '#505050', margin: '5vmin', display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center', whiteSpace: 'nowrap' }}>
<div style={{ fontSize: '9vmin' }}>DROP VIDEO(S)</div> <div style={{ fontSize: '9vmin' }}>DROP VIDEO(S)</div>
@ -1537,7 +1540,7 @@ const App = memo(() => {
</div> </div>
)} )}
{filePath && ( {isFileOpened && (
<Fragment> <Fragment>
<div <div
className="no-user-select" className="no-user-select"

Loading…
Cancel
Save