From 2df0d96923f3e701f29beda532676cbc28dbd7e9 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Tue, 1 Oct 2019 11:54:53 +0200 Subject: [PATCH] Consider user preference when opening project files from cli. The logic using just a "skip_project_file_check" boolean was too obscure imho, so used a string value with more explicit values to improve readability CURA-6824 --- cura/CuraApplication.py | 24 ++++++++++++++++--- cura/SingleInstance.py | 2 +- .../AskOpenAsProjectOrModelsDialog.qml | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index c8faae3704..899a00efbd 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -1600,8 +1600,11 @@ class CuraApplication(QtApplication): openProjectFile = pyqtSignal(QUrl, arguments = ["project_file"]) # Emitted when a project file is about to open. - @pyqtSlot(QUrl, bool) - def readLocalFile(self, file, skip_project_file_check = False): + @pyqtSlot(QUrl, str) + ## Open a local file + # \param force_project_mode \type{str} Either "open_as_model" or "open_as_project". This parameter is only + # considered if the file is a project file. + def readLocalFile(self, file, force_project_mode = None): if not file.isValid(): return @@ -1612,10 +1615,25 @@ class CuraApplication(QtApplication): self.deleteAll() break - if not skip_project_file_check and self.checkIsValidProjectFile(file): + is_project_file = self.checkIsValidProjectFile(file) + project_mode = force_project_mode + + if project_mode is None: + project_mode = self.getPreferences().getValue("cura/choice_on_open_project") + + if is_project_file and project_mode == "open_as_project": + # open as project immediately without presenting a dialog + workspace_handler = self.getWorkspaceFileHandler() + workspace_handler.readLocalFile(file) + return + + if is_project_file and project_mode == "always_ask": + # present a dialog asking to open as project or import models self.callLater(self.openProjectFile.emit, file) return + # Either the file is a model file or we want to load only models from project. Continue to load models. + if self.getPreferences().getValue("cura/select_models_on_load"): Selection.clear() diff --git a/cura/SingleInstance.py b/cura/SingleInstance.py index cf07b143c6..6fcf0da6cf 100644 --- a/cura/SingleInstance.py +++ b/cura/SingleInstance.py @@ -87,7 +87,7 @@ class SingleInstance: if command == "clear-all": self._application.callLater(lambda: self._application.deleteAll()) - # Command: Load a model file + # Command: Load a model or project file elif command == "open": self._application.callLater(lambda f = payload["filePath"]: self._application._openFile(f)) diff --git a/resources/qml/Dialogs/AskOpenAsProjectOrModelsDialog.qml b/resources/qml/Dialogs/AskOpenAsProjectOrModelsDialog.qml index f6436f62c5..2566a2d44c 100644 --- a/resources/qml/Dialogs/AskOpenAsProjectOrModelsDialog.qml +++ b/resources/qml/Dialogs/AskOpenAsProjectOrModelsDialog.qml @@ -53,7 +53,7 @@ UM.Dialog UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model") } - CuraApplication.readLocalFile(base.fileUrl, true) + CuraApplication.readLocalFile(base.fileUrl, "open_as_model") var meshName = backgroundItem.getMeshName(base.fileUrl.toString()) backgroundItem.hasMesh(decodeURIComponent(meshName))