Changeset View
Changeset View
Standalone View
Standalone View
src/controls/ActionToolBar.qml
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 90 | RowLayout { | |||
---|---|---|---|---|---|
99 | function findIndex(array, cb) { | 99 | function findIndex(array, cb) { | ||
100 | for (var i = 0, length = array.length; i < length; ++i) { | 100 | for (var i = 0, length = array.length; i < length; ++i) { | ||
101 | if (cb(array[i])) { | 101 | if (cb(array[i])) { | ||
102 | return i; | 102 | return i; | ||
103 | } | 103 | } | ||
104 | } | 104 | } | ||
105 | return -1; | 105 | return -1; | ||
106 | } | 106 | } | ||
107 | | ||||
108 | function isActionVisible(action) { | ||||
109 | var index = actionsLayout.findIndex(actionsLayout.overflowSet, function(act){return act === action}); | ||||
110 | if (index === -1) { | ||||
111 | index = actionsLayout.findIndex(root.hiddenActions, function(act){return act === action}); | ||||
112 | if (index === -1) { | ||||
113 | return true | ||||
114 | } | ||||
115 | } | ||||
116 | return false | ||||
117 | } | ||||
118 | | ||||
107 | RowLayout { | 119 | RowLayout { | ||
108 | Layout.minimumWidth: 0 | 120 | Layout.minimumWidth: 0 | ||
109 | Layout.fillHeight: true | 121 | Layout.fillHeight: true | ||
110 | Repeater { | 122 | Repeater { | ||
111 | model: root.actions | 123 | model: root.actions | ||
112 | delegate: PrivateActionToolButton { | 124 | delegate: PrivateActionToolButton { | ||
113 | id: actionDelegate | 125 | id: actionDelegate | ||
114 | flat: root.flat | 126 | flat: root.flat | ||
Show All 30 Lines | |||||
145 | } | 157 | } | ||
146 | } | 158 | } | ||
147 | 159 | | |||
148 | Item { | 160 | Item { | ||
149 | Layout.fillWidth: true | 161 | Layout.fillWidth: true | ||
150 | visible: root.Layout.fillWidth | 162 | visible: root.Layout.fillWidth | ||
151 | } | 163 | } | ||
152 | 164 | | |||
153 | Controls.ToolButton { | 165 | PrivateActionToolButton { | ||
154 | id: moreButton | 166 | id: moreButton | ||
155 | 167 | | |||
156 | Layout.alignment: Qt.AlignRight | 168 | Layout.alignment: Qt.AlignRight | ||
157 | Kirigami.Icon { | | |||
158 | anchors.centerIn: parent | | |||
159 | source: "overflow-menu" | | |||
160 | width: Kirigami.Units.iconSizes.smallMedium | | |||
161 | height: width | | |||
162 | } | | |||
163 | | ||||
164 | //checkable: true | | |||
165 | checked: menu.visible | | |||
166 | visible: hiddenActions.length > 0 || actionsLayout.overflowSet.length > 0; | | |||
167 | onClicked: menu.visible ? menu.close() : menu.open() | | |||
168 | | ||||
169 | ActionsMenu { | | |||
170 | id: menu | | |||
171 | y: root.position == Controls.ToolBar.Footer ? -height : moreButton.height | | |||
172 | x: -width + moreButton.width | | |||
173 | actions: root.actions | | |||
174 | submenuComponent: Component { | | |||
175 | ActionsMenu { | | |||
176 | Binding { | | |||
177 | target: parentItem | | |||
178 | property: "visible" | | |||
179 | value: actionsLayout.findIndex(actionsLayout.overflowSet, function(act) {return act === parentAction}) > -1 && (parentAction.hasOwnProperty("visible") ? parentAction.visible === undefined || parentAction.visible : !parentAction.hasOwnProperty("visible")) | | |||
180 | } | | |||
181 | } | | |||
182 | } | | |||
183 | itemDelegate: ActionMenuItem { | | |||
184 | visible: actionsLayout.findIndex(actionsLayout.overflowSet, function(act) {return act === ourAction}) > -1 && ( ourAction.hasOwnProperty("visible") ? ourAction.visible === undefined || ourAction.visible : !ourAction.hasOwnProperty("visible")) | | |||
185 | } | | |||
186 | Instantiator { | | |||
187 | | ||||
188 | model: root.hiddenActions | | |||
189 | delegate: QtObject { | | |||
190 | readonly property QtObject action: modelData | | |||
191 | property QtObject item: null | | |||
192 | 169 | | |||
193 | Component.onDestruction: if (item) item.destroy() | 170 | visible: hiddenActions.length > 0 || actionsLayout.overflowSet.length > 0 | ||
171 | showMenuArrow: false | ||||
194 | 172 | | |||
195 | function create() { | 173 | kirigamiAction: Kirigami.Action { | ||
196 | if (!action.children || action.children.length === 0) { | 174 | icon.name: "overflow-menu" | ||
197 | item = menu.itemDelegate.createObject(null, { ourAction: action }); | 175 | children: Array.prototype.map.call(root.actions, i => i).concat(Array.prototype.map.call(hiddenActions, i => i)) | ||
198 | menu.addItem(item) | | |||
199 | } else if (menu.submenuComponent) { | | |||
200 | item = menu.submenuComponent.createObject(null, { title: action.text, actions: action.children }); | | |||
201 | menu.addMenu(item) | | |||
202 | } | | |||
203 | //break the binding | | |||
204 | item.visible = true; | | |||
205 | } | | |||
206 | function remove() { | | |||
207 | if (!action.children || action.children.length === 0) { | | |||
208 | menu.removeItem(item) | | |||
209 | } else if (menu.submenuComponent) { | | |||
210 | menu.removeMenu(item) | | |||
211 | } | 176 | } | ||
177 | | ||||
178 | menu.submenuComponent: ActionsMenu { | ||||
179 | Binding { | ||||
180 | target: parentItem | ||||
181 | property: "visible" | ||||
apol: it could be `children: [].concat(root.actions).concat(hiddenActions);` no? | |||||
Ah, I didn't know about concat(). I actually looked for something like that but seem to have missed it. ahiemstra: Ah, I didn't know about `concat()`. I actually looked for something like that but seem to have… | |||||
Of course, things weren't as simple as that since root.actions and hiddenActions are list properties not normal JS arrays. But I found a solution. ahiemstra: Of course, things weren't as simple as that since root.actions and hiddenActions are list… | |||||
182 | value: !actionsLayout.isActionVisible(parentAction) && (parentAction.visible === undefined || parentAction.visible) | ||||
212 | } | 183 | } | ||
213 | } | 184 | } | ||
214 | 185 | | |||
215 | onObjectAdded: object.create() | 186 | menu.itemDelegate: ActionMenuItem { | ||
since it's boolean, you can do: apol: since it's boolean, you can do:
`visible: !actionsLayout.isActionVisible(ourAction) &&… | |||||
216 | onObjectRemoved: object.remove() | 187 | visible: !actionsLayout.isActionVisible(ourAction) && (ourAction.visible === undefined || ourAction.visible) | ||
217 | } | | |||
218 | } | 188 | } | ||
219 | } | 189 | } | ||
220 | } | 190 | } | ||
221 | } | 191 | } |
it could be children: [].concat(root.actions).concat(hiddenActions); no?