Merge pull request #6456 from Ultimaker/CURA-6824

Consider user preference when opening project files from cli.
This commit is contained in:
Lipu Fei 2019-10-07 13:46:44 +02:00 committed by GitHub
commit 121315cbf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 41 deletions

View File

@ -1600,8 +1600,12 @@ class CuraApplication(QtApplication):
openProjectFile = pyqtSignal(QUrl, arguments = ["project_file"]) # Emitted when a project file is about to open. openProjectFile = pyqtSignal(QUrl, arguments = ["project_file"]) # Emitted when a project file is about to open.
@pyqtSlot(QUrl, bool) @pyqtSlot(QUrl, str)
def readLocalFile(self, file, skip_project_file_check = False): @pyqtSlot(QUrl)
## Open a local file
# \param project_mode How to handle project files. Either None(default): Follow user preference, "open_as_model" or
# "open_as_project". This parameter is only considered if the file is a project file.
def readLocalFile(self, file: QUrl, project_mode: Optional[str] = None):
if not file.isValid(): if not file.isValid():
return return
@ -1612,10 +1616,24 @@ class CuraApplication(QtApplication):
self.deleteAll() self.deleteAll()
break break
if not skip_project_file_check and self.checkIsValidProjectFile(file): is_project_file = self.checkIsValidProjectFile(file)
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) self.callLater(self.openProjectFile.emit, file)
return 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"): if self.getPreferences().getValue("cura/select_models_on_load"):
Selection.clear() Selection.clear()

View File

@ -87,7 +87,7 @@ class SingleInstance:
if command == "clear-all": if command == "clear-all":
self._application.callLater(lambda: self._application.deleteAll()) self._application.callLater(lambda: self._application.deleteAll())
# Command: Load a model file # Command: Load a model or project file
elif command == "open": elif command == "open":
self._application.callLater(lambda f = payload["filePath"]: self._application._openFile(f)) self._application.callLater(lambda f = payload["filePath"]: self._application._openFile(f))

View File

@ -53,7 +53,7 @@ UM.Dialog
UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model") 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()) var meshName = backgroundItem.getMeshName(base.fileUrl.toString())
backgroundItem.hasMesh(decodeURIComponent(meshName)) backgroundItem.hasMesh(decodeURIComponent(meshName))

View File

@ -42,7 +42,7 @@ UM.Dialog
{ {
for (var i in fileUrls) for (var i in fileUrls)
{ {
CuraApplication.readLocalFile(fileUrls[i], true); CuraApplication.readLocalFile(fileUrls[i], "open_as_model");
} }
var meshName = backgroundItem.getMeshName(fileUrls[0].toString()); var meshName = backgroundItem.getMeshName(fileUrls[0].toString());

View File

@ -29,42 +29,8 @@ Menu
} }
onTriggered: onTriggered:
{ {
var toShowDialog = false; CuraApplication.readLocalFile(modelData);
var toOpenAsProject = false;
var toOpenAsModel = false;
if (CuraApplication.checkIsValidProjectFile(modelData)) {
// check preference
var choice = UM.Preferences.getValue("cura/choice_on_open_project");
if (choice == "open_as_project")
{
toOpenAsProject = true;
}else if (choice == "open_as_model"){
toOpenAsModel = true;
}else{
toShowDialog = true;
}
}
else {
toOpenAsModel = true;
}
if (toShowDialog) {
askOpenAsProjectOrModelsDialog.fileUrl = modelData;
askOpenAsProjectOrModelsDialog.show();
return;
}
// open file in the prefered way
if (toOpenAsProject)
{
UM.WorkspaceFileHandler.readLocalFile(modelData);
}
else if (toOpenAsModel)
{
CuraApplication.readLocalFile(modelData, true);
}
var meshName = backgroundItem.getMeshName(modelData.toString()) var meshName = backgroundItem.getMeshName(modelData.toString())
backgroundItem.hasMesh(decodeURIComponent(meshName)) backgroundItem.hasMesh(decodeURIComponent(meshName))
} }