From 5bec46a29cb2f4f0c63ccf1d9e74e669a77651e0 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Tue, 28 Mar 2017 12:16:33 +0200 Subject: [PATCH 1/6] Drag-and-drop files behave the same as open file menu CURA-3495 --- resources/qml/Cura.qml | 106 +++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 63 deletions(-) diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 2a8e6bd7b9..f17d9e9189 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,36 +720,45 @@ 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(); + function handleOpenFileUrls(fileUrls) + { + // 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 { - handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList); + else if (CuraApplication.checkIsValidProjectFile(fileUrls[i])) + { + projectFileUrlList.push(fileUrls[i]); } } + + // 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.slice(); + infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice(); + infoMultipleFilesWithGcodeDialog.open(); + } + else + { + handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList); + } } function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList) @@ -790,7 +766,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 +778,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 +794,7 @@ UM.MainWindow } else { - openFilesIncludingProjectsDialog.loadModelFiles(fileUrls); + openFilesIncludingProjectsDialog.loadModelFiles(fileUrls.slice()); } } From 1fc7120fff9f659456f73b90f1dab0b7d5b343a6 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Tue, 28 Mar 2017 12:54:32 +0200 Subject: [PATCH 2/6] Fix dialog text "file(s)" -> "files" CURA-3495 --- resources/qml/OpenFilesIncludingProjectsDialog.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/OpenFilesIncludingProjectsDialog.qml b/resources/qml/OpenFilesIncludingProjectsDialog.qml index af7b1c0f47..0fcd716c49 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 multiple project files 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?") anchors.margins: UM.Theme.getSize("default_margin").width font: UM.Theme.getFont("default") wrapMode: Text.WordWrap From e4af8e36bbb11ebd9e8d859fe7dc8ee219f5155a Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Tue, 28 Mar 2017 14:38:21 +0200 Subject: [PATCH 3/6] Fix dialog text for opening multiple files with project(s) CURA-3495 --- resources/qml/OpenFilesIncludingProjectsDialog.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/OpenFilesIncludingProjectsDialog.qml b/resources/qml/OpenFilesIncludingProjectsDialog.qml index 0fcd716c49..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 files 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 From 208935960f4678b522de150989bcd6f2b24b1651 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Tue, 28 Mar 2017 15:02:45 +0200 Subject: [PATCH 4/6] Add comments for putting open file logic in qml CURA-3495 --- resources/qml/Cura.qml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index f17d9e9189..871d7fcd40 100755 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -724,6 +724,10 @@ UM.MainWindow } } + // FIXME(lipu): 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 From 42b8f06e999682aac089e8dd94c37d8dc3e18753 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 29 Mar 2017 12:52:53 +0200 Subject: [PATCH 5/6] Ignore gcode when selected multiple files CURA-3495 --- resources/qml/Cura.qml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 871d7fcd40..2515510f82 100755 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -733,20 +733,22 @@ UM.MainWindow // 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])) { - hasGcode = true; continue; } 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; @@ -755,7 +757,7 @@ UM.MainWindow { infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles; infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile; - infoMultipleFilesWithGcodeDialog.fileUrls = fileUrls.slice(); + infoMultipleFilesWithGcodeDialog.fileUrls = nonGcodeFileList.slice(); infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice(); infoMultipleFilesWithGcodeDialog.open(); } From e92c21af2881cecea8d65b62104639cdc2316afd Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 29 Mar 2017 12:53:16 +0200 Subject: [PATCH 6/6] Remove FIXME CURA-3495 --- resources/qml/Cura.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 2515510f82..40c91eb487 100755 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -724,7 +724,7 @@ UM.MainWindow } } - // FIXME(lipu): 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, // 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.