This commit is contained in:
Ghostkeeper 2016-03-21 15:33:33 +01:00
commit ebafaad411
2 changed files with 57 additions and 25 deletions

View File

@ -215,26 +215,42 @@ UM.MainWindow
Instantiator
{
id: profileMenuInstantiator
model: UM.ProfilesModel { addSeparators: true }
model: UM.ProfilesModel {}
property int separatorIndex: -1
Loader {
property QtObject model_data: model
property int model_index: index
sourceComponent: model.separator ? profileMenuSeparatorDelegate : profileMenuItemDelegate
sourceComponent: profileMenuItemDelegate
}
onObjectAdded:
{
//Insert a separator between readonly and custom profiles
if(separatorIndex < 0 && index > 0) {
if(model.getItem(index-1).readOnly != model.getItem(index).readOnly) {
profileMenu.addSeparator();
separatorIndex = index;
}
}
//Because of the separator, custom profiles move one index lower
profileMenu.insertItem((model.getItem(index).readOnly) ? index : index + 1, object.item);
}
onObjectRemoved:
{
//When adding a profile, the menu is rebuild by removing all items.
//If a separator was added, we need to remove that too.
if(separatorIndex >= 0)
{
profileMenu.removeItem(profileMenu.items[separatorIndex])
separatorIndex = -1;
}
profileMenu.removeItem(object.item);
}
onObjectAdded: profileMenu.insertItem(index, object.item)
onObjectRemoved: profileMenu.removeItem(object.item)
}
ExclusiveGroup { id: profileMenuGroup; }
Component
{
id: profileMenuSeparatorDelegate
MenuSeparator {
id: item
}
}
Component
{
id: profileMenuItemDelegate
@ -259,7 +275,7 @@ UM.MainWindow
}
}
MenuSeparator { }
MenuSeparator { id: profileMenuSeparator }
MenuItem { action: actions.addProfile; }
MenuItem { action: actions.manageProfiles; }

View File

@ -51,23 +51,40 @@ Item{
Instantiator
{
id: profileSelectionInstantiator
model: UM.ProfilesModel { addSeparators: true }
model: UM.ProfilesModel {}
property int separatorIndex: -1
Loader {
property QtObject model_data: model
property int model_index: index
sourceComponent: model.separator ? menuSeparatorDelegate : menuItemDelegate
sourceComponent: menuItemDelegate
}
onObjectAdded:
{
//Insert a separator between readonly and custom profiles
if(separatorIndex < 0 && index > 0) {
if(model.getItem(index-1).readOnly != model.getItem(index).readOnly) {
profileSelectionMenu.addSeparator();
separatorIndex = index;
}
}
//Because of the separator, custom profiles move one index lower
profileSelectionMenu.insertItem((model.getItem(index).readOnly) ? index : index + 1, object.item);
}
onObjectRemoved:
{
//When adding a profile, the menu is rebuild by removing all items.
//If a separator was added, we need to remove that too.
if(separatorIndex >= 0)
{
profileSelectionMenu.removeItem(profileSelectionMenu.items[separatorIndex])
separatorIndex = -1;
}
profileSelectionMenu.removeItem(object.item);
}
onObjectAdded: profileSelectionMenu.insertItem(index, object.item)
onObjectRemoved: profileSelectionMenu.removeItem(object.item)
}
ExclusiveGroup { id: profileSelectionMenuGroup; }
Component
{
id: menuSeparatorDelegate
MenuSeparator {
id: item
}
}
Component
{
id: menuItemDelegate
@ -92,7 +109,6 @@ Item{
}
}
MenuSeparator { }
MenuItem {
action: base.addProfileAction;