changeset 289:37f67999b661

We can provide a better interface for most common cases by essentially showing a formatted log for the summary rather than a diff only
author Chris Cannam
date Mon, 21 Feb 2011 12:15:04 +0000
parents ca6edd303c9d
children a1c8630a0057
files changesetitem.cpp changesetitem.h changesetscene.cpp changesetscene.h hgaction.h hgtabwidget.cpp hgtabwidget.h historywidget.cpp historywidget.h mainwindow.cpp mainwindow.h
diffstat 11 files changed, 53 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/changesetitem.cpp	Mon Feb 21 11:37:58 2011 +0000
+++ b/changesetitem.cpp	Mon Feb 21 12:15:04 2011 +0000
@@ -121,6 +121,11 @@
     QAction *copyId = menu->addAction(tr("Copy identifier to clipboard"));
     connect(copyId, SIGNAL(triggered()), this, SLOT(copyIdActivated()));
 
+    QAction *stat = menu->addAction(tr("Summarise changes"));
+    connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryActivated()));
+
+    menu->addSeparator();
+
     QStringList parents = m_changeset->parents();
 
     QString leftId, rightId;
@@ -146,32 +151,6 @@
 
     if (parents.size() > 1) {
         if (havePositions) {
-            QAction *stat = menu->addAction(tr("Summarise changes from left parent"));
-            connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryToParentActivated()));
-            m_summaryActions[stat] = leftId;
-            
-            stat = menu->addAction(tr("Summarise changes from right parent"));
-            connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryToParentActivated()));
-            m_summaryActions[stat] = rightId;
-        } else {
-            
-            foreach (QString parentId, parents) {
-                QString text = tr("Summarise changes from parent %1").arg(Changeset::hashOf(parentId));
-                QAction *stat = menu->addAction(text);
-                connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryToParentActivated()));
-                m_summaryActions[stat] = parentId;
-            }
-
-        }
-    } else {
-        QAction *stat = menu->addAction(tr("Summarise changes"));
-        connect(stat, SIGNAL(triggered()), this, SLOT(showSummaryToParentActivated()));
-    }
-
-    menu->addSeparator();
-
-    if (parents.size() > 1) {
-        if (havePositions) {
             
             QAction *diff = menu->addAction(tr("Diff to left parent"));
             connect(diff, SIGNAL(triggered()), this, SLOT(diffToParentActivated()));
@@ -243,22 +222,9 @@
     emit diffToParent(getId(), parentId);
 }
 
-void ChangesetItem::showSummaryToParentActivated()
+void ChangesetItem::showSummaryActivated()
 {
-    QAction *a = qobject_cast<QAction *>(sender());
-    QString parentId;
-    if (m_summaryActions.contains(a)) {
-        parentId = m_summaryActions[a];
-        DEBUG << "ChangesetItem::showSummaryToParentActivated: specific parent " 
-              << parentId << " selected" << endl;
-    } else {
-        parentId = m_changeset->parents()[0];
-        DEBUG << "ChangesetItem::showSummaryToParentActivated: "
-              << "no specific parent selected, using first parent "
-              << parentId << endl;
-    }
-
-    emit showSummaryToParent(getId(), parentId);
+    emit showSummary(m_changeset);
 }
 
 void ChangesetItem::updateActivated() { emit updateTo(getId()); }
--- a/changesetitem.h	Mon Feb 21 11:37:58 2011 +0000
+++ b/changesetitem.h	Mon Feb 21 12:15:04 2011 +0000
@@ -63,7 +63,7 @@
     void updateTo(QString);
     void diffToCurrent(QString);
     void diffToParent(QString child, QString parent);
-    void showSummaryToParent(QString child, QString parent);
+    void showSummary(Changeset *);
     void mergeFrom(QString);
     void tag(QString);
 
@@ -75,7 +75,7 @@
     void copyIdActivated();
     void updateActivated();
     void diffToParentActivated();
-    void showSummaryToParentActivated();
+    void showSummaryActivated();
     void diffToCurrentActivated();
     void mergeActivated();
     void tagActivated();
--- a/changesetscene.cpp	Mon Feb 21 11:37:58 2011 +0000
+++ b/changesetscene.cpp	Mon Feb 21 12:15:04 2011 +0000
@@ -45,8 +45,8 @@
     connect(item, SIGNAL(diffToParent(QString, QString)),
             this, SIGNAL(diffToParent(QString, QString)));
 
-    connect(item, SIGNAL(showSummaryToParent(QString, QString)),
-            this, SIGNAL(showSummaryToParent(QString, QString)));
+    connect(item, SIGNAL(showSummary(Changeset *)),
+            this, SIGNAL(showSummary(Changeset *)));
 
     connect(item, SIGNAL(mergeFrom(QString)),
             this, SIGNAL(mergeFrom(QString)));
--- a/changesetscene.h	Mon Feb 21 11:37:58 2011 +0000
+++ b/changesetscene.h	Mon Feb 21 12:15:04 2011 +0000
@@ -21,6 +21,7 @@
 #include <QGraphicsScene>
 
 class ChangesetItem;
+class Changeset;
 class UncommittedItem;
 class DateItem;
 
@@ -46,7 +47,7 @@
 
     void updateTo(QString id);
     void diffToParent(QString id, QString parent);
-    void showSummaryToParent(QString id, QString parent);
+    void showSummary(Changeset *);
     void diffToCurrent(QString id);
     void mergeFrom(QString id);
     void tag(QString id);
--- a/hgaction.h	Mon Feb 21 11:37:58 2011 +0000
+++ b/hgaction.h	Mon Feb 21 12:15:04 2011 +0000
@@ -63,15 +63,20 @@
     QString workingDir;
     QStringList params;
     QString executable; // empty for normal Hg, but gets filled in by hgrunner
+    void *extraData;
 
     HgAction() : action(ACT_NONE) { }
 
     HgAction(HGACTIONS _action, QString _wd, QStringList _params) :
-        action(_action), workingDir(_wd), params(_params) { }
+        action(_action), workingDir(_wd), params(_params), extraData(0) { }
+
+    HgAction(HGACTIONS _action, QString _wd, QStringList _params, void *_d) :
+        action(_action), workingDir(_wd), params(_params), extraData(_d) { }
 
     bool operator==(const HgAction &a) {
         return (a.action == action && a.workingDir == workingDir &&
-                a.params == params && a.executable == executable);
+                a.params == params && a.executable == executable &&
+                a.extraData == extraData);
     }
 
     bool shouldBeFast() const {
--- a/hgtabwidget.cpp	Mon Feb 21 11:37:58 2011 +0000
+++ b/hgtabwidget.cpp	Mon Feb 21 12:15:04 2011 +0000
@@ -69,8 +69,8 @@
     connect(m_historyWidget, SIGNAL(diffToParent(QString, QString)),
             this, SIGNAL(diffToParent(QString, QString)));
 
-    connect(m_historyWidget, SIGNAL(showSummaryToParent(QString, QString)),
-            this, SIGNAL(showSummaryToParent(QString, QString)));
+    connect(m_historyWidget, SIGNAL(showSummary(Changeset *)),
+            this, SIGNAL(showSummary(Changeset *)));
 
     connect(m_historyWidget, SIGNAL(mergeFrom(QString)),
             this, SIGNAL(mergeFrom(QString)));
--- a/hgtabwidget.h	Mon Feb 21 11:37:58 2011 +0000
+++ b/hgtabwidget.h	Mon Feb 21 12:15:04 2011 +0000
@@ -91,7 +91,7 @@
 
     void updateTo(QString id);
     void diffToParent(QString id, QString parent);
-    void showSummaryToParent(QString id, QString parent);
+    void showSummary(Changeset *);
     void diffToCurrent(QString id);
     void mergeFrom(QString id);
     void tag(QString id);
--- a/historywidget.cpp	Mon Feb 21 11:37:58 2011 +0000
+++ b/historywidget.cpp	Mon Feb 21 12:15:04 2011 +0000
@@ -277,8 +277,8 @@
     connect(scene, SIGNAL(diffToParent(QString, QString)),
             this, SIGNAL(diffToParent(QString, QString)));
 
-    connect(scene, SIGNAL(showSummaryToParent(QString, QString)),
-            this, SIGNAL(showSummaryToParent(QString, QString)));
+    connect(scene, SIGNAL(showSummary(Changeset *)),
+            this, SIGNAL(showSummary(Changeset *)));
 
     connect(scene, SIGNAL(mergeFrom(QString)),
             this, SIGNAL(mergeFrom(QString)));
--- a/historywidget.h	Mon Feb 21 11:37:58 2011 +0000
+++ b/historywidget.h	Mon Feb 21 12:15:04 2011 +0000
@@ -54,7 +54,7 @@
 
     void updateTo(QString id);
     void diffToParent(QString id, QString parent);
-    void showSummaryToParent(QString id, QString parent);
+    void showSummary(Changeset *);
     void diffToCurrent(QString id);
     void mergeFrom(QString id);
     void tag(QString id);
--- a/mainwindow.cpp	Mon Feb 21 11:37:58 2011 +0000
+++ b/mainwindow.cpp	Mon Feb 21 12:15:04 2011 +0000
@@ -601,15 +601,17 @@
 }
 
 
-void MainWindow::hgShowSummaryToParent(QString child, QString parent)
+void MainWindow::hgShowSummaryFor(Changeset *cs)
 {
     QStringList params;
 
-    params << "diff" << "--stat"
-           << "--rev" << Changeset::hashOf(parent)
-           << "--rev" << Changeset::hashOf(child);
-
-    m_runner->requestAction(HgAction(ACT_DIFF_SUMMARY, m_workFolderPath, params));
+    // This will pick a default parent if there is more than one
+    // (whereas with diff we need to supply one).  But it does need a
+    // bit more parsing
+    params << "log" << "--stat" << "--rev" << Changeset::hashOf(cs->id());
+
+    m_runner->requestAction(HgAction(ACT_DIFF_SUMMARY, m_workFolderPath,
+                                     params, cs));
 }
 
 
@@ -1917,8 +1919,21 @@
         break;
 
     case ACT_DIFF_SUMMARY:
-        if (output == "") {
-            // Can happen, for a merge commit
+    {
+        // Output has log info first, diff following after a blank line
+        output.replace("\r\n", "\n");
+        QStringList olist = output.split("\n\n", QString::SkipEmptyParts);
+        if (olist.size() > 1) output = olist[1];
+
+        Changeset *cs = (Changeset *)completedAction.extraData;
+        if (cs) {
+            QMessageBox::information
+                (this, tr("Change summary"),
+                 format3(tr("Summary of changes"),
+                         cs->formatHtml(),
+                         output));
+        } else if (output == "") {
+            // Can happen, for a merge commit (depending on parent)
             QMessageBox::information(this, tr("Change summary"),
                                      format3(tr("Summary of changes"),
                                              tr("No changes"),
@@ -1930,6 +1945,7 @@
                                              output));
         }            
         break;
+    }
 
     case ACT_FOLDERDIFF:
     case ACT_CHGSETDIFF:
@@ -2106,8 +2122,8 @@
     connect(m_hgTabs, SIGNAL(diffToParent(QString, QString)),
             this, SLOT(hgDiffToParent(QString, QString)));
 
-    connect(m_hgTabs, SIGNAL(showSummaryToParent(QString, QString)),
-            this, SLOT(hgShowSummaryToParent(QString, QString)));
+    connect(m_hgTabs, SIGNAL(showSummary(Changeset *)),
+            this, SLOT(hgShowSummaryFor(Changeset *)));
 
     connect(m_hgTabs, SIGNAL(mergeFrom(QString)),
             this, SLOT(hgMergeFrom(QString)));
--- a/mainwindow.h	Mon Feb 21 11:37:58 2011 +0000
+++ b/mainwindow.h	Mon Feb 21 12:15:04 2011 +0000
@@ -69,7 +69,7 @@
     void hgAdd();
     void hgCommit();
     void hgShowSummary();
-    void hgShowSummaryToParent(QString, QString);
+    void hgShowSummaryFor(Changeset *);
     void hgFolderDiff();
     void hgDiffToCurrent(QString);
     void hgDiffToParent(QString, QString);