Reset menu selection when canceling profile switch

Contributes to CURA-853
This commit is contained in:
fieldOfView 2016-02-15 14:19:32 +01:00
parent 69331696f0
commit 5613a5de20
3 changed files with 48 additions and 4 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)