RedPanda-CPP/RedPandaIDE/vcs/gitbranchdialog.cpp

90 lines
2.2 KiB
C++
Raw Permalink Normal View History

2022-02-19 20:38:08 +08:00
#include "gitbranchdialog.h"
#include "ui_gitbranchdialog.h"
#include "gitmanager.h"
2022-02-20 21:47:57 +08:00
#include "../widgets/infomessagebox.h"
2022-02-19 20:38:08 +08:00
GitBranchDialog::GitBranchDialog(const QString& folder, QWidget *parent) :
QDialog(parent),
ui(new Ui::GitBranchDialog),
mFolder(folder)
{
ui->setupUi(this);
mManager = new GitManager();
int current=-1;
QStringList branches =mManager->listBranches(mFolder,current);
ui->lstBranches->addItems(branches);
ui->lstBranches->setCurrentIndex(current);
ui->rbBranch->setChecked(true);
ui->rbNonSpecifyTrack->setChecked(true);
ui->txtNewBranch->setEnabled(false);
if (branches.isEmpty()) {
QString currentBranch;
if (mManager->hasRepository(mFolder,currentBranch)) {
ui->lstBranches->addItem(currentBranch);
ui->btnOk->setEnabled(false);
}
ui->grpOptions->setEnabled(false);
}
}
GitBranchDialog::~GitBranchDialog()
{
delete mManager;
delete ui;
}
void GitBranchDialog::on_btnCancel_clicked()
{
reject();
}
void GitBranchDialog::on_btnOk_clicked()
{
2022-02-21 11:37:29 +08:00
QString branch;
2022-02-19 20:38:08 +08:00
if (ui->chkCreate->isChecked())
2022-02-21 11:37:29 +08:00
branch = ui->txtNewBranch->text();
2022-02-19 20:38:08 +08:00
else
2022-02-21 11:37:29 +08:00
branch = ui->lstBranches->currentText();
2022-02-19 20:38:08 +08:00
bool result = false;
2022-02-20 21:47:57 +08:00
QString output;
2022-02-21 11:37:29 +08:00
if (!branch.isEmpty()) {
2022-02-19 20:38:08 +08:00
result = mManager->switchToBranch(
mFolder,
2022-02-21 11:37:29 +08:00
branch,
2022-02-19 20:38:08 +08:00
ui->chkCreate->isChecked(),
ui->chkForce->isChecked(),
ui->chkMerge->isChecked(),
ui->rbForceTrack->isChecked(),
ui->rbForceNoTrack->isChecked(),
2022-02-20 21:47:57 +08:00
ui->chkForceCreation->isChecked(),
output);
2022-02-19 20:38:08 +08:00
}
2022-02-20 21:47:57 +08:00
if (result) {
2022-02-19 20:38:08 +08:00
accept();
2022-02-20 21:47:57 +08:00
} else if (!output.isEmpty()) {
InfoMessageBox box;
box.setMessage(output);
box.exec();
2022-02-19 20:38:08 +08:00
reject();
2022-02-20 21:47:57 +08:00
}
2022-02-19 20:38:08 +08:00
}
void GitBranchDialog::on_lstBranches_currentIndexChanged(int /*index*/)
{
ui->txtNewBranch->setText("branch_"+ui->lstBranches->currentText());
}
void GitBranchDialog::on_chkCreate_stateChanged(int /*arg1*/)
{
ui->txtNewBranch->setEnabled(ui->chkCreate->isChecked());
}
void GitBranchDialog::closeEvent(QCloseEvent */* event */)
{
reject();
}