2 * Copyright (C) 2013 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 0.1
22import "../Components/ListItems" as ListItems
28 property SortFilterProxyModel categories: categoryFilter
29 property bool isCurrent
30 property alias moving: categoryView.moving
31 property int tabBarHeight: 0
32 property PageHeader pageHeader: null
33 property OpenEffect openEffect: null
34 property Item previewListView: null
36 signal movementStarted
37 signal positionedAtBeginning
39 property bool enableHeightBehaviorOnNextCreation: false
40 property var categoryView: categoryView
42 // FIXME delay the search so that daemons have time to settle, note that
43 // removing this will break ScopeView::test_changeScope
47 scope.activateApplication.connect(activateApp);
51 function activateApp(appId) {
52 shell.activateApplication(appId);
58 value: isCurrent && !previewListView.onScreen
64 onTriggered: scope.searchQuery = ""
67 SortFilterProxyModel {
69 model: scope ? scope.categories : null
70 dynamicSortFilter: true
71 filterRole: Categories.RoleCount
77 pageHeader.resetSearch();
78 previewListView.open = false;
81 onMovementStarted: categoryView.showHeader()
83 onPositionedAtBeginning: categoryView.positionAtBeginning()
86 target: scopeView.scope
87 property: "searchQuery"
88 value: pageHeader.searchQuery
94 property: "searchQuery"
95 value: scopeView.scope.searchQuery
101 onSearchClicked: if (isCurrent) {
102 pageHeader.triggerSearch()
103 categoryView.showHeader()
108 target: scopeView.scope
109 onShowDash: previewListView.open = false;
110 onHideDash: previewListView.open = false;
115 objectName: "categoryListView"
117 model: scopeView.categories
118 forceNoClip: previewListView.onScreen
120 property string expandedCategoryId: ""
121 signal correctExpandedCategory();
123 onContentYChanged: pageHeader.positionRealHeader();
124 onOriginYChanged: pageHeader.positionRealHeader();
125 onContentHeightChanged: pageHeader.positionRealHeader();
127 Behavior on contentY {
128 enabled: previewListView.open
129 UbuntuNumberAnimation {}
132 delegate: ListItems.Base {
134 objectName: "dashCategory" + category
135 highlightWhenPressed: false
137 readonly property bool expandable: rendererLoader.item ? rendererLoader.item.expandable : false
138 readonly property bool filtered: rendererLoader.item ? rendererLoader.item.filter : true
139 readonly property string category: categoryId
140 readonly property var item: rendererLoader.item
150 source: getRenderer(model.renderer, model.contentType, model.rendererHint, results)
153 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
154 item.enableHeightBehavior = scopeView.enableHeightBehaviorOnNextCreation;
155 scopeView.enableHeightBehaviorOnNextCreation = false;
157 if (source.toString().indexOf("Apps/RunningApplicationsGrid.qml") != -1) {
158 // TODO: the running apps grid doesn't support standard scope results model yet
159 item.model = Qt.binding(function() { return results.model })
160 item.canEnableTerminationMode = Qt.binding(function() { return scopeView.isCurrent })
162 item.model = Qt.binding(function() { return results })
164 item.objectName = Qt.binding(function() { return categoryId })
165 if (item.expandable) {
166 var shouldFilter = categoryId != categoryView.expandedCategoryId;
167 if (shouldFilter != item.filter) {
168 item.filter = shouldFilter;
171 updateDelegateCreationRange();
174 Component.onDestruction: {
175 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
176 scopeView.enableHeightBehaviorOnNextCreation = item.enableHeightBehaviorOnNextCreation;
181 target: rendererLoader.item
183 // Prepare the preview in case activate() triggers a preview only
184 openEffect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
185 previewListView.categoryId = categoryId
186 previewListView.categoryDelegate = rendererLoader.item
187 previewListView.model = target.model;
188 previewListView.init = true;
189 previewListView.currentIndex = index;
191 var item = target.model.get(index);
193 if ((scopeView.scope.id == "applications.scope" && categoryId == "installed")
194 || (scopeView.scope.id == "home.scope" && categoryId == "applications.scope")) {
195 scopeView.scope.activate(item.uri, item.icon, item.category, 0, item.mimetype, item.title,
196 item.comment, item.dndUri, item.metadata)
198 previewListView.open = true
200 scopeView.scope.preview(item.uri, item.icon, item.category, 0, item.mimetype, item.title,
201 item.comment, item.dndUri, item.metadata)
205 openEffect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
206 previewListView.categoryId = categoryId
207 previewListView.categoryDelegate = rendererLoader.item
208 previewListView.model = target.model;
209 previewListView.init = true;
210 previewListView.currentIndex = index;
211 previewListView.open = true
213 var item = target.model.get(index)
214 scopeView.scope.preview(item.uri, item.icon, item.category, 0, item.mimetype, item.title,
215 item.comment, item.dndUri, item.metadata)
220 onExpandedCategoryIdChanged: {
221 collapseAllButExpandedCategory();
223 onCorrectExpandedCategory: {
224 collapseAllButExpandedCategory();
226 function collapseAllButExpandedCategory() {
227 var item = rendererLoader.item;
228 if (item.expandable) {
229 var shouldFilter = categoryId != categoryView.expandedCategoryId;
230 if (shouldFilter != item.filter) {
231 // If the filter animation will be seen start it, otherwise, just flip the switch
232 var shrinkingVisible = shouldFilter && y + item.collapsedHeight < categoryView.height;
233 var growingVisible = !shouldFilter && y + height < categoryView.height;
234 if (!previewListView.open || !shouldFilter) {
235 if (shrinkingVisible || growingVisible) {
236 item.startFilterAnimation(shouldFilter)
238 item.filter = shouldFilter;
240 if (!shouldFilter && !previewListView.open) {
241 categoryView.maximizeVisibleArea(index, item.uncollapsedHeight);
247 onOriginYChanged: rendererLoader.updateDelegateCreationRange();
248 onContentYChanged: rendererLoader.updateDelegateCreationRange();
249 onHeightChanged: rendererLoader.updateDelegateCreationRange();
250 onContentHeightChanged: rendererLoader.updateDelegateCreationRange();
253 function updateDelegateCreationRange() {
254 // Do not update the range if we are overshooting up or down, since we'll come back
255 // to the stable position and delete/create items without any reason
256 if (categoryView.contentY < categoryView.originY) {
258 } else if (categoryView.contentY + categoryView.height > categoryView.contentHeight) {
262 if (item && item.hasOwnProperty("delegateCreationBegin")) {
263 if (baseItem.y + baseItem.height <= 0) {
264 // Not visible (item at top of the list)
265 item.delegateCreationBegin = baseItem.height
266 item.delegateCreationEnd = baseItem.height
267 } else if (baseItem.y >= categoryView.height) {
268 // Not visible (item at bottom of the list)
269 item.delegateCreationBegin = 0
270 item.delegateCreationEnd = 0
272 item.delegateCreationBegin = Math.max(-baseItem.y, 0)
273 item.delegateCreationEnd = Math.min(categoryView.height + item.delegateCreationBegin, baseItem.height)
279 onHeightChanged: rendererLoader.updateDelegateCreationRange();
280 onYChanged: rendererLoader.updateDelegateCreationRange();
283 sectionProperty: "name"
284 sectionDelegate: ListItems.Header {
285 objectName: "dashSectionHeader" + (delegate ? delegate.category : "")
286 property var delegate: categoryView.item(delegateIndex)
287 width: categoryView.width
290 if (delegate && delegate.expandable)
291 return delegate.filtered ? "graphics/header_handlearrow.png" : "graphics/header_handlearrow2.png"
295 if (categoryView.expandedCategoryId != delegate.category)
296 categoryView.expandedCategoryId = delegate.category;
298 categoryView.expandedCategoryId = "";
302 implicitHeight: scopeView.tabBarHeight
304 if (scopeView.pageHeader) {
305 scopeView.pageHeader.height = height;
308 onYChanged: positionRealHeader();
310 function positionRealHeader() {
311 if (scopeView.pageHeader) {
312 scopeView.pageHeader.y = y + parent.y;
318 function getDefaultRendererId(contentType) {
319 switch (contentType) {
320 default: return "grid";
324 function getRenderer(rendererId, contentType, rendererHint, results) {
325 if (rendererId == "default") {
326 rendererId = getDefaultRendererId(contentType);
328 if (rendererId == "carousel") {
329 // Selectively disable carousel, 6 is fixed for now, should change on the form factor
330 if (results.count <= 6)
333 switch (rendererId) {
335 switch (contentType) {
336 case "music": return "Music/MusicCarousel.qml";
337 case "video": return "Video/VideoCarousel.qml";
338 default: return "Generic/GenericCarousel.qml";
342 switch (contentType) {
344 if (rendererHint == "toggled")
345 return "Apps/DashPluginFilterGrid.qml";
347 return "Generic/GenericFilterGrid.qml";
349 case "music": return "Music/MusicFilterGrid.qml";
350 case "video": return "Video/VideoFilterGrid.qml";
351 case "weather": return "Generic/WeatherFilterGrid.qml";
352 default: return "Generic/GenericFilterGrid.qml";
356 switch (contentType) {
357 case "apps": return "Apps/RunningApplicationsGrid.qml";
358 default: return "Generic/GenericFilterGrid.qml";
361 default: return "Generic/GenericFilterGrid.qml";
366 target: scopeView.scope
368 if (previewListView.init) {
369 // Preview was triggered because of a click on the item. Need to expand now.
370 if (!previewListView.open) {
371 previewListView.open = true
374 var index = previewListView.currentIndex
375 previewListView.currentIndex = -1
376 previewListView.currentIndex = index
377 previewListView.init = false
379 previewListView.currentItem.previewData = preview
383 // TODO: Move as InverseMouseArea to DashPreview
385 objectName: "closePreviewMouseArea"
386 enabled: previewListView.onScreen
389 topMargin: openEffect.bottomGapPx
392 previewListView.open = false;
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