From 71118dd979cbbcd3dedd20f279bd1ac136ad5f5a Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Date: Sun, 10 May 2015 17:19:34 -0300
Subject: [PATCH 3/3] Only show Collapse all when its needed

This makes Collapse All only visible when its needed, and it
also fixes a crash when invocking collapse all when there was
nothing to collapse.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
---
 qt-ui/divelistview.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index ae502ee..f8ea3ee 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -800,6 +800,7 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
 		// verify if there is a node that`s not expanded.
 		bool needs_expand = false;
 		bool needs_collapse = false;
+		uint expanded_nodes = 0;
 		for(int i = 0, end = model()->rowCount(); i < end; i++) {
 			QModelIndex idx = model()->index(i, 0);
 			if (idx.data(DiveTripModel::DIVE_ROLE).value<void *>())
@@ -807,15 +808,21 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
 
 			if (!isExpanded(idx))
 				needs_expand = true;
-			else
+			else {
 				needs_collapse = true;
+				expanded_nodes ++;
+			}
 		}
 		if (needs_expand)
 			popup.addAction(tr("Expand all"), this, SLOT(expandAll()));
 		if (needs_collapse)
 			popup.addAction(tr("Collapse all"), this, SLOT(collapseAll()));
 
-		collapseAction = popup.addAction(tr("Collapse others"), this, SLOT(collapseAll()));
+		// verify if there`s a need for collapse others
+		if (expanded_nodes > 1)
+			collapseAction = popup.addAction(tr("Collapse others"), this, SLOT(collapseAll()));
+
+
 		if (d) {
 			popup.addAction(tr("Remove dive(s) from trip"), this, SLOT(removeFromTrip()));
 			popup.addAction(tr("Create new trip above"), this, SLOT(newTripAbove()));
-- 
2.3.2 (Apple Git-55)

