on xenial help sign in
Convert the overrides to functions as Nick suggested
f9ea873Albert Astals
qml/Dash/GenericScopeView.qml+34−29
@@ -34,8 +34,6 @@ FocusScope {
34 property bool enableHeightBehaviorOnNextCreation: false
34 property bool enableHeightBehaviorOnNextCreation: false
35 property var categoryView: categoryView
35 property var categoryView: categoryView
36 property bool showPageHeader: true
36 property bool showPageHeader: true
37− property var clickOverride: null
38− property var pressAndHoldOverride: null
39 readonly property alias previewShown: previewListView.open
37 readonly property alias previewShown: previewListView.open
40
38
41 property var scopeStyle: ScopeStyle {
39 property var scopeStyle: ScopeStyle {
@@ -66,6 +64,34 @@ FocusScope {
66 previewListView.open = false;
64 previewListView.open = false;
67 }
65 }
68
66
67+ function itemClicked(index, result, item, itemModel, resultsModel, limitedCategoryItemCount) {
68+ if (scope.id === "scopes" || scope.id == "clickscope") {
69+ // TODO Technically it is possible that calling activate() will make the scope emit
70+ // previewRequested so that we show a preview but there's no scope that does that yet
71+ // so it's not implemented
72+ scope.activate(result)
73+ } else {
74+ openPreview(index, resultsModel, limitedCategoryItemCount);
75+ }
76+ }
77+
78+ function itemPressedAndHeld(index, resultsModel, limitedCategoryItemCount) {
79+ openPreview(index, resultsModel, limitedCategoryItemCount);
80+ }
81+
82+ function openPreview(index, resultsModel, limitedCategoryItemCount) {
83+ if (limitedCategoryItemCount > 0) {
84+ previewLimitModel.model = resultsModel;
85+ previewLimitModel.limit = limitedCategoryItemCount;
86+ previewListView.model = previewLimitModel;
87+ } else {
88+ previewListView.model = resultsModel;
89+ }
90+ previewListView.currentIndex = -1;
91+ previewListView.currentIndex = index;
92+ previewListView.open = true;
93+ }
94+
69 Binding {
95 Binding {
70 target: scope
96 target: scope
71 property: "isActive"
97 property: "isActive"
@@ -238,40 +264,19 @@ FocusScope {
238 Connections {
264 Connections {
239 target: rendererLoader.item
265 target: rendererLoader.item
240 onClicked: {
266 onClicked: {
241− if (scopeView.clickOverride) {
242− scopeView.clickOverride(index, result, item, itemModel);
267+ scopeView.itemClicked(index, result, item, itemModel, target.model, categoryItemCount());
243− return;
244− }
245−
246− if (scopeView.scope.id === "scopes" || scopeView.scope.id == "clickscope") {
247− // TODO Technically it is possible that calling activate() will make the scope emit
248− // previewRequested so that we show a preview but there's no scope that does that yet
249− // so it's not implemented
250− scopeView.scope.activate(result)
251− } else {
252− openPreview(index);
253− }
254 }
268 }
255
269
256 onPressAndHold: {
270 onPressAndHold: {
257− if (scopeView.pressAndHoldOverride) {
271+ scopeView.itemPressedAndHeld(index, target.model, categoryItemCount());
258− scopeView.pressAndHoldOverride(index);
259− } else {
260− openPreview(index);
261− }
262 }
272 }
263
273
264− function openPreview(index) {
274+ function categoryItemCount() {
275+ var categoryItemCount = -1;
265 if (!rendererLoader.expanded && !seeAllLabel.visible && target.collapsedItemCount > 0) {
276 if (!rendererLoader.expanded && !seeAllLabel.visible && target.collapsedItemCount > 0) {
266− previewLimitModel.model = target.model;
267− previewLimitModel.limit = target.collapsedItemCount;
277+ categoryItemCount = target.collapsedItemCount;
268− previewListView.model = previewLimitModel;
269− } else {
270− previewListView.model = target.model;
271 }
278 }
272− previewListView.currentIndex = -1;
279+ return categoryItemCount;
273− previewListView.currentIndex = index;
274− previewListView.open = true;
275 }
280 }
276 }
281 }
277 Connections {
282 Connections {
qml/Dash/ScopesOverview.qml+2−2
@@ -336,7 +336,7 @@ Item {
336 opacity: searchResultsViewer.scope ? 1 : 0
336 opacity: searchResultsViewer.scope ? 1 : 0
337 Behavior on opacity { UbuntuNumberAnimation { } }
337 Behavior on opacity { UbuntuNumberAnimation { } }
338
338
339− clickOverride: function (index, result, item, itemModel) {
339+ function itemClicked(index, result, item, itemModel, resultsModel, limitedCategoryItemCount) {
340 pageHeader.closePopup();
340 pageHeader.closePopup();
341 if (itemModel.scopeId) {
341 if (itemModel.scopeId) {
342 // This can end up in openScope so save restorePosition and restoreSize
342 // This can end up in openScope so save restorePosition and restoreSize
@@ -349,7 +349,7 @@ Item {
349 }
349 }
350 }
350 }
351
351
352− pressAndHoldOverride: function (index) {
352+ function itemPressedAndHeld(index, resultsModel, limitedCategoryItemCount) {
353 // Do nothing
353 // Do nothing
354 }
354 }
355 }
355 }