diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 2a8e6bd7b9..40c91eb487 100755 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -259,40 +259,7 @@ UM.MainWindow { if (drop.urls.length > 0) { - // Import models - var imported_model = -1; - for (var i in drop.urls) - { - // There is no endsWith in this version of JS... - if ((drop.urls[i].length <= 12) || (drop.urls[i].substring(drop.urls[i].length-12) !== ".curaprofile")) { - // Drop an object - Printer.readLocalFile(drop.urls[i]); - if (imported_model == -1) - { - imported_model = i; - } - } - } - - // Import profiles - var import_result = Cura.ContainerManager.importProfiles(drop.urls); - if (import_result.message !== "") { - messageDialog.text = import_result.message - if (import_result.status == "ok") - { - messageDialog.icon = StandardIcon.Information - } - else - { - messageDialog.icon = StandardIcon.Critical - } - messageDialog.open() - } - if (imported_model != -1) - { - var meshName = backgroundItem.getMeshName(drop.urls[imported_model].toString()) - backgroundItem.hasMesh(decodeURIComponent(meshName)) - } + handleOpenFileUrls(drop.urls); } } } @@ -753,35 +720,50 @@ UM.MainWindow CuraApplication.setDefaultPath("dialog_load_path", folder); - // look for valid project files - var projectFileUrlList = []; - var hasGcode = false; - for (var i in fileUrls) - { - var endsWithG = /\.g$/; - var endsWithGcode = /\.gcode$/; - if (endsWithG.test(fileUrls[i]) || endsWithGcode.test(fileUrls[i])) { - hasGcode = true; - continue; - } - else if (CuraApplication.checkIsValidProjectFile(fileUrls[i])) { - projectFileUrlList.push(fileUrls[i]); - } - } + handleOpenFileUrls(fileUrls); + } + } - // show a warning if selected multiple files together with Gcode - var hasProjectFile = projectFileUrlList.length > 0; - var selectedMultipleFiles = fileUrls.length > 1; - if (selectedMultipleFiles && hasGcode) { - infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles; - infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile; - infoMultipleFilesWithGcodeDialog.fileUrls = fileUrls; - infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList; - infoMultipleFilesWithGcodeDialog.open(); + // 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, + // 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. + function handleOpenFileUrls(fileUrls) + { + // look for valid project files + var projectFileUrlList = []; + var hasGcode = false; + var nonGcodeFileList = []; + for (var i in fileUrls) + { + var endsWithG = /\.g$/; + var endsWithGcode = /\.gcode$/; + if (endsWithG.test(fileUrls[i]) || endsWithGcode.test(fileUrls[i])) + { + continue; } - else { - handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList); + else if (CuraApplication.checkIsValidProjectFile(fileUrls[i])) + { + projectFileUrlList.push(fileUrls[i]); } + nonGcodeFileList.push(fileUrls[i]); + } + hasGcode = nonGcodeFileList.length < fileUrls.length; + + // show a warning if selected multiple files together with Gcode + var hasProjectFile = projectFileUrlList.length > 0; + var selectedMultipleFiles = fileUrls.length > 1; + if (selectedMultipleFiles && hasGcode) + { + infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles; + infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile; + infoMultipleFilesWithGcodeDialog.fileUrls = nonGcodeFileList.slice(); + infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice(); + infoMultipleFilesWithGcodeDialog.open(); + } + else + { + handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList); } } @@ -790,7 +772,7 @@ UM.MainWindow // we only allow opening one project file if (selectedMultipleFiles && hasProjectFile) { - openFilesIncludingProjectsDialog.fileUrls = fileUrls; + openFilesIncludingProjectsDialog.fileUrls = fileUrls.slice(); openFilesIncludingProjectsDialog.show(); return; } @@ -802,9 +784,13 @@ UM.MainWindow // check preference var choice = UM.Preferences.getValue("cura/choice_on_open_project"); if (choice == "open_as_project") + { openFilesIncludingProjectsDialog.loadProjectFile(projectFile); + } else if (choice == "open_as_model") - openFilesIncludingProjectsDialog.loadModelFiles([projectFile]); + { + openFilesIncludingProjectsDialog.loadModelFiles([projectFile].slice()); + } else // always ask { // ask whether to open as project or as models @@ -814,7 +800,7 @@ UM.MainWindow } else { - openFilesIncludingProjectsDialog.loadModelFiles(fileUrls); + openFilesIncludingProjectsDialog.loadModelFiles(fileUrls.slice()); } } diff --git a/resources/qml/OpenFilesIncludingProjectsDialog.qml b/resources/qml/OpenFilesIncludingProjectsDialog.qml index af7b1c0f47..0a2fc0acf7 100644 --- a/resources/qml/OpenFilesIncludingProjectsDialog.qml +++ b/resources/qml/OpenFilesIncludingProjectsDialog.qml @@ -56,7 +56,7 @@ UM.Dialog Text { - text: catalog.i18nc("@text:window", "We have found multiple project file(s) within the files you have\nselected. You can open only one project file at a time. We\nsuggest to only import models from those files. Would you like\nto proceed?") + text: catalog.i18nc("@text:window", "We have found one or more project file(s) within the files you\nhave selected. You can open only one project file at a time. We\nsuggest to only import models from those files. Would you like\nto proceed?") anchors.margins: UM.Theme.getSize("default_margin").width font: UM.Theme.getFont("default") wrapMode: Text.WordWrap