Move custom functions into FileDialog

CURA-3495
This commit is contained in:
Lipu Fei 2017-04-03 10:58:24 +02:00
parent c5bf107be6
commit f57e866119

View File

@ -259,7 +259,7 @@ UM.MainWindow
{ {
if (drop.urls.length > 0) if (drop.urls.length > 0)
{ {
handleOpenFileUrls(drop.urls); openDialog.handleOpenFileUrls(drop.urls);
} }
} }
} }
@ -722,37 +722,36 @@ UM.MainWindow
handleOpenFileUrls(fileUrls); handleOpenFileUrls(fileUrls);
} }
}
// Yeah... I know... it is a mess to put all those things here. // Yeah... I know... it is a mess to put all those things here.
// There are lots of user interactions in this part of the logic, such as showing a warning dialog here and there, // There are lots of user interactions in this part of the logic, such as showing a warning dialog here and there,
// etc. This means it will come back and forth from time to time between QML and Python. So, separating the logic // etc. This means it will come back and forth from time to time between QML and Python. So, separating the logic
// and view here may require more effort but make things more difficult to understand. // and view here may require more effort but make things more difficult to understand.
function handleOpenFileUrls(fileUrls) function handleOpenFileUrls(fileUrlList)
{ {
// look for valid project files // look for valid project files
var projectFileUrlList = []; var projectFileUrlList = [];
var hasGcode = false; var hasGcode = false;
var nonGcodeFileList = []; var nonGcodeFileList = [];
for (var i in fileUrls) for (var i in fileUrlList)
{ {
var endsWithG = /\.g$/; var endsWithG = /\.g$/;
var endsWithGcode = /\.gcode$/; var endsWithGcode = /\.gcode$/;
if (endsWithG.test(fileUrls[i]) || endsWithGcode.test(fileUrls[i])) if (endsWithG.test(fileUrlList[i]) || endsWithGcode.test(fileUrlList[i]))
{ {
continue; continue;
} }
else if (CuraApplication.checkIsValidProjectFile(fileUrls[i])) else if (CuraApplication.checkIsValidProjectFile(fileUrlList[i]))
{ {
projectFileUrlList.push(fileUrls[i]); projectFileUrlList.push(fileUrlList[i]);
} }
nonGcodeFileList.push(fileUrls[i]); nonGcodeFileList.push(fileUrlList[i]);
} }
hasGcode = nonGcodeFileList.length < fileUrls.length; hasGcode = nonGcodeFileList.length < fileUrlList.length;
// show a warning if selected multiple files together with Gcode // show a warning if selected multiple files together with Gcode
var hasProjectFile = projectFileUrlList.length > 0; var hasProjectFile = projectFileUrlList.length > 0;
var selectedMultipleFiles = fileUrls.length > 1; var selectedMultipleFiles = fileUrlList.length > 1;
if (selectedMultipleFiles && hasGcode) if (selectedMultipleFiles && hasGcode)
{ {
infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles; infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles;
@ -763,16 +762,16 @@ UM.MainWindow
} }
else else
{ {
handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList); handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList);
} }
} }
function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList) function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrlList, projectFileUrlList)
{ {
// we only allow opening one project file // we only allow opening one project file
if (selectedMultipleFiles && hasProjectFile) if (selectedMultipleFiles && hasProjectFile)
{ {
openFilesIncludingProjectsDialog.fileUrls = fileUrls.slice(); openFilesIncludingProjectsDialog.fileUrlList = fileUrlList.slice();
openFilesIncludingProjectsDialog.show(); openFilesIncludingProjectsDialog.show();
return; return;
} }
@ -800,7 +799,8 @@ UM.MainWindow
} }
else else
{ {
openFilesIncludingProjectsDialog.loadModelFiles(fileUrls.slice()); openFilesIncludingProjectsDialog.loadModelFiles(fileUrlList.slice());
}
} }
} }
@ -818,7 +818,7 @@ UM.MainWindow
onAccepted: onAccepted:
{ {
handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList); openDialog.handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList);
} }
} }