From cfc473a8f584f7f845e74005686538e911769ded Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Tue, 4 May 2021 16:58:16 -0600 Subject: [PATCH] Allow ExpandableListItem to not be expandable when it has no valid actions Typically ExpandableListItem expands when you click on it or its expander arrow, and shows a list of contextual actions. However there may occasionally arise cirsumstances under which an item has no actions. An example would be in the Disks & Devices applet when a device doesn't match any of the Solid predicates and therefore gets no contextual actions. In this case, we should hide the expander arrow and now let the user try to expand it, because there would just be a little empty list stub. --- .../qml/ExpandableListItem.qml | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/declarativeimports/plasmaextracomponents/qml/ExpandableListItem.qml b/src/declarativeimports/plasmaextracomponents/qml/ExpandableListItem.qml index ed45b9548..cbc9d3e86 100644 --- a/src/declarativeimports/plasmaextracomponents/qml/ExpandableListItem.qml +++ b/src/declarativeimports/plasmaextracomponents/qml/ExpandableListItem.qml @@ -282,11 +282,33 @@ Item { */ property bool isDefault: false + /* + * hasExpandableContent: bool (read-only) + * Whether or not this expandable list item is actually expandable. True if + * this item has either a custom view or else at least one enabled action. + * Otherwise false. + */ + readonly property bool hasExpandableContent: { + // If there is custom content, assume it is expandable (otherwise what + // would be the point?) + if (customExpandedViewContent != actionsListComponent) { + return true; + } + // Filter out disabled items which won't appear, when determining if there + // are any valid actions + if (contextualActionsModel) { + return Array.from(contextualActionsModel).filter(item => item.enabled).length > 0; + } + return false; + } /* * expand() * Show the expanded view, growing the list item to its taller size. */ function expand() { + if (!listItem.hasExpandableContent) { + return; + } expandedView.active = true listItem.itemExpanded(listItem) } @@ -296,6 +318,9 @@ Item { * Hide the expanded view and collapse the list item to its shorter size. */ function collapse() { + if (!listItem.hasExpandableContent) { + return; + } expandedView.active = false listItem.itemCollapsed(listItem) } @@ -305,6 +330,9 @@ Item { * Expand or collapse the list item depending on its current state. */ function toggleExpanded() { + if (!listItem.hasExpandableContent) { + return; + } expandedView.active ? listItem.collapse() : listItem.expand() } @@ -318,7 +346,7 @@ Item { // Handle left clicks and taps TapHandler { - enabled: listItem.isEnabled + enabled: listItem.isEnabled && listItem.hasExpandableContent acceptedButtons: Qt.LeftButton @@ -457,6 +485,7 @@ Item { // Expand/collapse button PlasmaComponents3.ToolButton { + visible: listItem.hasExpandableContent icon.name: expandedView.active? "collapse" : "expand" onClicked: listItem.toggleExpanded()