Changeset View
Changeset View
Standalone View
Standalone View
src/controls/private/ActionsMenu.qml
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 47 | Instantiator { | |||
---|---|---|---|---|---|
48 | id: actionsInstantiator | 48 | id: actionsInstantiator | ||
49 | 49 | | |||
50 | active: theMenu.visible | 50 | active: theMenu.visible | ||
51 | delegate: QtObject { | 51 | delegate: QtObject { | ||
52 | readonly property QtObject action: modelData | 52 | readonly property QtObject action: modelData | ||
53 | property QtObject item: null | 53 | property QtObject item: null | ||
54 | 54 | | |||
55 | function create() { | 55 | function create() { | ||
56 | if (!action.children || action.children.length === 0) { | 56 | if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) { | ||
57 | if (action.hasOwnProperty("separator") && action.separator) { | 57 | if (action.hasOwnProperty("separator") && action.separator) { | ||
58 | item = theMenu.separatorDelegate.createObject(null, {}); | 58 | item = theMenu.separatorDelegate.createObject(null, {}); | ||
59 | } | 59 | } | ||
60 | else { | 60 | else { | ||
61 | item = theMenu.itemDelegate.createObject(null, { ourAction: action }); | 61 | item = theMenu.itemDelegate.createObject(null, { ourAction: action }); | ||
62 | } | 62 | } | ||
63 | theMenu.addItem(item) | 63 | theMenu.addItem(item) | ||
64 | } else if (theMenu.submenuComponent) { | 64 | } else if (theMenu.submenuComponent) { | ||
65 | item = theMenu.submenuComponent.createObject(null, { parentAction: action, title: action.text, actions: action.children }); | 65 | item = theMenu.submenuComponent.createObject(null, { parentAction: action, title: action.text, actions: action.children }); | ||
66 | 66 | | |||
67 | theMenu.insertMenu(theMenu.count, item) | 67 | theMenu.insertMenu(theMenu.count, item) | ||
68 | item.parentItem = theMenu.contentData[theMenu.contentData.length-1] | 68 | item.parentItem = theMenu.contentData[theMenu.contentData.length-1] | ||
69 | } | 69 | } | ||
70 | } | 70 | } | ||
71 | function remove() { | 71 | function remove() { | ||
72 | if (!action.children || action.children.length === 0) { | 72 | if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) { | ||
73 | theMenu.removeItem(item) | 73 | theMenu.removeItem(item) | ||
74 | } else if (theMenu.submenuComponent) { | 74 | } else if (theMenu.submenuComponent) { | ||
75 | theMenu.removeMenu(item) | 75 | theMenu.removeMenu(item) | ||
76 | } | 76 | } | ||
77 | } | 77 | } | ||
78 | } | 78 | } | ||
79 | 79 | | |||
80 | onObjectAdded: object.create() | 80 | onObjectAdded: object.create() | ||
81 | onObjectRemoved: object.remove() | 81 | onObjectRemoved: object.remove() | ||
82 | } | 82 | } | ||
83 | } | 83 | } |