2 * Copyright (C) 2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18import Ubuntu.Components 1.1
22 objectName: "dashNavigation"
25 property var scope: null
26 property var scopeStyle: null
27 property color foregroundColor: Theme.palette.normal.baseText
28 property bool isAltNavigation: false
29 property bool showDivider: false
32 readonly property var currentNavigation: scope && scope[hasNavigation] ? getNavigation(scope[currentNavigationId]) : null
33 readonly property alias listView: navigationListView
34 property bool showList: false
37 // Are we drilling down the tree or up?
38 property bool isGoingBack: false
39 readonly property string hasNavigation: isAltNavigation ? "hasAltNavigation" : "hasNavigation"
40 readonly property string currentNavigationId: isAltNavigation ? "currentAltNavigationId" : "currentNavigationId"
41 function getNavigation(navId) {
42 if (isAltNavigation) {
43 return scope.getAltNavigation(navId);
45 return scope.getNavigation(navId);
49 visible: root.currentNavigation != null
52 navigationListView.updateMaxHeight();
53 root.showList = !root.showList;
58 anchors.margins: units.gu(2)
59 verticalAlignment: Text.AlignVCenter
60 text: root.currentNavigation ? root.currentNavigation.label : ""
61 color: root.foregroundColor
65 anchors.verticalCenter: parent.verticalCenter
66 anchors.right: parent.right
67 anchors.rightMargin: units.gu(2)
68 name: showList ? "up" : "down"
71 color: root.foregroundColor
74 // navigationListView is outside root
76 id: navigationListView
77 objectName: "navigationListView"
78 orientation: ListView.Horizontal
80 clip: root.width != windowWidth
84 // navigationId: the navigation id of the navigation the list represents
85 // nullifyNavigation: overrides navigationId to be null
86 // This is used to "clear" the delegate when going "right" on the tree
88 anchors.top: root.bottom
89 property int maxHeight: -1
90 Component.onCompleted: updateMaxHeight();
91 function updateMaxHeight()
93 maxHeight = (windowHeight - mapToItem(null, 0, 0).y) - units.gu(8);
95 property int prevHeight: maxHeight
96 height: currentItem ? currentItem.height : maxHeight
99 prevHeight = currentItem.desiredHeight;
102 highlightMoveDuration: UbuntuAnimation.FastDuration
103 delegate: DashNavigationList {
104 objectName: "navigation" + index
106 width: navigationListView.width
107 scopeStyle: root.scopeStyle
108 foregroundColor: root.foregroundColor
109 property real desiredHeight: {
111 if (navigation && navigation.loaded && x == navigationListView.contentX)
113 navigationListView.updateMaxHeight();
114 return Math.min(implicitHeight, navigationListView.maxHeight);
116 return navigationListView.prevHeight;
122 height: desiredHeight
123 navigation: (nullifyNavigation || !scope) ? null : getNavigation(navigationId)
124 currentNavigation: root.currentNavigation
126 scope.setNavigationState(newNavigationId, isAltNavigation);
127 // We only need to add a new item to the model
128 // if we have children, otherwise just load it
131 navigationModel.append({"navigationId": newNavigationId, "nullifyNavigation": false});
132 navigationListView.currentIndex++;
137 onGoBackToParentClicked: {
138 scope.setNavigationState(navigation.parentNavigationId, isAltNavigation);
140 navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", false);
141 navigationListView.currentIndex--;
143 onAllNavigationClicked: {
145 if (root.currentNavigation.parentNavigationId == navigation.navigationId) {
146 // For leaves we have to go to the parent too
147 scope.setNavigationState(root.currentNavigation.parentNavigationId, isAltNavigation);
152 if (contentX == width * navigationListView.currentIndex) {
154 navigationModel.remove(navigationListView.currentIndex + 1);
156 navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", true);
164 top: navigationListView.bottom
165 left: navigationListView.left
166 right: navigationListView.right
168 fillMode: Image.Stretch
169 source: "graphics/navigation_shadow.png"
170 visible: root.showList
174 navigationModel.clear();
175 if (scope && scope[hasNavigation]) {
176 navigationModel.append({"navigationId": scope[currentNavigationId], "nullifyNavigation": false});
182 // This is duplicated since we can't have something based on the dynamic hasNavigation string property
183 onHasNavigationChanged: {
184 if (!root.isAltNavigation) {
185 if (scope.hasNavigation) {
186 navigationModel.append({"navigationId": scope.currentNavigationId, "nullifyNavigation": false});
188 navigationModel.clear();
192 onHasAltNavigationChanged: {
193 if (root.isAltNavigation) {
194 if (scope.hasAltNavigation) {
195 navigationModel.append({"navigationId": scope.currentAltNavigationId, "nullifyNavigation": false});
197 navigationModel.clear();
204 anchors.fill: navigationListView
205 enabled: root.showList
206 onClicked: root.showList = false
210 visible: root.showDivider
213 bottom: parent.bottom
215 leftMargin: -units.dp(1)
218 color: root.foregroundColor
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