Gerrit: Remove repo selection from the dialog

Behave like the Branches dialog, which is updated by the current open file.

Change-Id: Id106b3e4fa777bcbf08b826f4e7d52845dde57a6
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Orgad Shaneh
2017-02-04 22:06:58 +02:00
committed by Orgad Shaneh
parent ffbc331168
commit f77af5e336
5 changed files with 51 additions and 45 deletions

View File

@@ -41,6 +41,7 @@
#include <QCompleter> #include <QCompleter>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFileInfo>
#include <QPushButton> #include <QPushButton>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStringListModel> #include <QStringListModel>
@@ -67,6 +68,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_ui->setupUi(this); m_ui->setupUi(this);
setCurrentPath(repository);
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);
@@ -106,10 +108,6 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
connect(m_ui->treeView, &QAbstractItemView::activated, connect(m_ui->treeView, &QAbstractItemView::activated,
this, &GerritDialog::slotActivated); this, &GerritDialog::slotActivated);
m_ui->repositoryChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
m_ui->repositoryChooser->setHistoryCompleter("Git.RepoDir.History");
m_ui->repositoryChooser->setPath(repository);
m_displayButton = addActionButton(tr("&Show"), [this]() { slotFetchDisplay(); }); m_displayButton = addActionButton(tr("&Show"), [this]() { slotFetchDisplay(); });
m_cherryPickButton = addActionButton(tr("Cherry &Pick"), [this]() { slotFetchCherryPick(); }); m_cherryPickButton = addActionButton(tr("Cherry &Pick"), [this]() { slotFetchCherryPick(); });
m_checkoutButton = addActionButton(tr("C&heckout"), [this]() { slotFetchCheckout(); }); m_checkoutButton = addActionButton(tr("C&heckout"), [this]() { slotFetchCheckout(); });
@@ -129,12 +127,15 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
QString GerritDialog::repositoryPath() const QString GerritDialog::repositoryPath() const
{ {
return m_ui->repositoryChooser->path(); return m_repository;
} }
void GerritDialog::setCurrentPath(const QString &path) void GerritDialog::setCurrentPath(const QString &path)
{ {
m_ui->repositoryChooser->setPath(path); if (path == m_repository)
return;
m_repository = path;
m_ui->repositoryLabel->setText(Git::Internal::GitPlugin::msgRepositoryLabel(path));
} }
QPushButton *GerritDialog::addActionButton(const QString &text, QPushButton *GerritDialog::addActionButton(const QString &text,
@@ -211,16 +212,14 @@ void GerritDialog::slotRefresh()
void GerritDialog::updateRemote() void GerritDialog::updateRemote()
{ {
const QString repository = m_ui->repositoryChooser->path(); if (m_repository.isEmpty() || !QFileInfo(m_repository).isDir())
if (m_repository == repository || !m_ui->repositoryChooser->isValid())
return; return;
static const QRegularExpression sshPattern( static const QRegularExpression sshPattern(
"^(?:(?<protocol>[^:]+)://)?(?:(?<user>[^@]+)@)?(?<host>[^:/]+)(?::(?<port>\\d+))?"); "^(?:(?<protocol>[^:]+)://)?(?:(?<user>[^@]+)@)?(?<host>[^:/]+)(?::(?<port>\\d+))?");
m_repository = repository;
*m_server = m_parameters->server; *m_server = m_parameters->server;
QString errorMessage; // Mute errors. We'll just fallback to the defaults QString errorMessage; // Mute errors. We'll just fallback to the defaults
QMap<QString, QString> remotesList = QMap<QString, QString> remotesList =
Git::Internal::GitPlugin::client()->synchronousRemotesList(repository, &errorMessage); Git::Internal::GitPlugin::client()->synchronousRemotesList(m_repository, &errorMessage);
QStringList remoteUrls; QStringList remoteUrls;
// Prefer a remote named gerrit // Prefer a remote named gerrit
const QString gerritRemote = remotesList.value("gerrit"); const QString gerritRemote = remotesList.value("gerrit");

View File

@@ -7,13 +7,43 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>950</width> <width>950</width>
<height>672</height> <height>700</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Gerrit</string> <string>Gerrit</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="repositoryLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">Repository: Dummy</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item> <item>
<widget class="QWidget" name="widget" native="true"> <widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
@@ -161,26 +191,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="repositoryChooserLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Apply in:</string>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="repositoryChooser" native="true"/>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
@@ -211,12 +221,6 @@
<extends>QTreeView</extends> <extends>QTreeView</extends>
<header location="global">utils/itemviews.h</header> <header location="global">utils/itemviews.h</header>
</customwidget> </customwidget>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections> <connections>

View File

@@ -297,10 +297,13 @@ bool GerritPlugin::initialize(ActionContainer *ac)
return true; return true;
} }
void GerritPlugin::updateActions(bool hasTopLevel) void GerritPlugin::updateActions(const VcsBase::VcsBasePluginState &state)
{ {
const bool hasTopLevel = state.hasTopLevel();
m_gerritCommand->action()->setEnabled(hasTopLevel); m_gerritCommand->action()->setEnabled(hasTopLevel);
m_pushToGerritCommand->action()->setEnabled(hasTopLevel); m_pushToGerritCommand->action()->setEnabled(hasTopLevel);
if (m_dialog)
m_dialog->setCurrentPath(state.topLevel());
} }
void GerritPlugin::addToLocator(CommandLocator *locator) void GerritPlugin::addToLocator(CommandLocator *locator)
@@ -349,7 +352,6 @@ void GerritPlugin::push(const QString &topLevel)
// Open or raise the Gerrit dialog window. // Open or raise the Gerrit dialog window.
void GerritPlugin::openView() void GerritPlugin::openView()
{ {
const QString repository = GitPlugin::instance()->currentState().topLevel();
if (m_dialog.isNull()) { if (m_dialog.isNull()) {
while (!m_parameters->isValid()) { while (!m_parameters->isValid()) {
Core::AsynchronousMessageBox::warning(tr("Error"), Core::AsynchronousMessageBox::warning(tr("Error"),
@@ -357,6 +359,7 @@ void GerritPlugin::openView()
if (!ICore::showOptionsDialog("Gerrit")) if (!ICore::showOptionsDialog("Gerrit"))
return; return;
} }
const QString repository = GitPlugin::instance()->currentState().topLevel();
GerritDialog *gd = new GerritDialog(m_parameters, m_server, repository, ICore::mainWindow()); GerritDialog *gd = new GerritDialog(m_parameters, m_server, repository, ICore::mainWindow());
gd->setModal(false); gd->setModal(false);
connect(gd, &GerritDialog::fetchDisplay, this, connect(gd, &GerritDialog::fetchDisplay, this,
@@ -369,8 +372,6 @@ void GerritPlugin::openView()
connect(this, &GerritPlugin::fetchFinished, gd, &GerritDialog::fetchFinished); connect(this, &GerritPlugin::fetchFinished, gd, &GerritDialog::fetchFinished);
m_dialog = gd; m_dialog = gd;
} }
if (!m_dialog->isVisible())
m_dialog->setCurrentPath(repository);
const Qt::WindowStates state = m_dialog->windowState(); const Qt::WindowStates state = m_dialog->windowState();
if (state & Qt::WindowMinimized) if (state & Qt::WindowMinimized)
m_dialog->setWindowState(state & ~Qt::WindowMinimized); m_dialog->setWindowState(state & ~Qt::WindowMinimized);
@@ -406,7 +407,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
QString repository; QString repository;
bool verifiedRepository = false; bool verifiedRepository = false;
if (!m_dialog.isNull() && !m_parameters.isNull() && QFile::exists(m_dialog->repositoryPath())) if (!m_dialog.isNull() && !m_parameters.isNull() && QFile::exists(m_dialog->repositoryPath()))
repository = VcsManager::findTopLevelForDirectory(m_dialog->repositoryPath()); repository = m_dialog->repositoryPath();
if (!repository.isEmpty()) { if (!repository.isEmpty()) {
// Check if remote from a working dir is the same as remote from patch // Check if remote from a working dir is the same as remote from patch

View File

@@ -42,6 +42,8 @@ class Command;
class CommandLocator; class CommandLocator;
} }
namespace VcsBase { class VcsBasePluginState; }
namespace Gerrit { namespace Gerrit {
namespace Internal { namespace Internal {
@@ -64,7 +66,7 @@ public:
void addToLocator(Core::CommandLocator *locator); void addToLocator(Core::CommandLocator *locator);
void push(const QString &topLevel); void push(const QString &topLevel);
void updateActions(bool hasTopLevel); void updateActions(const VcsBase::VcsBasePluginState &state);
signals: signals:
void fetchStarted(const QSharedPointer<Gerrit::Internal::GerritChange> &change); void fetchStarted(const QSharedPointer<Gerrit::Internal::GerritChange> &change);

View File

@@ -647,7 +647,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
/* "Gerrit" */ /* "Gerrit" */
m_gerritPlugin = new Gerrit::Internal::GerritPlugin(this); m_gerritPlugin = new Gerrit::Internal::GerritPlugin(this);
const bool ok = m_gerritPlugin->initialize(remoteRepositoryMenu); const bool ok = m_gerritPlugin->initialize(remoteRepositoryMenu);
m_gerritPlugin->updateActions(currentState().hasTopLevel()); m_gerritPlugin->updateActions(currentState());
m_gerritPlugin->addToLocator(m_commandLocator); m_gerritPlugin->addToLocator(m_commandLocator);
return ok; return ok;
@@ -1354,7 +1354,7 @@ void GitPlugin::updateActions(VcsBasePlugin::ActionState as)
updateContinueAndAbortCommands(); updateContinueAndAbortCommands();
updateRepositoryBrowserAction(); updateRepositoryBrowserAction();
m_gerritPlugin->updateActions(repositoryEnabled); m_gerritPlugin->updateActions(state);
} }
void GitPlugin::updateContinueAndAbortCommands() void GitPlugin::updateContinueAndAbortCommands()