Git: inline remote*.ui

Change-Id: Idb394e69d3976877d091a5cf65a3babfbafe9e6b
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2022-08-05 12:52:16 +02:00
parent 9ad5c4254d
commit 7070e89904
7 changed files with 114 additions and 303 deletions

View File

@@ -28,15 +28,24 @@
#include "gitclient.h"
#include "gitplugin.h"
#include "remotemodel.h"
#include "ui_remotedialog.h"
#include "ui_remoteadditiondialog.h"
#include <utils/fancylineedit.h>
#include <utils/headerviewstretcher.h>
#include <utils/layoutbuilder.h>
#include <vcsbase/vcsoutputwindow.h>
#include <QApplication>
#include <QApplication>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QRegularExpression>
#include <QTreeView>
using namespace Utils;
@@ -54,9 +63,11 @@ public:
m_invalidRemoteNameChars(GitPlugin::invalidBranchAndRemoteNamePattern()),
m_remoteNames(remoteNames)
{
m_ui.setupUi(this);
m_ui.nameEdit->setHistoryCompleter("Git.RemoteNames");
m_ui.nameEdit->setValidationFunction([this](Utils::FancyLineEdit *edit, QString *errorMessage) {
resize(381, 93);
m_nameEdit = new FancyLineEdit(this);
m_nameEdit->setHistoryCompleter("Git.RemoteNames");
m_nameEdit->setValidationFunction([this](FancyLineEdit *edit, QString *errorMessage) {
if (!edit)
return false;
@@ -83,12 +94,10 @@ public:
// is a valid remote name
return !input.isEmpty();
});
connect(m_ui.nameEdit, &QLineEdit::textChanged, [this]() {
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_ui.nameEdit->isValid());
});
m_ui.urlEdit->setHistoryCompleter("Git.RemoteUrls");
m_ui.urlEdit->setValidationFunction([](Utils::FancyLineEdit *edit, QString *errorMessage) {
m_urlEdit = new FancyLineEdit(this);
m_urlEdit->setHistoryCompleter("Git.RemoteUrls");
m_urlEdit->setValidationFunction([](FancyLineEdit *edit, QString *errorMessage) {
if (!edit || edit->text().isEmpty())
return false;
@@ -99,21 +108,38 @@ public:
return r.isValid;
});
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
using namespace Layouting;
Grid {
tr("Name:"), m_nameEdit, br,
tr("URL:"), m_urlEdit, br,
Span(2, buttonBox)
}.attachTo(this);
connect(m_nameEdit, &QLineEdit::textChanged, [this, buttonBox] {
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_nameEdit->isValid());
});
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
}
QString remoteName() const
{
return m_ui.nameEdit->text();
return m_nameEdit->text();
}
QString remoteUrl() const
{
return m_ui.urlEdit->text();
return m_urlEdit->text();
}
private:
Ui::RemoteAdditionDialog m_ui;
FancyLineEdit *m_nameEdit;
FancyLineEdit *m_urlEdit;
const QRegularExpression m_invalidRemoteNameChars;
QStringList m_remoteNames;
};
@@ -126,42 +152,78 @@ private:
RemoteDialog::RemoteDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::RemoteDialog),
m_remoteModel(new RemoteModel(this))
{
setModal(false);
setAttribute(Qt::WA_DeleteOnClose, true); // Do not update unnecessarily
setWindowTitle(tr("Remotes"));
m_ui->setupUi(this);
m_repositoryLabel = new QLabel;
m_ui->remoteView->setModel(m_remoteModel);
new Utils::HeaderViewStretcher(m_ui->remoteView->header(), 1);
auto refreshButton = new QPushButton(tr("Re&fresh"));
refreshButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
connect(m_ui->addButton, &QPushButton::clicked, this, &RemoteDialog::addRemote);
connect(m_ui->fetchButton, &QPushButton::clicked, this, &RemoteDialog::fetchFromRemote);
connect(m_ui->pushButton, &QPushButton::clicked, this, &RemoteDialog::pushToRemote);
connect(m_ui->removeButton, &QPushButton::clicked, this, &RemoteDialog::removeRemote);
connect(m_ui->refreshButton, &QPushButton::clicked, this, &RemoteDialog::refreshRemotes);
m_remoteView = new QTreeView;
m_remoteView->setMinimumSize(QSize(0, 100));
m_remoteView->setEditTriggers(QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
m_remoteView->setSelectionMode(QAbstractItemView::SingleSelection);
m_remoteView->setSelectionBehavior(QAbstractItemView::SelectRows);
m_remoteView->setRootIsDecorated(false);
m_remoteView->setUniformRowHeights(true);
m_remoteView->setModel(m_remoteModel);
new HeaderViewStretcher(m_remoteView->header(), 1);
connect(m_ui->remoteView->selectionModel(), &QItemSelectionModel::selectionChanged,
m_addButton = new QPushButton(tr("&Add..."));
m_addButton->setAutoDefault(false);
m_fetchButton = new QPushButton(tr("F&etch"));
m_pushButton = new QPushButton(tr("&Push"));
m_removeButton = new QPushButton(tr("&Remove"));
m_removeButton->setAutoDefault(false);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
using namespace Layouting;
Column {
Group {
Row { m_repositoryLabel, refreshButton }
},
Group {
title(tr("Remotes")),
Column {
m_remoteView,
Row { st, m_addButton, m_fetchButton, m_pushButton, m_removeButton }
}
},
buttonBox,
}.attachTo(this);
connect(m_addButton, &QPushButton::clicked, this, &RemoteDialog::addRemote);
connect(m_fetchButton, &QPushButton::clicked, this, &RemoteDialog::fetchFromRemote);
connect(m_pushButton, &QPushButton::clicked, this, &RemoteDialog::pushToRemote);
connect(m_removeButton, &QPushButton::clicked, this, &RemoteDialog::removeRemote);
connect(refreshButton, &QPushButton::clicked, this, &RemoteDialog::refreshRemotes);
connect(m_remoteView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &RemoteDialog::updateButtonState);
connect(m_remoteModel, &RemoteModel::refreshed,
this, &RemoteDialog::updateButtonState);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
updateButtonState();
}
RemoteDialog::~RemoteDialog()
{
delete m_ui;
}
RemoteDialog::~RemoteDialog() = default;
void RemoteDialog::refresh(const FilePath &repository, bool force)
{
if (m_remoteModel->workingDirectory() == repository && !force)
return;
// Refresh
m_ui->repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository));
m_repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository));
if (repository.isEmpty()) {
m_remoteModel->clear();
} else {
@@ -187,7 +249,7 @@ void RemoteDialog::addRemote()
void RemoteDialog::removeRemote()
{
const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes();
const QModelIndexList indexList = m_remoteView->selectionModel()->selectedIndexes();
if (indexList.isEmpty())
return;
@@ -203,7 +265,7 @@ void RemoteDialog::removeRemote()
void RemoteDialog::pushToRemote()
{
const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes();
const QModelIndexList indexList = m_remoteView->selectionModel()->selectedIndexes();
if (indexList.isEmpty())
return;
@@ -214,7 +276,7 @@ void RemoteDialog::pushToRemote()
void RemoteDialog::fetchFromRemote()
{
const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes();
const QModelIndexList indexList = m_remoteView->selectionModel()->selectedIndexes();
if (indexList.isEmpty())
return;
@@ -225,13 +287,13 @@ void RemoteDialog::fetchFromRemote()
void RemoteDialog::updateButtonState()
{
const QModelIndexList indexList = m_ui->remoteView->selectionModel()->selectedIndexes();
const QModelIndexList indexList = m_remoteView->selectionModel()->selectedIndexes();
const bool haveSelection = !indexList.isEmpty();
m_ui->addButton->setEnabled(true);
m_ui->fetchButton->setEnabled(haveSelection);
m_ui->pushButton->setEnabled(haveSelection);
m_ui->removeButton->setEnabled(haveSelection);
m_addButton->setEnabled(true);
m_fetchButton->setEnabled(haveSelection);
m_pushButton->setEnabled(haveSelection);
m_removeButton->setEnabled(haveSelection);
}
} // namespace Internal