Cura/resources/qml/Menus/ExtensionMenu.qml
Jaime van Kessel 6b9cc3f1c7 Use the correct function parameters when removing objects in menu
It turns out that the order of these functions matters. So when we created a
function with only one param, it would actually give it the index. Removing
with the index didn't work, so the object would still be there. The Qt objects
would already be deleted which caused segfaults

CURA-9222
2022-04-28 17:03:41 +02:00

64 lines
1.7 KiB
QML

// Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7
import QtQuick.Controls 2.4
import UM 1.5 as UM
import Cura 1.0 as Cura
Cura.Menu
{
id: extensionMenu
title: catalog.i18nc("@title:menu menubar:toplevel", "E&xtensions")
property var extensionModel: UM.ExtensionModel { }
Component
{
id: extensionsMenuItem
Cura.MenuItem
{
text: modelText
onTriggered: extensionsModel.subMenuTriggered(extensionName, modelText)
}
}
Component
{
id: extensionsMenuSeparator
Cura.MenuSeparator {}
}
Instantiator
{
id: extensions
model: extensionModel
Cura.Menu
{
id: sub_menu
title: model.name
shouldBeVisible: actions !== undefined
enabled: actions != null
Instantiator
{
model: actions
Loader
{
property var extensionsModel: extensions.model
property var modelText: model.text
property var extensionName: name
sourceComponent: modelText.trim() == "" ? extensionsMenuSeparator : extensionsMenuItem
}
onObjectAdded: function(index, object) { sub_menu.insertItem(index, object.item)}
onObjectRemoved: function(index, object) { sub_menu.removeItem(object.item)}
}
}
onObjectAdded: function(index, object) { extensionMenu.insertMenu(index, object) }
onObjectRemoved: function(index, object) { extensionMenu.removeMenu(object)}
}
}