Gerrit: Show only gerrit remotes in Push to Gerrit dialog

Task-number: QTCREATORBUG-16367
Change-Id: I18e24dd0748bd64790bd8d2c0eeeee2cf1d3991a
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2017-06-29 22:04:58 +03:00
committed by Orgad Shaneh
parent 6c70f22ada
commit 9df86c2e67
7 changed files with 64 additions and 26 deletions

View File

@@ -68,6 +68,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->remoteComboBox->setParameters(m_parameters); m_ui->remoteComboBox->setParameters(m_parameters);
m_ui->remoteComboBox->setFallbackEnabled(true);
m_queryModel->setStringList(m_parameters->savedQueries); m_queryModel->setStringList(m_parameters->savedQueries);
QCompleter *completer = new QCompleter(this); QCompleter *completer = new QCompleter(this);
completer->setModel(m_queryModel); completer->setModel(m_queryModel);

View File

@@ -315,7 +315,7 @@ void GerritPlugin::addToLocator(CommandLocator *locator)
void GerritPlugin::push(const QString &topLevel) void GerritPlugin::push(const QString &topLevel)
{ {
// QScopedPointer is required to delete the dialog when leaving the function // QScopedPointer is required to delete the dialog when leaving the function
GerritPushDialog dialog(topLevel, m_reviewers, ICore::mainWindow()); GerritPushDialog dialog(topLevel, m_reviewers, m_parameters, ICore::mainWindow());
if (!dialog.isValid()) { if (!dialog.isValid()) {
QMessageBox::warning(ICore::mainWindow(), tr("Initialization Failed"), QMessageBox::warning(ICore::mainWindow(), tr("Initialization Failed"),

View File

@@ -26,6 +26,7 @@
#include "gerritpushdialog.h" #include "gerritpushdialog.h"
#include "ui_gerritpushdialog.h" #include "ui_gerritpushdialog.h"
#include "branchcombobox.h" #include "branchcombobox.h"
#include "gerritserver.h"
#include "../gitplugin.h" #include "../gitplugin.h"
#include "../gitclient.h" #include "../gitclient.h"
@@ -114,21 +115,11 @@ void GerritPushDialog::initRemoteBranches()
BranchDate bd(ref.mid(refBranchIndex + 1), QDateTime::fromTime_t(timeT).date()); BranchDate bd(ref.mid(refBranchIndex + 1), QDateTime::fromTime_t(timeT).date());
m_remoteBranches.insertMulti(ref.left(refBranchIndex), bd); m_remoteBranches.insertMulti(ref.left(refBranchIndex), bd);
} }
QStringList remotes = GitPlugin::client()->synchronousRemotesList(m_workingDir).keys(); m_ui->remoteComboBox->updateRemotes(false);
remotes.removeDuplicates();
{
const QString origin = "origin";
const QString gerrit = "gerrit";
if (remotes.removeOne(origin))
remotes.prepend(origin);
if (remotes.removeOne(gerrit))
remotes.prepend(gerrit);
}
m_ui->remoteComboBox->addItems(remotes);
m_ui->remoteComboBox->setEnabled(remotes.count() > 1);
} }
GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &reviewerList, QWidget *parent) : GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &reviewerList,
QSharedPointer<GerritParameters> parameters, QWidget *parent) :
QDialog(parent), QDialog(parent),
m_workingDir(workingDir), m_workingDir(workingDir),
m_ui(new Ui::GerritPushDialog) m_ui(new Ui::GerritPushDialog)
@@ -136,13 +127,15 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->repositoryLabel->setText(QDir::toNativeSeparators(workingDir)); m_ui->repositoryLabel->setText(QDir::toNativeSeparators(workingDir));
m_ui->remoteComboBox->setRepository(workingDir);
m_ui->remoteComboBox->setParameters(parameters);
PushItemDelegate *delegate = new PushItemDelegate(m_ui->commitView); PushItemDelegate *delegate = new PushItemDelegate(m_ui->commitView);
delegate->setParent(this); delegate->setParent(this);
initRemoteBranches(); initRemoteBranches();
if (m_ui->remoteComboBox->count() < 1) if (m_ui->remoteComboBox->isEmpty())
return; return;
m_ui->localBranchComboBox->init(workingDir); m_ui->localBranchComboBox->init(workingDir);
@@ -163,8 +156,8 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev
m_ui->reviewersLineEdit->setValidator(noSpaceValidator); m_ui->reviewersLineEdit->setValidator(noSpaceValidator);
m_ui->topicLineEdit->setValidator(noSpaceValidator); m_ui->topicLineEdit->setValidator(noSpaceValidator);
connect(m_ui->remoteComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(m_ui->remoteComboBox, &GerritRemoteChooser::remoteChanged,
this, &GerritPushDialog::setRemoteBranches); this, [this] { setRemoteBranches(); });
m_isValid = true; m_isValid = true;
} }
@@ -285,10 +278,8 @@ void GerritPushDialog::updateCommits(int index)
m_suggestedRemoteBranch = remoteBranch.mid(slash + 1); m_suggestedRemoteBranch = remoteBranch.mid(slash + 1);
const QString remote = remoteBranch.left(slash); const QString remote = remoteBranch.left(slash);
const int index = m_ui->remoteComboBox->findText(remote);
if (index != -1 && index != m_ui->remoteComboBox->currentIndex()) if (!m_ui->remoteComboBox->setCurrentRemote(remote))
m_ui->remoteComboBox->setCurrentIndex(index);
else
setRemoteBranches(); setRemoteBranches();
} }
validate(); validate();
@@ -302,7 +293,7 @@ void GerritPushDialog::validate()
QString GerritPushDialog::selectedRemoteName() const QString GerritPushDialog::selectedRemoteName() const
{ {
return m_ui->remoteComboBox->currentText(); return m_ui->remoteComboBox->currentRemoteName();
} }
QString GerritPushDialog::selectedRemoteBranchName() const QString GerritPushDialog::selectedRemoteBranchName() const

