mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-15 21:26:06 +08:00
Merge pull request #1599 from Ultimaker/feature_CURA-3495_open_menu
CURA-3495 Open project/files menu
This commit is contained in:
commit
a8be748df7
@ -259,40 +259,7 @@ UM.MainWindow
|
|||||||
{
|
{
|
||||||
if (drop.urls.length > 0)
|
if (drop.urls.length > 0)
|
||||||
{
|
{
|
||||||
// Import models
|
handleOpenFileUrls(drop.urls);
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -753,44 +720,59 @@ UM.MainWindow
|
|||||||
|
|
||||||
CuraApplication.setDefaultPath("dialog_load_path", folder);
|
CuraApplication.setDefaultPath("dialog_load_path", folder);
|
||||||
|
|
||||||
|
handleOpenFileUrls(fileUrls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
// look for valid project files
|
||||||
var projectFileUrlList = [];
|
var projectFileUrlList = [];
|
||||||
var hasGcode = false;
|
var hasGcode = false;
|
||||||
|
var nonGcodeFileList = [];
|
||||||
for (var i in fileUrls)
|
for (var i in fileUrls)
|
||||||
{
|
{
|
||||||
var endsWithG = /\.g$/;
|
var endsWithG = /\.g$/;
|
||||||
var endsWithGcode = /\.gcode$/;
|
var endsWithGcode = /\.gcode$/;
|
||||||
if (endsWithG.test(fileUrls[i]) || endsWithGcode.test(fileUrls[i])) {
|
if (endsWithG.test(fileUrls[i]) || endsWithGcode.test(fileUrls[i]))
|
||||||
hasGcode = true;
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (CuraApplication.checkIsValidProjectFile(fileUrls[i])) {
|
else if (CuraApplication.checkIsValidProjectFile(fileUrls[i]))
|
||||||
|
{
|
||||||
projectFileUrlList.push(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
|
// show a warning if selected multiple files together with Gcode
|
||||||
var hasProjectFile = projectFileUrlList.length > 0;
|
var hasProjectFile = projectFileUrlList.length > 0;
|
||||||
var selectedMultipleFiles = fileUrls.length > 1;
|
var selectedMultipleFiles = fileUrls.length > 1;
|
||||||
if (selectedMultipleFiles && hasGcode) {
|
if (selectedMultipleFiles && hasGcode)
|
||||||
|
{
|
||||||
infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles;
|
infoMultipleFilesWithGcodeDialog.selectedMultipleFiles = selectedMultipleFiles;
|
||||||
infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile;
|
infoMultipleFilesWithGcodeDialog.hasProjectFile = hasProjectFile;
|
||||||
infoMultipleFilesWithGcodeDialog.fileUrls = fileUrls;
|
infoMultipleFilesWithGcodeDialog.fileUrls = nonGcodeFileList.slice();
|
||||||
infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList;
|
infoMultipleFilesWithGcodeDialog.projectFileUrlList = projectFileUrlList.slice();
|
||||||
infoMultipleFilesWithGcodeDialog.open();
|
infoMultipleFilesWithGcodeDialog.open();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList);
|
handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList)
|
function handleOpenFiles(selectedMultipleFiles, hasProjectFile, fileUrls, projectFileUrlList)
|
||||||
{
|
{
|
||||||
// we only allow opening one project file
|
// we only allow opening one project file
|
||||||
if (selectedMultipleFiles && hasProjectFile)
|
if (selectedMultipleFiles && hasProjectFile)
|
||||||
{
|
{
|
||||||
openFilesIncludingProjectsDialog.fileUrls = fileUrls;
|
openFilesIncludingProjectsDialog.fileUrls = fileUrls.slice();
|
||||||
openFilesIncludingProjectsDialog.show();
|
openFilesIncludingProjectsDialog.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -802,9 +784,13 @@ UM.MainWindow
|
|||||||
// check preference
|
// check preference
|
||||||
var choice = UM.Preferences.getValue("cura/choice_on_open_project");
|
var choice = UM.Preferences.getValue("cura/choice_on_open_project");
|
||||||
if (choice == "open_as_project")
|
if (choice == "open_as_project")
|
||||||
|
{
|
||||||
openFilesIncludingProjectsDialog.loadProjectFile(projectFile);
|
openFilesIncludingProjectsDialog.loadProjectFile(projectFile);
|
||||||
|
}
|
||||||
else if (choice == "open_as_model")
|
else if (choice == "open_as_model")
|
||||||
openFilesIncludingProjectsDialog.loadModelFiles([projectFile]);
|
{
|
||||||
|
openFilesIncludingProjectsDialog.loadModelFiles([projectFile].slice());
|
||||||
|
}
|
||||||
else // always ask
|
else // always ask
|
||||||
{
|
{
|
||||||
// ask whether to open as project or as models
|
// ask whether to open as project or as models
|
||||||
@ -814,7 +800,7 @@ UM.MainWindow
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
openFilesIncludingProjectsDialog.loadModelFiles(fileUrls);
|
openFilesIncludingProjectsDialog.loadModelFiles(fileUrls.slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ UM.Dialog
|
|||||||
|
|
||||||
Text
|
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
|
anchors.margins: UM.Theme.getSize("default_margin").width
|
||||||
font: UM.Theme.getFont("default")
|
font: UM.Theme.getFont("default")
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
|
Loading…
x
Reference in New Issue
Block a user