Merge pull request #1535 from LipuFei/feature_CURA-3495_open_in_one

CURA-3495 Open project/models menu item
This commit is contained in:
jack 2017-03-20 10:59:40 +01:00 committed by GitHub
commit 42e7a0defa
5 changed files with 140 additions and 52 deletions

View file

@ -78,11 +78,6 @@ UM.MainWindow
RecentFilesMenu { }
MenuItem
{
action: Cura.Actions.loadWorkspace
}
MenuSeparator { }
MenuItem
@ -744,27 +739,43 @@ UM.MainWindow
id: openDialog;
//: File open dialog title
title: catalog.i18nc("@title:window","Open file")
title: catalog.i18nc("@title:window","Open file(s)")
modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
selectMultiple: true
nameFilters: UM.MeshFileHandler.supportedReadFileTypes;
folder: CuraApplication.getDefaultPath("dialog_load_path")
onAccepted:
{
//Because several implementations of the file dialog only update the folder
//when it is explicitly set.
// Because several implementations of the file dialog only update the folder
// when it is explicitly set.
var f = folder;
folder = f;
CuraApplication.setDefaultPath("dialog_load_path", folder);
for(var i in fileUrls)
// look for valid project files
var projectFileUrlList = [];
for (var i in fileUrls)
{
Printer.readLocalFile(fileUrls[i])
if (CuraApplication.checkIsValidProjectFile(fileUrls[i]))
projectFileUrlList.push(fileUrls[i]);
}
var meshName = backgroundItem.getMeshName(fileUrls[0].toString())
backgroundItem.hasMesh(decodeURIComponent(meshName))
// we only allow opening one project file
var selectedMultipleFiles = fileUrls.length > 1;
var hasProjectFile = projectFileUrlList.length > 0;
var selectedMultipleWithProjectFile = hasProjectFile && selectedMultipleFiles;
if (selectedMultipleWithProjectFile)
{
askOpenProjectOrModelsDialog.fileUrls = fileUrls;
askOpenProjectOrModelsDialog.show();
return;
}
if (hasProjectFile)
loadProjectFile(projectFileUrlList[0]);
else
loadModelFiles(fileUrls);
}
}
@ -774,38 +785,101 @@ UM.MainWindow
onTriggered: openDialog.open()
}
FileDialog
function loadProjectFile(projectFile)
{
id: openWorkspaceDialog;
UM.WorkspaceFileHandler.readLocalFile(projectFile);
//: File open dialog title
title: catalog.i18nc("@title:window","Open workspace")
modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
selectMultiple: false
nameFilters: UM.WorkspaceFileHandler.supportedReadFileTypes;
folder: CuraApplication.getDefaultPath("dialog_load_path")
onAccepted:
{
//Because several implementations of the file dialog only update the folder
//when it is explicitly set.
var f = folder;
folder = f;
CuraApplication.setDefaultPath("dialog_load_path", folder);
for(var i in fileUrls)
{
UM.WorkspaceFileHandler.readLocalFile(fileUrls[i])
}
var meshName = backgroundItem.getMeshName(fileUrls[0].toString())
backgroundItem.hasMesh(decodeURIComponent(meshName))
}
var meshName = backgroundItem.getMeshName(projectFile.toString());
backgroundItem.hasMesh(decodeURIComponent(meshName));
}
Connections
function loadModelFiles(fileUrls)
{
target: Cura.Actions.loadWorkspace
onTriggered: openWorkspaceDialog.open()
for (var i in fileUrls)
Printer.readLocalFile(fileUrls[i]);
var meshName = backgroundItem.getMeshName(fileUrls[0].toString());
backgroundItem.hasMesh(decodeURIComponent(meshName));
}
UM.Dialog
{
// This dialog asks the user whether he/she wants to open the project file we have detected or the model files.
id: askOpenProjectOrModelsDialog
title: catalog.i18nc("@title:window", "Open file(s)")
width: 620
height: 250
maximumHeight: height
maximumWidth: width
minimumHeight: height
minimumWidth: width
modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
property var fileUrls: []
property int spacerHeight: 10
Column
{
anchors.fill: parent
anchors.margins: UM.Theme.getSize("default_margin").width
anchors.left: parent.left
anchors.right: parent.right
spacing: UM.Theme.getSize("default_margin").width
Text
{
id: askOpenProjectOrModelsDialogText
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?")
anchors.margins: UM.Theme.getSize("default_margin").width
font: UM.Theme.getFont("default")
wrapMode: Text.WordWrap
}
Item // Spacer
{
height: askOpenProjectOrModelsDialog.spacerHeight
width: height
}
// Buttons
Item
{
anchors.right: parent.right
anchors.left: parent.left
height: childrenRect.height
Button
{
id: cancelButton
text: catalog.i18nc("@action:button", "Cancel");
anchors.right: importAllAsModelsButton.left
anchors.rightMargin: UM.Theme.getSize("default_margin").width
onClicked:
{
// cancel
askOpenProjectOrModelsDialog.hide();
}
}
Button
{
id: importAllAsModelsButton
text: catalog.i18nc("@action:button", "Import all as models");
anchors.right: parent.right
isDefault: true
onClicked:
{
// load models from all selected file
loadModelFiles(askOpenProjectOrModelsDialog.fileUrls);
askOpenProjectOrModelsDialog.hide();
}
}
}
}
}
EngineLog
@ -846,7 +920,7 @@ UM.MainWindow
function start(id)
{
var actions = Cura.MachineActionManager.getFirstStartActions(id)
var actions = Cura.MachineActionManager.getFirstStartActions(id)
resetPages() // Remove previous pages
for (var i = 0; i < actions.length; i++)
@ -905,7 +979,6 @@ UM.MainWindow
{
discardOrKeepProfileChangesDialog.show()
}
}
Connections
@ -955,4 +1028,3 @@ UM.MainWindow
}
}
}