diff --git a/src/plugins/git/gerrit/gerritdialog.cpp b/src/plugins/git/gerrit/gerritdialog.cpp index 87f0ba3fbc8..4318174c7b8 100644 --- a/src/plugins/git/gerrit/gerritdialog.cpp +++ b/src/plugins/git/gerrit/gerritdialog.cpp @@ -104,6 +104,7 @@ GerritDialog::GerritDialog(const QSharedPointer &p, , m_queryLineEdit(new QueryValidatingLineEdit) , m_filterLineEdit(new Utils::FilterLineEdit) , m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Close)) + , m_fetchRunning(false) { setWindowTitle(tr("Gerrit %1@%2").arg(p->user, p->host)); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); @@ -266,6 +267,14 @@ const QStandardItem *GerritDialog::currentItem(int column) const return 0; } +void GerritDialog::updateButtons() +{ + const bool enabled = !m_fetchRunning && m_treeView->selectionModel()->currentIndex().isValid(); + m_displayButton->setEnabled(enabled); + m_applyButton->setEnabled(enabled); + m_checkoutButton->setEnabled(enabled); +} + void GerritDialog::slotCurrentChanged() { const QModelIndex current = m_treeView->selectionModel()->currentIndex(); @@ -276,9 +285,27 @@ void GerritDialog::slotCurrentChanged() } else { m_detailsBrowser->setText(QString()); } - m_displayButton->setEnabled(valid); - m_applyButton->setEnabled(valid); - m_checkoutButton->setEnabled(valid); + updateButtons(); +} + +void GerritDialog::fetchStarted(const QSharedPointer &change) +{ + // Disable buttons to prevent parallel gerrit operations which can cause mix-ups. + m_fetchRunning = true; + updateButtons(); + const QString toolTip = tr("Fetching \"%1\"...").arg(change->title); + m_displayButton->setToolTip(toolTip); + m_applyButton->setToolTip(toolTip); + m_checkoutButton->setToolTip(toolTip); +} + +void GerritDialog::fetchFinished() +{ + m_fetchRunning = false; + updateButtons(); + m_displayButton->setToolTip(QString()); + m_applyButton->setToolTip(QString()); + m_checkoutButton->setToolTip(QString()); } } // namespace Internal diff --git a/src/plugins/git/gerrit/gerritdialog.h b/src/plugins/git/gerrit/gerritdialog.h index d9a4444fe4d..f1854c10b9f 100644 --- a/src/plugins/git/gerrit/gerritdialog.h +++ b/src/plugins/git/gerrit/gerritdialog.h @@ -84,6 +84,10 @@ signals: void fetchApply(const QSharedPointer &); void fetchCheckout(const QSharedPointer &); +public slots: + void fetchStarted(const QSharedPointer &change); + void fetchFinished(); + private slots: void slotCurrentChanged(); void slotDoubleClicked(const QModelIndex &); @@ -98,6 +102,7 @@ private: const QStandardItem *currentItem(int column = 0) const; QPushButton *addActionButton(const QString &text, const char *buttonSlot); void updateCompletions(const QString &query); + void updateButtons(); const QSharedPointer m_parameters; QSortFilterProxyModel *m_filterModel; @@ -112,6 +117,7 @@ private: QPushButton *m_applyButton; QPushButton *m_checkoutButton; QPushButton *m_refreshButton; + bool m_fetchRunning; }; } // namespace Internal diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp index bc35d31c8fa..0fdac66320a 100644 --- a/src/plugins/git/gerrit/gerritplugin.cpp +++ b/src/plugins/git/gerrit/gerritplugin.cpp @@ -372,6 +372,9 @@ void GerritPlugin::openView() this, SLOT(fetchApply(QSharedPointer))); connect(gd, SIGNAL(fetchCheckout(QSharedPointer)), this, SLOT(fetchCheckout(QSharedPointer))); + connect(this, SIGNAL(fetchStarted(QSharedPointer)), + gd, SLOT(fetchStarted(QSharedPointer))); + connect(this, SIGNAL(fetchFinished()), gd, SLOT(fetchFinished())); m_dialog = gd; } const Qt::WindowStates state = m_dialog.data()->windowState(); @@ -442,6 +445,8 @@ void GerritPlugin::fetch(const QSharedPointer &c FetchContext *fc = new FetchContext(change, repository, git, m_parameters, FetchMode(mode), this); + connect(fc, SIGNAL(destroyed(QObject*)), this, SIGNAL(fetchFinished())); + emit fetchStarted(change); fc->start(); } diff --git a/src/plugins/git/gerrit/gerritplugin.h b/src/plugins/git/gerrit/gerritplugin.h index 9e096f393e0..2470dcfcc8c 100644 --- a/src/plugins/git/gerrit/gerritplugin.h +++ b/src/plugins/git/gerrit/gerritplugin.h @@ -62,6 +62,10 @@ public slots: void fetchApply(const QSharedPointer &change); void fetchCheckout(const QSharedPointer &change); +signals: + void fetchStarted(const QSharedPointer &change); + void fetchFinished(); + private slots: void openView();