changeset 571:012ba1b83328

Show cancel button with progress bar only when running an operation that it makes sense to cancel (we don't really want people cancelling e.g. initial folder scan because it would leave things in an inconsistent state)
author Chris Cannam
date Thu, 01 Mar 2012 22:53:54 +0000
parents e0d734fad735
children da2dd0e290ac
files src/hgaction.h src/hgrunner.cpp src/hgrunner.h
diffstat 3 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/hgaction.h	Wed Feb 29 15:24:10 2012 +0000
+++ b/src/hgaction.h	Thu Mar 01 22:53:54 2012 +0000
@@ -118,6 +118,20 @@
 	    return false;
 	}
     }
+
+    bool makesSenseToCancel() const {
+        switch (action) {
+        case ACT_INCOMING:
+        case ACT_PUSH:
+        case ACT_PULL:
+        case ACT_CLONEFROMREMOTE:
+        case ACT_FOLDERDIFF:
+        case ACT_CHGSETDIFF:
+            return true;
+        default:
+            return false;
+        }
+    }
 };
 
 #endif
--- a/src/hgrunner.cpp	Wed Feb 29 15:24:10 2012 +0000
+++ b/src/hgrunner.cpp	Thu Mar 01 22:53:54 2012 +0000
@@ -26,7 +26,7 @@
 #include <QTemporaryFile>
 #include <QDir>
 #include <QProgressBar>
-#include <QToolButton>
+#include <QPushButton>
 #include <QGridLayout>
 
 #include <iostream>
@@ -52,10 +52,11 @@
     m_progress = new QProgressBar;
     layout->addWidget(m_progress, 0, 0);
 
-    m_cancel = new QToolButton;
+    m_cancel = new QPushButton;
     m_cancel->setIcon(QIcon(":images/cancel-small.png"));
-    m_cancel->setToolButtonStyle(Qt::ToolButtonIconOnly);
-    m_cancel->setAutoRaise(true);
+    m_cancel->setFlat(true);
+    m_cancel->setFixedHeight(m_progress->sizeHint().height());
+    m_cancel->setFixedWidth(m_progress->sizeHint().height());
     connect(m_cancel, SIGNAL(clicked()), this, SLOT(killCurrentActions()));
     layout->addWidget(m_cancel, 0, 1);
 
@@ -538,7 +539,10 @@
 
     m_isRunning = true;
     m_progress->setRange(0, 0);
-    if (!action.shouldBeFast()) show();
+    if (!action.shouldBeFast()) {
+        show();
+        m_cancel->setVisible(action.makesSenseToCancel());
+    }
     m_stdout.clear();
     m_stderr.clear();
     m_realm = "";
--- a/src/hgrunner.h	Wed Feb 29 15:24:10 2012 +0000
+++ b/src/hgrunner.h	Thu Mar 01 22:53:54 2012 +0000
@@ -24,7 +24,7 @@
 #include <QProcess>
 
 class QProgressBar;
-class QToolButton;
+class QPushButton;
 class QFile;
 
 #include <deque>
@@ -88,7 +88,7 @@
     QString unbundleExtension();
 
     QProgressBar *m_progress;
-    QToolButton *m_cancel;
+    QPushButton *m_cancel;
 
     QStringList addExtensionOptions(QStringList);