From 2520afcea34265676abd1d5e57bb324e0e08e26d Mon Sep 17 00:00:00 2001 From: Marc Plano-Lesay Date: Mon, 4 Nov 2013 07:20:41 +0100 Subject: [PATCH] Disable multi-selection unusable actions - refs #7 --- assets/ArticlesListPage/ArticlesListPage.qml | 151 ++++++++++++------- 1 file changed, 94 insertions(+), 57 deletions(-) diff --git a/assets/ArticlesListPage/ArticlesListPage.qml b/assets/ArticlesListPage/ArticlesListPage.qml index f884309..1846b48 100644 --- a/assets/ArticlesListPage/ArticlesListPage.qml +++ b/assets/ArticlesListPage/ArticlesListPage.qml @@ -17,75 +17,81 @@ Page { multiSelectHandler { status: qsTr("None selected") - actions: [ + actions: [ ActionItem { + id: actionMultiRead title: qsTr("Mark as read") imageSource: "asset:///images/mark_as_read.png" - onTriggered: { - var selectionList = listView.selectionList(); - listView.clearSelection(); + onTriggered: { + var selectionList = listView.selectionList(); + listView.clearSelection(); for (var i = 0; i < selectionList.length; ++i) - _articleModel.data(selectionList[i]).unread = false; + _articleModel.data(selectionList[i]).unread = false; } - }, + }, ActionItem { + id: actionMultiUnread title: qsTr("Keep unread") - imageSource: "asset:///images/keep_unread.png" - - onTriggered: { - var selectionList = listView.selectionList(); - listView.clearSelection(); + imageSource: "asset:///images/keep_unread.png" + + onTriggered: { + var selectionList = listView.selectionList(); + listView.clearSelection(); for (var i = 0; i < selectionList.length; ++ i) - _articleModel.data(selectionList[i]).unread = true; - } - }, - - ActionItem { - title: qsTr("Publish") - imageSource: "asset:///images/publish.png" - - onTriggered: { - var selectionList = listView.selectionList(); - listView.clearSelection(); + _articleModel.data(selectionList[i]).unread = true; + } + }, + + ActionItem { + id: actionMultiPublish + title: qsTr("Publish") + imageSource: "asset:///images/publish.png" + + onTriggered: { + var selectionList = listView.selectionList(); + listView.clearSelection(); for (var i = 0; i < selectionList.length; ++ i) - _articleModel.data(selectionList[i]).published = true; - } - }, - ActionItem { - title: qsTr("Unpublish") - imageSource: "asset:///images/unpublish.png" - - onTriggered: { - var selectionList = listView.selectionList(); - listView.clearSelection(); + _articleModel.data(selectionList[i]).published = true; + } + }, + ActionItem { + id: actionMultiUnpublish + title: qsTr("Unpublish") + imageSource: "asset:///images/unpublish.png" + + onTriggered: { + var selectionList = listView.selectionList(); + listView.clearSelection(); for (var i = 0; i < selectionList.length; ++ i) - _articleModel.data(selectionList[i]).published = false; - } - }, - - ActionItem { - title: qsTr("Star") - imageSource: "asset:///images/star.png" - - onTriggered: { - var selectionList = listView.selectionList(); - listView.clearSelection(); + _articleModel.data(selectionList[i]).published = false; + } + }, + + ActionItem { + id: actionMultiStar + title: qsTr("Star") + imageSource: "asset:///images/star.png" + + onTriggered: { + var selectionList = listView.selectionList(); + listView.clearSelection(); for (var i = 0; i < selectionList.length; ++ i) - _articleModel.data(selectionList[i]).marked = true; - } - }, - ActionItem { - title: qsTr("Unstar") - imageSource: "asset:///images/unstar.png" - - onTriggered: { - var selectionList = listView.selectionList(); - listView.clearSelection(); + _articleModel.data(selectionList[i]).marked = true; + } + }, + ActionItem { + id: actionMultiUnstar + title: qsTr("Unstar") + imageSource: "asset:///images/unstar.png" + + onTriggered: { + var selectionList = listView.selectionList(); + listView.clearSelection(); for (var i = 0; i < selectionList.length; ++ i) - _articleModel.data(selectionList[i]).marked = false; - } - } + _articleModel.data(selectionList[i]).marked = false; + } + } ] } @@ -96,7 +102,38 @@ Page { multiSelectHandler.status = qsTr("1 item selected"); } else { multiSelectHandler.status = qsTr("None selected"); - } + } + + // Update available actions + var starred = false; + var unstarred = false; + var published = false; + var unpublished = false; + var read = false; + var unread = false; + for (var i = 0; i < selectionList().length; ++ i) { + var elt = _articleModel.data(selectionList()[i]); + if (elt.marked) + starred = true; + else + unstarred = true; + + if (elt.published) + published = true; + else + unpublished = true; + + if (elt.unread) + unread = true; + else + read = true; + } + actionMultiUnstar.enabled = starred; + actionMultiStar.enabled = unstarred; + actionMultiUnpublish.enabled = published; + actionMultiPublish.enabled = unpublished; + actionMultiUnread.enabled = read; + actionMultiRead.enabled = unread; } listItemComponents: [