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
27 property Scope scope: null
28 property SortFilterProxyModel categories: categoryFilter
29 property bool isCurrent: false
30 property alias moving: categoryView.moving
31 property int tabBarHeight: 0
32 property PageHeader pageHeader: null
33 property Item previewListView: null
35 signal movementStarted
36 signal positionedAtBeginning
38 property bool enableHeightBehaviorOnNextCreation: false
39 property var categoryView: categoryView
41 // FIXME delay the search so that daemons have time to settle, note that
42 // removing this will break ScopeView::test_changeScope
46 scope.activateApplication.connect(activateApp);
50 function activateApp(appId) {
51 shell.activateApplication(appId);
57 value: isCurrent && !previewListView.open
63 onTriggered: scope.searchQuery = ""
66 SortFilterProxyModel {
68 model: scope ? scope.categories : null
69 dynamicSortFilter: true
70 filterRole: Categories.RoleCount
76 pageHeader.resetSearch();
77 previewListView.open = false;
80 onMovementStarted: categoryView.showHeader()
82 onPositionedAtBeginning: categoryView.positionAtBeginning()
85 target: scopeView.scope
86 property: "searchQuery"
87 value: pageHeader.searchQuery
93 property: "searchQuery"
94 value: scopeView.scope ? scopeView.scope.searchQuery : ""
100 onSearchClicked: if (isCurrent) {
101 pageHeader.triggerSearch()
102 categoryView.showHeader()
107 target: scopeView.scope
108 onShowDash: previewListView.open = false;
109 onHideDash: previewListView.open = false;
114 objectName: "categoryListView"
116 model: scopeView.categories
117 forceNoClip: previewListView.open
119 property string expandedCategoryId: ""
121 onContentYChanged: pageHeader.positionRealHeader();
122 onOriginYChanged: pageHeader.positionRealHeader();
123 onContentHeightChanged: pageHeader.positionRealHeader();
125 delegate: ListItems.Base {
127 objectName: "dashCategory" + category
128 highlightWhenPressed: false
131 readonly property bool expandable: rendererLoader.item ? rendererLoader.item.expandable : false
132 readonly property bool filtered: rendererLoader.item ? rendererLoader.item.filter : true
133 readonly property string category: categoryId
134 readonly property var item: rendererLoader.item
144 source: getRenderer(model.renderer, results)
147 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
148 item.enableHeightBehavior = scopeView.enableHeightBehaviorOnNextCreation;
149 scopeView.enableHeightBehaviorOnNextCreation = false;
151 if (source.toString().indexOf("Apps/RunningApplicationsGrid.qml") != -1) {
152 // TODO: this is still a kludge :D Ideally add some kind of hook so that we
153 // can do this from DashApps.qml or think a better way that needs no special casing
154 item.firstModel = Qt.binding(function() { return mainStageApplicationsModel })
155 item.secondModel = Qt.binding(function() { return sideStageApplicationModel })
156 item.canEnableTerminationMode = Qt.binding(function() { return scopeView.isCurrent })
158 item.model = Qt.binding(function() { return results })
160 item.objectName = Qt.binding(function() { return categoryId })
161 if (item.expandable) {
162 var shouldFilter = categoryId != categoryView.expandedCategoryId;
163 if (shouldFilter != item.filter) {
164 item.filter = shouldFilter;
167 updateDelegateCreationRange();
168 // FIXME: should be "template", not "renderer"
169 item.template = Qt.binding(function() { return model.renderer });
170 item.components = Qt.binding(function() { return model.components });
173 Component.onDestruction: {
174 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
175 scopeView.enableHeightBehaviorOnNextCreation = item.enableHeightBehaviorOnNextCreation;
180 target: rendererLoader.item
182 if (scopeView.scope.id === "scopes" || (scopeView.scope.id == "clickscope" && categoryId == "local")) {
183 // TODO Technically it is possible that calling activate() will make the scope emit
184 // previewRequested so that we show a preview but there's no scope that does that yet
185 // so it's not implemented
186 var item = target.model.get(index);
187 scopeView.scope.activate(item.result)
189 previewListView.model = target.model;
190 previewListView.currentIndex = -1
191 previewListView.currentIndex = index;
192 previewListView.open = true
196 previewListView.model = target.model;
197 previewListView.currentIndex = -1
198 previewListView.currentIndex = index;
199 previewListView.open = true
204 onExpandedCategoryIdChanged: {
205 collapseAllButExpandedCategory();
207 function collapseAllButExpandedCategory() {
208 var item = rendererLoader.item;
209 if (item.expandable) {
210 var shouldFilter = categoryId != categoryView.expandedCategoryId;
211 if (shouldFilter != item.filter) {
212 // If the filter animation will be seen start it, otherwise, just flip the switch
213 var shrinkingVisible = shouldFilter && y + item.collapsedHeight < categoryView.height;
214 var growingVisible = !shouldFilter && y + height < categoryView.height;
215 if (!previewListView.open || !shouldFilter) {
216 if (shrinkingVisible || growingVisible) {
217 item.startFilterAnimation(shouldFilter)
219 item.filter = shouldFilter;
221 if (!shouldFilter && !previewListView.open) {
222 categoryView.maximizeVisibleArea(index, item.uncollapsedHeight);
228 onOriginYChanged: rendererLoader.updateDelegateCreationRange();
229 onContentYChanged: rendererLoader.updateDelegateCreationRange();
230 onHeightChanged: rendererLoader.updateDelegateCreationRange();
231 onContentHeightChanged: rendererLoader.updateDelegateCreationRange();
234 function updateDelegateCreationRange() {
235 // Do not update the range if we are overshooting up or down, since we'll come back
236 // to the stable position and delete/create items without any reason
237 if (categoryView.contentY < categoryView.originY) {
239 } else if (categoryView.contentY + categoryView.height > categoryView.contentHeight) {
243 if (item && item.hasOwnProperty("delegateCreationBegin")) {
244 if (baseItem.y + baseItem.height <= 0) {
245 // Not visible (item at top of the list)
246 item.delegateCreationBegin = baseItem.height
247 item.delegateCreationEnd = baseItem.height
248 } else if (baseItem.y >= categoryView.height) {
249 // Not visible (item at bottom of the list)
250 item.delegateCreationBegin = 0
251 item.delegateCreationEnd = 0
253 item.delegateCreationBegin = Math.max(-baseItem.y, 0)
254 item.delegateCreationEnd = Math.min(categoryView.height + item.delegateCreationBegin, baseItem.height)
266 fillMode: Image.Stretch
267 source: "graphics/dash_divider_top_lightgrad.png"
272 // FIXME Should not rely on count field of model, SortfilterProxyModel in this case.
273 visible: index != categoryView.model.count - 1
275 bottom: parent.bottom
279 fillMode: Image.Stretch
280 source: "graphics/dash_divider_top_darkgrad.png"
285 onHeightChanged: rendererLoader.updateDelegateCreationRange();
286 onYChanged: rendererLoader.updateDelegateCreationRange();
289 sectionProperty: "name"
290 sectionDelegate: ListItems.Header {
291 objectName: "dashSectionHeader" + (delegate ? delegate.category : "")
292 property var delegate: categoryView.item(delegateIndex)
293 width: categoryView.width
296 if (delegate && delegate.expandable)
297 return delegate.filtered ? "graphics/header_handlearrow.png" : "graphics/header_handlearrow2.png"
301 if (categoryView.expandedCategoryId != delegate.category)
302 categoryView.expandedCategoryId = delegate.category;
304 categoryView.expandedCategoryId = "";
308 implicitHeight: scopeView.tabBarHeight
310 if (scopeView.pageHeader && scopeView.isCurrent) {
311 scopeView.pageHeader.height = height;
314 onYChanged: positionRealHeader();
316 function positionRealHeader() {
317 if (scopeView.pageHeader && scopeView.isCurrent) {
318 scopeView.pageHeader.y = y + parent.y;
324 function getRenderer(template, results) {
325 var layout = template["category-layout"];
327 if (layout == "running-apps") {
328 return "Apps/RunningApplicationsGrid.qml";
331 if (layout === "carousel") {
332 // TODO: Selectively disable carousel, 4 is fixed for now, should change depending on form factor
333 if (results.count <= 4) layout = "grid";
336 case "carousel": return "CardCarousel.qml";
338 default: return "CardFilterGrid.qml";
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