forked from qt-creator/qt-creator
Git: added rename branch
Change-Id: I327a2bc91b871dc03797d9af52bb2d32be8e76d2 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -95,11 +95,12 @@ private:
|
||||
};
|
||||
|
||||
|
||||
BranchAddDialog::BranchAddDialog(QWidget *parent) :
|
||||
BranchAddDialog::BranchAddDialog(QWidget *parent, bool addBranch) :
|
||||
QDialog(parent),
|
||||
m_ui(new Ui::BranchAddDialog)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
setWindowTitle(addBranch ? tr("Add Branch") : tr("Rename Branch"));
|
||||
m_ui->branchNameEdit->setValidator(new BranchNameValidator(this));
|
||||
connect(m_ui->branchNameEdit, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStatus()));
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class BranchAddDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BranchAddDialog(QWidget *parent = 0);
|
||||
explicit BranchAddDialog(QWidget *parent = 0, bool addBranch = true);
|
||||
~BranchAddDialog();
|
||||
|
||||
void setBranchName(const QString &);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Add Branch</string>
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
|
||||
@@ -64,6 +64,7 @@ BranchDialog::BranchDialog(QWidget *parent) :
|
||||
connect(m_ui->addButton, SIGNAL(clicked()), this, SLOT(add()));
|
||||
connect(m_ui->checkoutButton, SIGNAL(clicked()), this, SLOT(checkout()));
|
||||
connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(remove()));
|
||||
connect(m_ui->renameButton, SIGNAL(clicked()), this, SLOT(rename()));
|
||||
connect(m_ui->diffButton, SIGNAL(clicked()), this, SLOT(diff()));
|
||||
connect(m_ui->logButton, SIGNAL(clicked()), this, SLOT(log()));
|
||||
connect(m_ui->mergeButton, SIGNAL(clicked()), this, SLOT(merge()));
|
||||
@@ -106,6 +107,7 @@ void BranchDialog::enableButtons()
|
||||
const bool currentLocal = m_model->isLocal(m_model->currentBranch());
|
||||
|
||||
m_ui->removeButton->setEnabled(hasSelection && !currentSelected && isLocal && isLeaf);
|
||||
m_ui->renameButton->setEnabled(hasSelection && isLocal && isLeaf);
|
||||
m_ui->logButton->setEnabled(hasSelection && isLeaf);
|
||||
m_ui->diffButton->setEnabled(hasSelection && isLeaf);
|
||||
m_ui->checkoutButton->setEnabled(hasSelection && !currentSelected && isLeaf);
|
||||
@@ -230,6 +232,36 @@ void BranchDialog::remove()
|
||||
m_model->removeBranch(selected);
|
||||
}
|
||||
|
||||
void BranchDialog::rename()
|
||||
{
|
||||
QModelIndex selected = selectedIndex();
|
||||
QTC_CHECK(selected != m_model->currentBranch()); // otherwise the button would not be enabled!
|
||||
QTC_CHECK(m_model->isLocal(selected)); // otherwise the button would not be enabled!
|
||||
|
||||
QString oldBranchName = m_model->branchName(selected);
|
||||
QStringList localNames = m_model->localBranchNames();
|
||||
|
||||
QPointer<BranchAddDialog> branchAddDialog = new BranchAddDialog(this, false);
|
||||
branchAddDialog->setBranchName(oldBranchName);
|
||||
branchAddDialog->setTrackedBranchName(QString(), false);
|
||||
|
||||
branchAddDialog->exec();
|
||||
|
||||
if (!branchAddDialog.isNull() && branchAddDialog->result() == QDialog::Accepted && m_model) {
|
||||
if (branchAddDialog->branchName() == oldBranchName)
|
||||
return;
|
||||
if (localNames.contains(branchAddDialog->branchName())) {
|
||||
QMessageBox::critical(this, tr("Branch exists"),
|
||||
tr("Local Branch \'%1\' already exists.")
|
||||
.arg(branchAddDialog->branchName()));
|
||||
return;
|
||||
}
|
||||
m_model->renameBranch(oldBranchName, branchAddDialog->branchName());
|
||||
refresh();
|
||||
}
|
||||
enableButtons();
|
||||
}
|
||||
|
||||
void BranchDialog::diff()
|
||||
{
|
||||
QString branchName = m_model->branchName(selectedIndex());
|
||||
|
||||
@@ -68,6 +68,7 @@ private slots:
|
||||
void add();
|
||||
void checkout();
|
||||
void remove();
|
||||
void rename();
|
||||
void diff();
|
||||
void log();
|
||||
void merge();
|
||||
|
||||
@@ -95,6 +95,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="renameButton">
|
||||
<property name="text">
|
||||
<string>Re&name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="checkoutButton">
|
||||
<property name="text">
|
||||
|
||||
Reference in New Issue
Block a user