@@ -16,15 +16,60 @@
1616
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
19+import Utils 0.1
20+import Unity 0.1
1921import "../Components"
2022import "../Components/ListItems" as ListItems
2123
22−ScopeView {
24+FocusScope {
2325 id: scopeView
26+
27+ property Scope scope
28+ property SortFilterProxyModel categories: categoryFilter
29+ property bool isCurrent
30+ property ListModel searchHistory
31+ property alias moving: categoryView.moving
32+
33+ signal endReached
34+ signal movementStarted
35+ signal positionedAtBeginning
36+
2437 readonly property alias previewShown: previewListView.onScreen
2538 property bool enableHeightBehaviorOnNextCreation: false
2639
27− moving: categoryView.moving
40+ // FIXME delay the search so that daemons have time to settle, note that
41+ // removing this will break ScopeView::test_changeScope
42+ onScopeChanged: {
43+ if (scope) {
44+ timer.restart();
45+ scope.activateApplication.connect(activateApp);
46+ }
47+ }
48+
49+ function activateApp(desktopFilePath) {
50+ shell.activateApplication(desktopFilePath);
51+ }
52+
53+ Binding {
54+ target: scope
55+ property: "isActive"
56+ value: isCurrent
57+ }
58+
59+ Timer {
60+ id: timer
61+ interval: 2000
62+ onTriggered: scope.searchQuery = ""
63+ }
64+
65+ SortFilterProxyModel {
66+ id: categoryFilter
67+ model: scope ? scope.categories : null
68+ dynamicSortFilter: true
69+ filterRole: Categories.RoleCount
70+ filterRegExp: /^0$/
71+ invertMatch: true
72+ }
2873
2974 onIsCurrentChanged: {
3075 pageHeader.resetSearch();
@@ -130,14 +175,14 @@ ScopeView {
130175 target: rendererLoader.item
131176 onClicked: {
132177 // Prepare the preview in case activate() triggers a preview only
133− effect.positionPx = mapToItem(categoryView, 0, itemY).y
178+ effect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
134179 previewListView.categoryId = categoryId
135180 previewListView.categoryDelegate = rendererLoader.item
136− previewListView.model = model;
181+ previewListView.model = target.model;
137182 previewListView.init = true;
138183 previewListView.currentIndex = index;
139184
140− var item = model.get(index);
185+ var item = target.model.get(index);
141186
142187 if ((scopeView.scope.id == "applications.scope" && categoryId == "installed")
143188 || (scopeView.scope.id == "home.scope" && categoryId == "applications.scope")) {
@@ -151,15 +196,15 @@ ScopeView {
151196 }
152197 }
153198 onPressAndHold: {
154− effect.positionPx = mapToItem(categoryView, 0, itemY).y
199+ effect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
155200 previewListView.categoryId = categoryId
156201 previewListView.categoryDelegate = rendererLoader.item
157− previewListView.model = model;
202+ previewListView.model = target.model;
158203 previewListView.init = true;
159204 previewListView.currentIndex = index;
160205 previewListView.open = true
161206
162− var item = model.get(index)
207+ var item = target.model.get(index)
163208 scopeView.scope.preview( item.uri, item.icon, item.category, 0, item.mimetype, item.title,
164209 item.comment, item.dndUri, item.metadata)
165210 }
@@ -393,12 +438,19 @@ ScopeView {
393438
394439 if (!init && model !== undefined) {
395440 var item = model.get(currentIndex)
396− scopeView.scope.preview( item.uri, item.icon, item.category, 0, item.mimetype, item.title, item.comment, item.dndUri, item.metadata)
441+ scopeView.scope.preview(item.uri, item.icon, item.category, 0, item.mimetype, item.title, item.comment, item.dndUri, item.metadata)
397442 }
398443
399444 var itemY = categoryView.contentItem.mapFromItem(categoryDelegate.currentItem).y;
445+
446+ // Find new contentY and effect.postionPx
400447 var newContentY = itemY - effect.positionPx - categoryDelegate.verticalSpacing;
401− var effectAdjust = effect.positionPx;
448+
449+ // Make sure the item is not covered by a header. Move the effect split down if necessary
450+ var headerHeight = pageHeader.height + categoryView.stickyHeaderHeight;
451+ var effectAdjust = Math.max(effect.positionPx, headerHeight);
452+
453+ // Make sure we don't overscroll the listview. If yes, adjust effect position
402454 if (newContentY < 0) {
403455 effectAdjust += newContentY;
404456 newContentY = 0;
@@ -409,7 +461,7 @@ ScopeView {
409461 }
410462
411463 effect.positionPx = effectAdjust;
412− categoryView.contentY = newContentY - categoryView.originY;
464+ categoryView.contentY = newContentY;
413465 }
414466
415467 property bool open: false