Git: Allow direct checkout in add branch dialog

Avoid one modal message box by adding a checkbox in the
dialog. In case the user misses to check the box, the
branch can still be checked out later with the context
menu action "checkout".

Change-Id: I51262e694aad9f55511beefa0d8d23ea66429664
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
Andre Hartmann
2018-11-25 20:10:25 +01:00
committed by André Hartmann
parent f4db8e9c6a
commit e77729a05a
4 changed files with 28 additions and 7 deletions

View File

@@ -110,6 +110,7 @@ BranchAddDialog::BranchAddDialog(const QStringList &localBranches, bool addBranc
m_ui(new Ui::BranchAddDialog)
{
m_ui->setupUi(this);
setCheckoutVisible(false);
setWindowTitle(addBranch ? tr("Add Branch") : tr("Rename Branch"));
m_ui->branchNameEdit->setValidator(new BranchNameValidator(localBranches, this));
connect(m_ui->branchNameEdit, &QLineEdit::textChanged, this, &BranchAddDialog::updateButtonStatus);
@@ -149,6 +150,17 @@ bool BranchAddDialog::track() const
return m_ui->trackingCheckBox->isChecked();
}
void BranchAddDialog::setCheckoutVisible(bool visible)
{
m_ui->checkoutCheckBox->setVisible(visible);
m_ui->checkoutCheckBox->setChecked(visible);
}
bool BranchAddDialog::checkout() const
{
return m_ui->checkoutCheckBox->isChecked();
}
/*! Updates the ok button enabled state of the dialog according to the validity of the branch name. */
void BranchAddDialog::updateButtonStatus()
{

View File

@@ -61,6 +61,9 @@ public:
bool track() const;
void setCheckoutVisible(bool visible);
bool checkout() const;
private:
void updateButtonStatus();

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>134</height>
<height>138</height>
</rect>
</property>
<property name="windowTitle">
@@ -24,14 +24,21 @@
<item row="0" column="1">
<widget class="QLineEdit" name="branchNameEdit"/>
</item>
<item row="1" column="0" colspan="2">
<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">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -41,7 +48,7 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>

View File

@@ -316,6 +316,7 @@ bool BranchView::add()
BranchAddDialog branchAddDialog(localNames, true, this);
branchAddDialog.setBranchName(suggestedName);
branchAddDialog.setTrackedBranchName(isTracked ? trackedBranch : QString(), !isLocal);
branchAddDialog.setCheckoutVisible(true);
if (branchAddDialog.exec() == QDialog::Accepted) {
QModelIndex idx = m_model->addBranch(branchAddDialog.branchName(), branchAddDialog.track(),
@@ -328,10 +329,8 @@ bool BranchView::add()
| QItemSelectionModel::Select
| QItemSelectionModel::Current);
m_branchView->scrollTo(mappedIdx);
if (QMessageBox::question(this, tr("Checkout"), tr("Checkout branch?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
if (branchAddDialog.checkout())
return checkout();
}
}
return false;