Git: inline branchadddialog.h

Change-Id: I8919f69bfdfd670855167bace62fb55603595270
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2022-08-04 12:54:02 +02:00
parent 321fae46f6
commit 03035feac3
5 changed files with 63 additions and 129 deletions

View File

@@ -24,13 +24,19 @@
****************************************************************************/
#include "branchadddialog.h"
#include "branchmodel.h"
#include "ui_branchadddialog.h"
#include "gitplugin.h"
#include <utils/fancylineedit.h>
#include <utils/hostosinfo.h>
#include <utils/layoutbuilder.h>
#include <QApplication>
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QRegularExpression>
#include <QValidator>
@@ -106,11 +112,22 @@ QWidget *BranchValidationDelegate::createEditor(QWidget *parent,
}
BranchAddDialog::BranchAddDialog(const QStringList &localBranches, Type type, QWidget *parent) :
QDialog(parent),
m_ui(new Ui::BranchAddDialog)
QDialog(parent)
{
m_ui->setupUi(this);
m_ui->trackingCheckBox->setVisible(false);
resize(590, 138);
auto branchNameLabel = new QLabel(tr("Branch Name:"));
m_branchNameEdit = new QLineEdit(this);
m_branchNameEdit->setValidator(new BranchNameValidator(localBranches, this));
m_checkoutCheckBox = new QCheckBox(tr("Checkout new branch"));
m_trackingCheckBox = new QCheckBox(this);
m_trackingCheckBox->setVisible(false);
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
setCheckoutVisible(false);
switch (type) {
@@ -122,67 +139,75 @@ BranchAddDialog::BranchAddDialog(const QStringList &localBranches, Type type, QW
break;
case BranchAddDialog::AddTag:
setWindowTitle(tr("Add Tag"));
m_ui->branchNameLabel->setText(tr("Tag name:"));
branchNameLabel->setText(tr("Tag name:"));
break;
case BranchAddDialog::RenameTag:
setWindowTitle(tr("Rename Tag"));
m_ui->branchNameLabel->setText(tr("Tag name:"));
branchNameLabel->setText(tr("Tag name:"));
break;
}
m_ui->branchNameEdit->setValidator(new BranchNameValidator(localBranches, this));
connect(m_ui->branchNameEdit, &QLineEdit::textChanged, this, &BranchAddDialog::updateButtonStatus);
using namespace Utils::Layouting;
Column {
Row { branchNameLabel, m_branchNameEdit },
m_checkoutCheckBox,
m_trackingCheckBox,
st,
m_buttonBox
}.attachTo(this);
connect(m_branchNameEdit, &QLineEdit::textChanged, this, &BranchAddDialog::updateButtonStatus);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
BranchAddDialog::~BranchAddDialog()
{
delete m_ui;
}
BranchAddDialog::~BranchAddDialog() = default;
void BranchAddDialog::setBranchName(const QString &n)
{
m_ui->branchNameEdit->setText(n);
m_ui->branchNameEdit->selectAll();
m_branchNameEdit->setText(n);
m_branchNameEdit->selectAll();
}
QString BranchAddDialog::branchName() const
{
return m_ui->branchNameEdit->text();
return m_branchNameEdit->text();
}
void BranchAddDialog::setTrackedBranchName(const QString &name, bool remote)
{
if (name.isEmpty()) {
m_ui->trackingCheckBox->setVisible(false);
m_ui->trackingCheckBox->setChecked(false);
m_trackingCheckBox->setVisible(false);
m_trackingCheckBox->setChecked(false);
} else {
m_ui->trackingCheckBox->setText(remote ? tr("Track remote branch \"%1\"").arg(name) :
tr("Track local branch \"%1\"").arg(name));
m_ui->trackingCheckBox->setVisible(true);
m_ui->trackingCheckBox->setChecked(remote);
m_trackingCheckBox->setText(remote ? tr("Track remote branch \"%1\"").arg(name)
: tr("Track local branch \"%1\"").arg(name));
m_trackingCheckBox->setVisible(true);
m_trackingCheckBox->setChecked(remote);
}
}
bool BranchAddDialog::track() const
{
return m_ui->trackingCheckBox->isChecked();
return m_trackingCheckBox->isChecked();
}
void BranchAddDialog::setCheckoutVisible(bool visible)
{
m_ui->checkoutCheckBox->setVisible(visible);
m_ui->checkoutCheckBox->setChecked(visible);
m_checkoutCheckBox->setVisible(visible);
m_checkoutCheckBox->setChecked(visible);
}
bool BranchAddDialog::checkout() const
{
return m_ui->checkoutCheckBox->isChecked();
return m_checkoutCheckBox->isChecked();
}
/*! Updates the ok button enabled state of the dialog according to the validity of the branch name. */
void BranchAddDialog::updateButtonStatus()
{
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_ui->branchNameEdit->hasAcceptableInput());
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_branchNameEdit->hasAcceptableInput());
}
} // namespace Internal