# HG changeset patch # User Chris Cannam # Date 1291122473 0 # Node ID 1208d9688a8f09e099d5996254bc63f875ef8331 # Parent aaeab914f2a334d58826a6710b6d45a6804d28fe * Have a go at switching to new items in history widget when something happens in repo diff -r aaeab914f2a3 -r 1208d9688a8f hgtabwidget.cpp --- a/hgtabwidget.cpp Tue Nov 30 12:45:34 2010 +0000 +++ b/hgtabwidget.cpp Tue Nov 30 13:07:53 2010 +0000 @@ -140,11 +140,17 @@ void HgTabWidget::setNewLog(QString hgLogList) { m_historyWidget->parseNewLog(hgLogList); + if (m_historyWidget->haveNewItems()) { + setCurrentWidget(m_historyWidget); + } } void HgTabWidget::addIncrementalLog(QString hgLogList) { m_historyWidget->parseIncrementalLog(hgLogList); + if (m_historyWidget->haveNewItems()) { + setCurrentWidget(m_historyWidget); + } } void HgTabWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath) diff -r aaeab914f2a3 -r 1208d9688a8f historywidget.cpp --- a/historywidget.cpp Tue Nov 30 12:45:34 2010 +0000 +++ b/historywidget.cpp Tue Nov 30 13:07:53 2010 +0000 @@ -34,6 +34,7 @@ m_panner = new Panner; m_uncommitted = new UncommittedItem(); m_uncommitted->setRow(-1); + m_uncommittedVisible = false; QGridLayout *layout = new QGridLayout; layout->addWidget(m_panned, 0, 0); @@ -47,7 +48,7 @@ HistoryWidget::~HistoryWidget() { clearChangesets(); - delete m_uncommitted; + if (!m_uncommittedVisible) delete m_uncommitted; } void HistoryWidget::clearChangesets() @@ -69,17 +70,8 @@ void HistoryWidget::showUncommittedChanges(bool show) { - QGraphicsScene *scene = m_panned->scene(); - if (!scene) return; - - if (show) { - if (m_uncommitted->scene() == scene) return; - scene->addItem(m_uncommitted); - m_uncommitted->ensureVisible(); - } else { - if (m_uncommitted->scene() != scene) return; - scene->removeItem(m_uncommitted); - } + m_uncommittedVisible = show; + layoutAll(); } void HistoryWidget::parseNewLog(QString log) @@ -141,7 +133,6 @@ void HistoryWidget::layoutAll() { setChangesetParents(); - showUncommittedChanges(false); // detach the item from our scene ChangesetScene *scene = new ChangesetScene(); ChangesetItem *tipItem = 0; @@ -159,13 +150,28 @@ } QGraphicsScene *oldScene = m_panned->scene(); + + // detach m_uncommitted from old scene so it doesn't get deleted + if (oldScene && (m_uncommitted->scene() == oldScene)) { + oldScene->removeItem(m_uncommitted); + } + if (m_uncommittedVisible) { + scene->addItem(m_uncommitted); + } + m_panned->setScene(scene); m_panner->setScene(scene); if (oldScene) delete oldScene; - if (tipItem) tipItem->ensureVisible(); updateNewAndCurrentItems(); + + if (m_uncommittedVisible) { + m_uncommitted->ensureVisible(); + } else if (tipItem) { + DEBUG << "asking tip item to be visible" << endl; + tipItem->ensureVisible(); + } } void HistoryWidget::setChangesetParents() diff -r aaeab914f2a3 -r 1208d9688a8f historywidget.h --- a/historywidget.h Tue Nov 30 12:45:34 2010 +0000 +++ b/historywidget.h Tue Nov 30 13:07:53 2010 +0000 @@ -40,12 +40,15 @@ void parseNewLog(QString log); void parseIncrementalLog(QString log); + + bool haveNewItems() const { return !m_newIds.empty(); } private: Changesets m_changesets; QStringList m_currentIds; QSet m_newIds; UncommittedItem *m_uncommitted; + bool m_uncommittedVisible; Panned *m_panned; Panner *m_panner;