From 5613a5de2074af2c373c137601b930a5ce6f9ba0 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 15 Feb 2016 14:19:32 +0100 Subject: [PATCH] Reset menu selection when canceling profile switch Contributes to CURA-853 --- resources/qml/Cura.qml | 13 ++++++++++++- resources/qml/ProfileSetup.qml | 13 ++++++++++++- resources/qml/SidebarHeader.qml | 26 ++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index a1e1ce4909..6d385279d0 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -214,13 +214,24 @@ UM.MainWindow Instantiator { + id: profileMenuInstantiator model: UM.ProfilesModel { } MenuItem { text: model.name; checkable: true; checked: model.active; exclusiveGroup: profileMenuGroup; - onTriggered: UM.MachineManager.setActiveProfile(model.name) + onTriggered: + { + UM.MachineManager.setActiveProfile(model.name); + if (!model.active) { + //Selecting a profile was canceled; undo menu selection + checked = false; + var activeProfileName = UM.MachineManager.activeProfile; + var activeProfileIndex = profileMenuInstantiator.model.find("name", activeProfileName); + profileMenuInstantiator.model.setProperty(activeProfileIndex, "active", true); + } + } } onObjectAdded: profileMenu.insertItem(index, object) onObjectRemoved: profileMenu.removeItem(object) diff --git a/resources/qml/ProfileSetup.qml b/resources/qml/ProfileSetup.qml index 52e9bc0827..d2be4ee69b 100644 --- a/resources/qml/ProfileSetup.qml +++ b/resources/qml/ProfileSetup.qml @@ -49,6 +49,7 @@ Item{ id: profileSelectionMenu Instantiator { + id: profileSelectionInstantiator model: UM.ProfilesModel { } MenuItem { @@ -56,7 +57,17 @@ Item{ checkable: true; checked: model.active; exclusiveGroup: profileSelectionMenuGroup; - onTriggered: UM.MachineManager.setActiveProfile(model.name) + onTriggered: + { + UM.MachineManager.setActiveProfile(model.name); + if (!model.active) { + //Selecting a profile was canceled; undo menu selection + checked = false; + var activeProfileName = UM.MachineManager.activeProfile; + var activeProfileIndex = profileSelectionInstantiator.model.find("name", activeProfileName); + profileSelectionInstantiator.model.setProperty(activeProfileIndex, "active", true); + } + } } onObjectAdded: profileSelectionMenu.insertItem(index, object) onObjectRemoved: profileSelectionMenu.removeItem(object) diff --git a/resources/qml/SidebarHeader.qml b/resources/qml/SidebarHeader.qml index a921e8b002..68095e9401 100644 --- a/resources/qml/SidebarHeader.qml +++ b/resources/qml/SidebarHeader.qml @@ -129,6 +129,7 @@ Item id: variantsSelectionMenu Instantiator { + id: variantSelectionInstantiator model: UM.MachineVariantsModel { id: variantsModel } MenuItem { @@ -136,7 +137,17 @@ Item checkable: true; checked: model.active; exclusiveGroup: variantSelectionMenuGroup; - onTriggered: UM.MachineManager.setActiveMachineVariant(variantsModel.getItem(index).name) + onTriggered: + { + UM.MachineManager.setActiveMachineVariant(variantsModel.getItem(index).name); + if (typeof(model) !== "undefined" && !model.active) { + //Selecting a variant was canceled; undo menu selection + checked = false; + var activeMachineVariantName = UM.MachineManager.activeMachineVariant; + var activeMachineVariantIndex = variantSelectionInstantiator.model.find("name", activeMachineVariantName); + variantSelectionInstantiator.model.setProperty(activeMachineVariantIndex, "active", true); + } + } } onObjectAdded: variantsSelectionMenu.insertItem(index, object) onObjectRemoved: variantsSelectionMenu.removeItem(object) @@ -182,6 +193,7 @@ Item id: materialSelectionMenu Instantiator { + id: materialSelectionInstantiator model: UM.MachineMaterialsModel { id: machineMaterialsModel } MenuItem { @@ -189,7 +201,17 @@ Item checkable: true; checked: model.active; exclusiveGroup: materialSelectionMenuGroup; - onTriggered: UM.MachineManager.setActiveMaterial(machineMaterialsModel.getItem(index).name) + onTriggered: + { + UM.MachineManager.setActiveMaterial(machineMaterialsModel.getItem(index).name); + if (typeof(model) !== "undefined" && !model.active) { + //Selecting a material was canceled; undo menu selection + checked = false; + var activeMaterialName = UM.MachineManager.activeMaterial; + var activeMaterialIndex = materialSelectionInstantiator.model.find("name", activeMaterialName); + materialSelectionInstantiator.model.setProperty(activeMaterialIndex, "active", true); + } + } } onObjectAdded: materialSelectionMenu.insertItem(index, object) onObjectRemoved: materialSelectionMenu.removeItem(object)