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

@@ -2,7 +2,7 @@ add_qtc_plugin(Git
PLUGIN_DEPENDS Core DiffEditor TextEditor VcsBase
SOURCES
annotationhighlighter.cpp annotationhighlighter.h
branchadddialog.cpp branchadddialog.h branchadddialog.ui
branchadddialog.cpp branchadddialog.h
branchcheckoutdialog.cpp branchcheckoutdialog.h branchcheckoutdialog.ui
branchmodel.cpp branchmodel.h
branchview.cpp branchview.h

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

View File

@@ -28,13 +28,17 @@
#include <QDialog>
#include <QItemDelegate>
QT_BEGIN_NAMESPACE
class QCheckBox;
class QDialogButtonBox;
class QLineEdit;
QT_BEGIN_NAMESPACE
namespace Git {
namespace Internal {
class BranchModel;
namespace Ui { class BranchAddDialog; }
class BranchValidationDelegate : public QItemDelegate
{
public:
@@ -74,7 +78,10 @@ public:
private:
void updateButtonStatus();
Ui::BranchAddDialog *m_ui;
QLineEdit *m_branchNameEdit;
QCheckBox *m_checkoutCheckBox;
QCheckBox *m_trackingCheckBox;
QDialogButtonBox *m_buttonBox;
};
} // namespace Internal

View File

@@ -1,97 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Git::Internal::BranchAddDialog</class>
<widget class="QDialog" name="Git::Internal::BranchAddDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>590</width>
<height>138</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="branchNameLabel">
<property name="text">
<string>Branch Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="branchNameEdit"/>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkoutCheckBox">
<property name="text">
<string>Checkout new branch</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="trackingCheckBox"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Git::Internal::BranchAddDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Git::Internal::BranchAddDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -18,7 +18,6 @@ QtcPlugin {
"annotationhighlighter.h",
"branchadddialog.cpp",
"branchadddialog.h",
"branchadddialog.ui",
"branchcheckoutdialog.cpp",
"branchcheckoutdialog.h",
"branchcheckoutdialog.ui",