changeset 564:39cac58b4f92

Add commandCancelled signal -- but don't make use of it; it didn't work out as I'd hoped
author Chris Cannam
date Tue, 28 Feb 2012 16:59:25 +0000
parents 0a094020c2d4
children c2e212ab0068
files src/hgrunner.cpp src/hgrunner.h src/mainwindow.cpp src/mainwindow.h
diffstat 4 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/hgrunner.cpp	Tue Feb 28 14:38:42 2012 +0000
+++ b/src/hgrunner.cpp	Tue Feb 28 16:59:25 2012 +0000
@@ -339,9 +339,9 @@
 
 void HgRunner::finished(int procExitCode, QProcess::ExitStatus procExitStatus)
 {
-	if (!m_proc) return;
+    if (!m_proc) return;
 
-	// Save the current action and reset m_currentAction before we
+    // Save the current action and reset m_currentAction before we
     // emit a signal to mark the completion; otherwise we may be
     // resetting the action after a slot has already tried to set it
     // to something else to start a new action
@@ -377,8 +377,10 @@
 
 void HgRunner::killCurrentActions()
 {
+    HgAction current = m_currentAction;
     m_queue.clear();
     killCurrentCommand();
+    emit commandCancelled(current);
 }
 
 void HgRunner::killCurrentCommand()
--- a/src/hgrunner.h	Tue Feb 28 14:38:42 2012 +0000
+++ b/src/hgrunner.h	Tue Feb 28 16:59:25 2012 +0000
@@ -46,6 +46,13 @@
     void commandCompleted(HgAction action, QString stdOut);
     void commandFailed(HgAction action, QString stdErr, QString stdOut);
 
+    /**
+     * Emitted when the currently executing command is cancelled. Note
+     * that this clears the queue completely, so all subsequent
+     * commands are also discarded.
+     */
+    void commandCancelled(HgAction action);
+
 private slots:
     void started();
     void error(QProcess::ProcessError);
--- a/src/mainwindow.cpp	Tue Feb 28 14:38:42 2012 +0000
+++ b/src/mainwindow.cpp	Tue Feb 28 16:59:25 2012 +0000
@@ -85,6 +85,8 @@
             this, SLOT(commandCompleted(HgAction, QString)));
     connect(m_runner, SIGNAL(commandFailed(HgAction, QString, QString)),
             this, SLOT(commandFailed(HgAction, QString, QString)));
+    connect(m_runner, SIGNAL(commandCancelled(HgAction)),
+            this, SLOT(commandCancelled(HgAction)));
     statusBar()->addPermanentWidget(m_runner);
 
     setWindowTitle(tr("EasyMercurial"));
@@ -2528,6 +2530,19 @@
     }
 }
 
+void MainWindow::commandCancelled(HgAction cancelledAction)
+{
+    // Originally I had this checking whether the cancelled action was
+    // a network one and, if so, calling hgQueryPaths to update the
+    // local view in case it had changed anything. But that doesn't
+    // work properly -- because at this point, although the command
+    // has been cancelled and a kill signal sent, it hasn't actually
+    // exited yet. If we request another command now, it will go on
+    // the stack and be associated with the failed exit forthcoming
+    // from the cancelled command -- giving the user a disturbing
+    // command-failed dialog
+}
+
 void MainWindow::connectActions()
 {
     connect(m_exitAct, SIGNAL(triggered()), this, SLOT(close()));
--- a/src/mainwindow.h	Tue Feb 28 14:38:42 2012 +0000
+++ b/src/mainwindow.h	Tue Feb 28 16:59:25 2012 +0000
@@ -54,6 +54,7 @@
     void commandStarting(HgAction);
     void commandCompleted(HgAction action, QString stdOut);
     void commandFailed(HgAction action, QString stdErr, QString stdOut);
+    void commandCancelled(HgAction action);
     void enableDisableActions();
 
 private slots: