Mercurial > hg > easyhg
changeset 281:9162f14c5ab7
* Change "diff to parent <id>" menu entries in changeset item right-button menu to "diff to left parent" and "diff to right parent"
author | Chris Cannam |
---|---|
date | Fri, 18 Feb 2011 13:38:31 +0000 |
parents | b6e4643d6c05 |
children | 1ec306df738e |
files | changesetitem.cpp changesetscene.cpp changesetscene.h mainwindow.cpp |
diffstat | 4 files changed, 56 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/changesetitem.cpp Wed Feb 09 12:02:53 2011 +0000 +++ b/changesetitem.cpp Fri Feb 18 13:38:31 2011 +0000 @@ -16,6 +16,7 @@ */ #include "changesetitem.h" +#include "changesetscene.h" #include "changesetdetailitem.h" #include "changeset.h" #include "textabbrev.h" @@ -121,15 +122,51 @@ menu->addSeparator(); - if (m_changeset->parents().size() > 1) { + QStringList parents = m_changeset->parents(); - foreach (QString parentId, m_changeset->parents()) { - QAction *diffParent = - menu->addAction(tr("Diff to parent %1") - .arg(Changeset::hashOf(parentId))); + if (parents.size() > 1) { + + QString leftId, rightId; + ChangesetScene *cs = dynamic_cast<ChangesetScene *>(scene()); + bool havePositions = false; + + if (cs && parents.size() == 2) { + ChangesetItem *i0 = cs->getItemById(parents[0]); + ChangesetItem *i1 = cs->getItemById(parents[1]); + if (i0 && i1) { + if (i0->x() < i1->x()) { + leftId = parents[0]; + rightId = parents[1]; + } else { + leftId = parents[1]; + rightId = parents[0]; + } + havePositions = true; + } + } + + if (havePositions) { + + QAction *diffParent = menu->addAction(tr("Diff to left parent")); connect(diffParent, SIGNAL(triggered()), this, SLOT(diffToParentActivated())); - m_parentDiffActions[diffParent] = parentId; + m_parentDiffActions[diffParent] = leftId; + + diffParent = menu->addAction(tr("Diff to right parent")); + connect(diffParent, SIGNAL(triggered()), + this, SLOT(diffToParentActivated())); + m_parentDiffActions[diffParent] = rightId; + + } else { + + foreach (QString parentId, parents) { + QString text = tr("Diff to parent %1") + .arg(Changeset::hashOf(parentId)); + QAction *diffParent = menu->addAction(text); + connect(diffParent, SIGNAL(triggered()), + this, SLOT(diffToParentActivated())); + m_parentDiffActions[diffParent] = parentId; + } } } else {
--- a/changesetscene.cpp Wed Feb 09 12:02:53 2011 +0000 +++ b/changesetscene.cpp Fri Feb 18 13:38:31 2011 +0000 @@ -108,3 +108,13 @@ } } +ChangesetItem * +ChangesetScene::getItemById(QString id) +{ + foreach (QGraphicsItem *it, items()) { + ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it); + if (csit && csit->getId() == id) return csit; + } +} + +
--- a/changesetscene.h Wed Feb 09 12:02:53 2011 +0000 +++ b/changesetscene.h Fri Feb 18 13:38:31 2011 +0000 @@ -35,6 +35,8 @@ void addUncommittedItem(UncommittedItem *item); void addDateItem(DateItem *item); + ChangesetItem *getItemById(QString id); // Slow: traversal required + signals: void commit(); void revert();
--- a/mainwindow.cpp Wed Feb 09 12:02:53 2011 +0000 +++ b/mainwindow.cpp Fri Feb 18 13:38:31 2011 +0000 @@ -590,7 +590,7 @@ QStringList params; - // Diff given revision against working folder + // Diff given revision against parent revision params << "--config" << "extensions.extdiff=" << "extdiff"; params << "--program" << diff;