View File

@@ -28,6 +28,7 @@
#include <QDialog> #include <QDialog>
#include <QMultiMap> #include <QMultiMap>
#include <QDate> #include <QDate>
#include <QSharedPointer>
namespace Git { namespace Git {
namespace Internal { class GitClient; } namespace Internal { class GitClient; }
@@ -36,6 +37,8 @@ namespace Internal { class GitClient; }
namespace Gerrit { namespace Gerrit {
namespace Internal { namespace Internal {
class GerritParameters;
namespace Ui { class GerritPushDialog; } namespace Ui { class GerritPushDialog; }
class GerritPushDialog : public QDialog class GerritPushDialog : public QDialog
@@ -43,7 +46,8 @@ class GerritPushDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
GerritPushDialog(const QString &workingDir, const QString &reviewerList, QWidget *parent); GerritPushDialog(const QString &workingDir, const QString &reviewerList,
QSharedPointer<GerritParameters> parameters, QWidget *parent);
~GerritPushDialog(); ~GerritPushDialog();
QString selectedCommit() const; QString selectedCommit() const;

View File

@@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>600</width> <width>740</width>
<height>410</height> <height>410</height>
</rect> </rect>
</property> </property>
@@ -170,7 +170,7 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QComboBox" name="remoteComboBox"/> <widget class="Gerrit::Internal::GerritRemoteChooser" name="remoteComboBox" native="true"/>
</item> </item>
<item row="6" column="0" colspan="3"> <item row="6" column="0" colspan="3">
<widget class="QLabel" name="infoLabel"> <widget class="QLabel" name="infoLabel">
@@ -203,6 +203,12 @@ Partial names can be used if they are unambiguous.</string>
<extends>QComboBox</extends> <extends>QComboBox</extends>
<header location="global">git/gerrit/branchcombobox.h</header> <header location="global">git/gerrit/branchcombobox.h</header>
</customwidget> </customwidget>
<customwidget>
<class>Gerrit::Internal::GerritRemoteChooser</class>
<extends>QWidget</extends>
<header location="global">git/gerrit/gerritremotechooser.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>localBranchComboBox</tabstop> <tabstop>localBranchComboBox</tabstop>

View File

@@ -51,6 +51,7 @@ GerritRemoteChooser::GerritRemoteChooser(QWidget *parent) :
m_remoteComboBox->setMinimumSize(QSize(40, 0)); m_remoteComboBox->setMinimumSize(QSize(40, 0));
horizontalLayout->addWidget(m_remoteComboBox); horizontalLayout->addWidget(m_remoteComboBox);
horizontalLayout->setMargin(0);
m_resetRemoteButton = new QToolButton(this); m_resetRemoteButton = new QToolButton(this);
m_resetRemoteButton->setToolTip(tr("Refresh Remote Servers")); m_resetRemoteButton->setToolTip(tr("Refresh Remote Servers"));
@@ -74,6 +75,22 @@ void GerritRemoteChooser::setParameters(QSharedPointer<GerritParameters> paramet
m_parameters = parameters; m_parameters = parameters;
} }
void GerritRemoteChooser::setFallbackEnabled(bool value)
{
m_enableFallback = value;
}
bool GerritRemoteChooser::setCurrentRemote(const QString &remoteName)
{
for (int i = 0, total = m_remoteComboBox->count(); i < total; ++i) {
if (m_remotes[i].first == remoteName) {
m_remoteComboBox->setCurrentIndex(i);
return true;
}
}
return false;
}
bool GerritRemoteChooser::updateRemotes(bool forceReload) bool GerritRemoteChooser::updateRemotes(bool forceReload)
{ {
QTC_ASSERT(!m_repository.isEmpty() || !m_parameters, return false); QTC_ASSERT(!m_repository.isEmpty() || !m_parameters, return false);
@@ -91,7 +108,9 @@ bool GerritRemoteChooser::updateRemotes(bool forceReload)
continue; continue;
addRemote(server, mapIt.key()); addRemote(server, mapIt.key());
} }
addRemote(m_parameters->server, tr("Fallback")); if (m_enableFallback)
addRemote(m_parameters->server, tr("Fallback"));
m_remoteComboBox->setEnabled(m_remoteComboBox->count() > 1);
m_updatingRemotes = false; m_updatingRemotes = false;
handleRemoteChanged(); handleRemoteChanged();
return true; return true;
@@ -116,6 +135,18 @@ GerritServer GerritRemoteChooser::currentServer() const
return m_remotes[index].second; return m_remotes[index].second;
} }
QString GerritRemoteChooser::currentRemoteName() const
{
const int index = m_remoteComboBox->currentIndex();
QTC_ASSERT(index >= 0 && index < int(m_remotes.size()), return QString());
return m_remotes[index].first;
}
bool GerritRemoteChooser::isEmpty() const
{
return m_remotes.empty();
}
void GerritRemoteChooser::handleRemoteChanged() void GerritRemoteChooser::handleRemoteChanged()
{ {
if (m_updatingRemotes || m_remotes.empty()) if (m_updatingRemotes || m_remotes.empty())

View File

@@ -47,9 +47,13 @@ public:
GerritRemoteChooser(QWidget *parent = nullptr); GerritRemoteChooser(QWidget *parent = nullptr);
void setRepository(const QString &repository); void setRepository(const QString &repository);
void setParameters(QSharedPointer<GerritParameters> parameters); void setParameters(QSharedPointer<GerritParameters> parameters);
void setFallbackEnabled(bool value);
bool setCurrentRemote(const QString &remoteName);
bool updateRemotes(bool forceReload); bool updateRemotes(bool forceReload);
GerritServer currentServer() const; GerritServer currentServer() const;
QString currentRemoteName() const;
bool isEmpty() const;
signals: signals:
void remoteChanged(); void remoteChanged();
@@ -63,6 +67,7 @@ private:
QComboBox *m_remoteComboBox = nullptr; QComboBox *m_remoteComboBox = nullptr;
QToolButton *m_resetRemoteButton = nullptr; QToolButton *m_resetRemoteButton = nullptr;
bool m_updatingRemotes = false; bool m_updatingRemotes = false;
bool m_enableFallback = false;
using NameAndServer = std::pair<QString, GerritServer>; using NameAndServer = std::pair<QString, GerritServer>;
std::vector<NameAndServer> m_remotes; std::vector<NameAndServer> m_remotes;
}; };