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 acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
63 enabled: d.currentItem != null
64 onPressed: d.dismissAll()
81 objectName: "barContext"
82 active: !d.currentItem && enableKeyFilter
90 objectName: root.objectName + "-item" + __ownIndex
92 readonly property int __ownIndex: index
93 property Item __popup: null;
94 property bool popupVisible: __popup && __popup.visible
96 implicitWidth: column.implicitWidth
97 implicitHeight: row.height
98 enabled: model.sensitive
102 __popup = menuComponent.createObject(root, { objectName: visualItem.objectName + "-menu" });
103 // force the current item to be the newly popped up menu
107 d.currentItem = visualItem;
113 if (d.currentItem === visualItem) {
114 d.currentItem = null;
123 if (d.currentItem === visualItem) {
124 d.currentItem = null;
131 onDismissAll: visualItem.dismiss()
137 x: visualItem.x - units.gu(1)
138 anchors.top: parent.bottom
139 unityMenuModel: root.unityMenuModel.submenu(visualItem.__ownIndex)
141 Component.onCompleted: reset();
153 Layout.preferredWidth: units.gu(2)
154 Layout.preferredHeight: units.gu(2)
155 Layout.alignment: Qt.AlignVCenter
157 visible: model.icon || false
158 source: model.icon || ""
164 height: _title.height
167 // FIXME - SDK Action:text modifies menu text with html underline for mnemonic
168 text: model.label.replace("_", "&").replace("<u>", "&").replace("</u>", "")
177 text: actionItem.text
178 horizontalAlignment: Text.AlignLeft
179 color: enabled ? "white" : "#5d5d5d"
183 } // Item ( delegate )
189 hoverEnabled: d.currentItem
193 updateCurrentItemFromPosition(Qt.point(mouseX, mouseY))
198 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
201 onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
203 function updateCurrentItemFromPosition(point) {
204 var pos = mapToItem(row, point.x, point.y);
206 if (!d.hoveredItem || !d.currentItem || !d.hoveredItem.contains(Qt.point(pos.x - d.currentItem.x, pos.y - d.currentItem.y))) {
207 d.hoveredItem = row.childAt(pos.x, pos.y);
208 if (!d.hoveredItem || !d.hoveredItem.enabled)
210 if (d.currentItem != d.hoveredItem) {
211 d.currentItem = d.hoveredItem;
223 x: d.currentItem ? row.x + d.currentItem.x - units.gu(1) : 0
224 width: d.currentItem ? d.currentItem.width + units.gu(2) : 0
226 color: UbuntuColors.orange
227 visible: d.currentItem
234 itemView: rowRepeater
236 property Item currentItem: null
237 property Item hoveredItem: null
238 property Item prevCurrentItem: null
240 readonly property int currentIndex: currentItem ? currentItem.__ownIndex : -1
242 property bool altPressed: false
243 property bool longAltPressed: false
248 var delegate = rowRepeater.itemAt(index);
250 d.currentItem = delegate;
254 onCurrentItemChanged: {
255 if (prevCurrentItem && prevCurrentItem != currentItem) {
257 prevCurrentItem.hide();
259 prevCurrentItem.dismiss();
263 if (currentItem) currentItem.show();
264 prevCurrentItem = currentItem;
267 function startShortcutTimer() {
269 menuBarShortcutTimer.start();
272 function stopSHortcutTimer() {
273 menuBarShortcutTimer.stop();
274 d.altPressed = false;
275 d.longAltPressed = false;
280 id: menuBarShortcutTimer
284 d.longAltPressed = true;
288 Keys.onEscapePressed: {
290 event.accepted = true;
293 Keys.onLeftPressed: {
295 d.selectPrevious(d.currentIndex);
299 Keys.onRightPressed: {
301 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