Commit f77af5e3 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

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: default avatarAndré Hartmann <aha_1980@gmx.de>
Reviewed-by: Riitta-Leena Miettinen's avatarLeena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent ffbc3311
......@@ -41,6 +41,7 @@
#include <QCompleter>
#include <QDesktopServices>
#include <QFileInfo>
#include <QPushButton>
#include <QSortFilterProxyModel>
#include <QStringListModel>
......@@ -67,6 +68,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_ui->setupUi(this);
setCurrentPath(repository);
m_queryModel->setStringList(m_parameters->savedQueries);
QCompleter *completer = new QCompleter(this);
completer->setModel(m_queryModel);
......@@ -106,10 +108,6 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
connect(m_ui->treeView, &QAbstractItemView::activated,
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_cherryPickButton = addActionButton(tr("Cherry &Pick"), [this]() { slotFetchCherryPick(); });
m_checkoutButton = addActionButton(tr("C&heckout"), [this]() { slotFetchCheckout(); });
......@@ -129,12 +127,15 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
QString GerritDialog::repositoryPath() const
{
return m_ui->repositoryChooser->path();
return m_repository;
}
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,
......@@ -211,16 +212,14 @@ void GerritDialog::slotRefresh()
void GerritDialog::updateRemote()
{
const QString repository = m_ui->repositoryChooser->path();
if (m_repository == repository || !m_ui->repositoryChooser->isValid())
if (m_repository.isEmpty() || !QFileInfo(m_repository).isDir())
return;
static const QRegularExpression sshPattern(
"^(?:(?<protocol>[^:]+)://)?(?:(?<user>[^@]+)@)?(?<host>[^:/]+)(?::(?<port>\\d+))?");
m_repository = repository;
*m_server = m_parameters->server;
QString errorMessage; // Mute errors. We'll just fallback to the defaults
QMap<QString, QString> remotesList =
Git::Internal::GitPlugin::client()->synchronousRemotesList(repository, &errorMessage);
Git::Internal::GitPlugin::client()->synchronousRemotesList(m_repository, &errorMessage);
QStringList remoteUrls;
// Prefer a remote named gerrit
const QString gerritRemote = remotesList.value("gerrit");
......
......@@ -7,13 +7,43 @@
<x>0</x>
<y>0</y>
<width>950</width>
<height>672</height>
<height>700</height>
</rect>
</property>
<property name="windowTitle">
<string>Gerrit</string>
</property>
<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>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
......@@ -161,26 +191,6 @@
</property>
</widget>
</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>
</widget>
</widget>
......@@ -211,12 +221,6 @@
<extends>QTreeView</extends>
<header location="global">utils/itemviews.h</header>
</customwidget>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
......
......@@ -297,10 +297,13 @@ bool GerritPlugin::initialize(ActionContainer *ac)
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_pushToGerritCommand->action()->setEnabled(hasTopLevel);
if (m_dialog)
m_dialog->setCurrentPath(state.topLevel());
}
void GerritPlugin::addToLocator(CommandLocator *locator)
......@@ -349,7 +352,6 @@ void GerritPlugin::push(const QString &topLevel)
// Open or raise the Gerrit dialog window.
void GerritPlugin::openView()
{
const QString repository = GitPlugin::instance()->currentState().topLevel();
if (m_dialog.isNull()) {
while (!m_parameters->isValid()) {
Core::AsynchronousMessageBox::warning(tr("Error"),
......@@ -357,6 +359,7 @@ void GerritPlugin::openView()
if (!ICore::showOptionsDialog("Gerrit"))
return;
}
const QString repository = GitPlugin::instance()->currentState().topLevel();
GerritDialog *gd = new GerritDialog(m_parameters, m_server, repository, ICore::mainWindow());
gd->setModal(false);
connect(gd, &GerritDialog::fetchDisplay, this,
......@@ -369,8 +372,6 @@ void GerritPlugin::openView()
connect(this, &GerritPlugin::fetchFinished, gd, &GerritDialog::fetchFinished);
m_dialog = gd;
}
if (!m_dialog->isVisible())
m_dialog->setCurrentPath(repository);
const Qt::WindowStates state = m_dialog->windowState();
if (state & Qt::WindowMinimized)
m_dialog->setWindowState(state & ~Qt::WindowMinimized);
......@@ -406,7 +407,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
QString repository;
bool verifiedRepository = false;
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()) {
// Check if remote from a working dir is the same as remote from patch
......
......@@ -42,6 +42,8 @@ class Command;
class CommandLocator;
}
namespace VcsBase { class VcsBasePluginState; }
namespace Gerrit {
namespace Internal {
......@@ -64,7 +66,7 @@ public:
void addToLocator(Core::CommandLocator *locator);
void push(const QString &topLevel);
void updateActions(bool hasTopLevel);
void updateActions(const VcsBase::VcsBasePluginState &state);
signals:
void fetchStarted(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
......
......@@ -647,7 +647,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
/* "Gerrit" */
m_gerritPlugin = new Gerrit::Internal::GerritPlugin(this);
const bool ok = m_gerritPlugin->initialize(remoteRepositoryMenu);
m_gerritPlugin->updateActions(currentState().hasTopLevel());
m_gerritPlugin->updateActions(currentState());
m_gerritPlugin->addToLocator(m_commandLocator);
return ok;
......@@ -1354,7 +1354,7 @@ void GitPlugin::updateActions(VcsBasePlugin::ActionState as)
updateContinueAndAbortCommands();
updateRepositoryBrowserAction();
m_gerritPlugin->updateActions(repositoryEnabled);
m_gerritPlugin->updateActions(state);
}
void GitPlugin::updateContinueAndAbortCommands()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment