From 99478d6a15acd9728482295e1bab131d543fc0a9 Mon Sep 17 00:00:00 2001 From: casper Date: Tue, 15 Feb 2022 11:18:02 +0100 Subject: [PATCH] Add "Ok" button in export/import materials popup dialog Proposed solution takes a different approach compared to the previous solution. Previously there was one message dialog that was hidden by default. When the import/export material confirm dialog was triggered the text and body of this message dialog would change. I did deviate from this pattern as this might introduce hard to debug issues when a property would be set on this dialog. As this dialog is used for various instances every instance should update the same properties. If one property is missed then the popup might show unwanted information. I propose a different solution instead. Here a popup is created dynamically. This way the properties used for each instance is clear. This might add a delay when showing the popup as the whole component needs to be created when called. CURA-8959 --- .../Preferences/Materials/MaterialsPage.qml | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index dbcef6c573..2e4ded685d 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -335,16 +335,19 @@ Item folder: CuraApplication.getDefaultPath("dialog_material_path") onAccepted: { - var result = Cura.ContainerManager.importMaterialContainer(fileUrl); + const result = Cura.ContainerManager.importMaterialContainer(fileUrl); + const messageDialog = Qt.createQmlObject("import UM 1.5 as UM; UM.MessageDialog { onClosed: destroy() }", base); + messageDialog.standardButtons = Dialog.Ok; messageDialog.title = catalog.i18nc("@title:window", "Import Material"); - if(result.status == "success") + switch (result.status) { - messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag !", "Successfully imported material %1").arg(fileUrl); - } - else - { - messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags or !", "Could not import material %1: %2").arg(fileUrl).arg(result.message); + case "success": + messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag !", "Successfully imported material %1").arg(fileUrl); + break; + default: + messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags or !", "Could not import material %1: %2").arg(fileUrl).arg(result.message); + break; } messageDialog.open(); CuraApplication.setDefaultPath("dialog_material_path", folder); @@ -360,25 +363,23 @@ Item folder: CuraApplication.getDefaultPath("dialog_material_path") onAccepted: { - var result = Cura.ContainerManager.exportContainer(base.currentItem.root_material_id, selectedNameFilter, fileUrl); + const result = Cura.ContainerManager.exportContainer(base.currentItem.root_material_id, selectedNameFilter, fileUrl); + const messageDialog = Qt.createQmlObject("import UM 1.5 as UM; UM.MessageDialog { onClosed: destroy() }", base); messageDialog.title = catalog.i18nc("@title:window", "Export Material"); - if(result.status == "error") + messageDialog.standardButtons = Dialog.Ok; + switch (result.status) { - messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags and !", "Failed to export material to %1: %2").arg(fileUrl).arg(result.message); - messageDialog.open(); - } - else if(result.status == "success") - { - messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag !", "Successfully exported material to %1").arg(result.path); - messageDialog.open(); + case "error": + messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags and !", "Failed to export material to %1: %2").arg(fileUrl).arg(result.message); + break; + case "success": + messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tag !", "Successfully exported material to %1").arg(result.path); + break; } + messageDialog.open(); + CuraApplication.setDefaultPath("dialog_material_path", folder); } } - - UM.MessageDialog - { - id: messageDialog - } }