2 * Copyright 2016 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18import QtQuick.Layouts 1.1
20import Ubuntu.Components 1.3
21import GlobalShortcut 1.0
27 property alias unityMenuModel: rowRepeater.model
29 readonly property bool valid: rowRepeater.count > 0
31 property bool enableKeyFilter: false
33 readonly property bool showRequested: d.longAltPressed || d.currentItem != null
35 implicitWidth: row.width
38 function select(index) {
47 shortcut: Qt.Key_Alt|Qt.AltModifier
48 active: enableKeyFilter
49 onTriggered: d.startShortcutTimer()
50 onReleased: d.stopSHortcutTimer()
52 // On an actual keyboard, the AltModifier is not supplied on release.
55 active: enableKeyFilter
56 onTriggered: d.startShortcutTimer()
57 onReleased: d.stopSHortcutTimer()
61 shortcut: Qt.AltModifier | Qt.Key_F10
62 active: enableKeyFilter && d.currentItem == null
64 for (var i = 0; i < rowRepeater.count; i++) {
65 var item = rowRepeater.itemAt(i);
75 acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
77 enabled: d.currentItem != null
78 onPressed: d.dismissAll()
95 objectName: "barContext"
96 active: !d.currentItem && enableKeyFilter
104 objectName: root.objectName + "-item" + __ownIndex
106 readonly property int __ownIndex: index
107 property Item __popup: null;
108 property bool popupVisible: __popup && __popup.visible
110 implicitWidth: column.implicitWidth
111 implicitHeight: row.height
112 enabled: model.sensitive
116 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
117 // force the current item to be the newly popped up menu
121 d.currentItem = visualItem;
127 if (d.currentItem === visualItem) {
128 d.currentItem = null;
137 if (d.currentItem === visualItem) {
138 d.currentItem = null;
145 onDismissAll: visualItem.dismiss()
151 x: visualItem.x - units.gu(1)
152 anchors.top: parent.bottom
153 unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
155 Component.onCompleted: reset();
167 Layout.preferredWidth: units.gu(2)
168 Layout.preferredHeight: units.gu(2)
169 Layout.alignment: Qt.AlignVCenter
171 visible: model.icon || false
172 source: model.icon || ""
178 height: _title.height
181 // FIXME - SDK Action:text modifies menu text with html underline for mnemonic
182 text: model.label.replace("_", "&").replace("<u>", "&").replace("</u>", "")
191 text: actionItem.text
192 horizontalAlignment: Text.AlignLeft
193 color: enabled ? "white" : "#5d5d5d"
197 } // Item ( delegate )
203 hoverEnabled: d.currentItem
207 updateCurrentItemFromPosition(Qt.point(mouseX, mouseY))
212 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
215 onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
217 function updateCurrentItemFromPosition(point) {
218 var pos = mapToItem(row, point.x, point.y);
220 if (!d.hoveredItem || !d.currentItem || !d.hoveredItem.contains(Qt.point(pos.x - d.currentItem.x, pos.y - d.currentItem.y))) {
221 d.hoveredItem = row.childAt(pos.x, pos.y);
222 if (!d.hoveredItem || !d.hoveredItem.enabled)
224 if (d.currentItem != d.hoveredItem) {
225 d.currentItem = d.hoveredItem;
237 x: d.currentItem ? row.x + d.currentItem.x - units.gu(1) : 0
238 width: d.currentItem ? d.currentItem.width + units.gu(2) : 0
240 color: UbuntuColors.orange
241 visible: d.currentItem
248 itemView: rowRepeater
250 property Item currentItem: null
251 property Item hoveredItem: null
252 property Item prevCurrentItem: null
254 readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -1
256 property bool altPressed: false
257 property bool longAltPressed: false
262 var delegate = rowRepeater.itemAt(index);
264 d.currentItem = delegate;
268 onCurrentItemChanged: {
269 if (prevCurrentItem && prevCurrentItem != currentItem) {
271 prevCurrentItem.hide();
273 prevCurrentItem.dismiss();
277 if (currentItem) currentItem.show();
278 prevCurrentItem = currentItem;
281 function startShortcutTimer() {
283 menuBarShortcutTimer.start();
286 function stopSHortcutTimer() {
287 menuBarShortcutTimer.stop();
288 d.altPressed = false;
289 d.longAltPressed = false;
294 id: menuBarShortcutTimer
298 d.longAltPressed = true;
302 Keys.onEscapePressed: {
304 event.accepted = true;
307 Keys.onLeftPressed: {
309 d.selectPrevious(d.currentIndex);
313 Keys.onRightPressed: {
315 d.selectNext(d.currentIndex);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list