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 { | 169 | | ||
158 | anchors.centerIn: parent | 170 | visible: hiddenActions.length > 0 || actionsLayout.overflowSet.length > 0 | ||
159 | source: "overflow-menu" | 171 | showMenuArrow: false | ||
160 | width: Kirigami.Units.iconSizes.smallMedium | 172 | | ||
161 | height: width | 173 | kirigamiAction: Kirigami.Action { | ||
162 | } | 174 | icon.name: "overflow-menu" | ||
163 | 175 | children: { | |||
164 | //checkable: true | 176 | var result = [] | ||
165 | checked: menu.visible | 177 | for (var i in root.actions) { | ||
166 | visible: hiddenActions.length > 0 || actionsLayout.overflowSet.length > 0; | 178 | result.push(root.actions[i]) | ||
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 | } | 179 | } | ||
180 | for (var i in hiddenActions) { | ||||
181 | result.push(hiddenActions[i]) | ||||
181 | } | 182 | } | ||
183 | return result; | ||||
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 | } | 184 | } | ||
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 | } | 185 | } | ||
186 | Instantiator { | | |||
187 | | ||||
188 | model: root.hiddenActions | | |||
189 | delegate: QtObject { | | |||
190 | readonly property QtObject action: modelData | | |||
191 | property QtObject item: null | | |||
192 | 186 | | |||
193 | Component.onDestruction: if (item) item.destroy() | 187 | menu.submenuComponent: ActionsMenu { | ||
194 | 188 | Binding { | |||
195 | function create() { | 189 | target: parentItem | ||
196 | if (!action.children || action.children.length === 0) { | 190 | property: "visible" | ||
197 | item = menu.itemDelegate.createObject(null, { ourAction: action }); | 191 | value: { | ||
198 | menu.addItem(item) | 192 | if (actionsLayout.isActionVisible(parentAction)) { | ||
199 | } else if (menu.submenuComponent) { | 193 | return false | ||
200 | item = menu.submenuComponent.createObject(null, { title: action.text, actions: action.children }); | | |||
201 | menu.addMenu(item) | | |||
202 | } | 194 | } | ||
203 | //break the binding | 195 | | ||
204 | item.visible = true; | 196 | return parentAction.hasOwnProperty("visible") ? parentAction.visible === undefined || parentAction.visible : true | ||
205 | } | 197 | } | ||
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 | } | 198 | } | ||
212 | } | 199 | } | ||
200 | | ||||
201 | menu.itemDelegate: ActionMenuItem { | ||||
202 | visible: { | ||||
203 | if (actionsLayout.isActionVisible(ourAction)) { | ||||
204 | return false | ||||
213 | } | 205 | } | ||
214 | 206 | | |||
215 | onObjectAdded: object.create() | 207 | return ourAction.hasOwnProperty("visible") ? ourAction.visible === undefined || ourAction.visible : true | ||
since it's boolean, you can do: apol: since it's boolean, you can do:
`visible: !actionsLayout.isActionVisible(ourAction) &&… | |||||
216 | onObjectRemoved: object.remove() | | |||
217 | } | 208 | } | ||
218 | } | 209 | } | ||
219 | } | 210 | } | ||
220 | } | 211 | } | ||
221 | } | 212 | } |
it could be children: [].concat(root.actions).concat(hiddenActions); no?