| 1 | #include "gitbranchdialog.h" |
| 2 | #include "ui_gitbranchdialog.h" |
| 3 | #include "gitmanager.h" |
| 4 | #include "../widgets/infomessagebox.h" |
| 5 | |
| 6 | GitBranchDialog::GitBranchDialog(const QString& folder, QWidget *parent) : |
| 7 | QDialog(parent), |
| 8 | ui(new Ui::GitBranchDialog), |
| 9 | mFolder(folder) |
| 10 | { |
| 11 | ui->setupUi(this); |
| 12 | mManager = new GitManager(); |
| 13 | int current=-1; |
| 14 | QStringList branches =mManager->listBranches(mFolder,current); |
| 15 | ui->lstBranches->addItems(branches); |
| 16 | ui->lstBranches->setCurrentIndex(current); |
| 17 | ui->rbBranch->setChecked(true); |
| 18 | ui->rbNonSpecifyTrack->setChecked(true); |
| 19 | ui->txtNewBranch->setEnabled(false); |
| 20 | if (branches.isEmpty()) { |
| 21 | QString currentBranch; |
| 22 | if (mManager->hasRepository(mFolder,currentBranch)) { |
| 23 | ui->lstBranches->addItem(currentBranch); |
| 24 | ui->btnOk->setEnabled(false); |
| 25 | } |
| 26 | ui->grpOptions->setEnabled(false); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | GitBranchDialog::~GitBranchDialog() |
| 31 | { |
| 32 | delete mManager; |
| 33 | delete ui; |
| 34 | } |
| 35 | |
| 36 | void GitBranchDialog::on_btnCancel_clicked() |
| 37 | { |
| 38 | reject(); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | void GitBranchDialog::on_btnOk_clicked() |
| 43 | { |
| 44 | QString branch; |
| 45 | if (ui->chkCreate->isChecked()) |
| 46 | branch = ui->txtNewBranch->text(); |
| 47 | else |
| 48 | branch = ui->lstBranches->currentText(); |
| 49 | bool result = false; |
| 50 | QString output; |
| 51 | if (!branch.isEmpty()) { |
| 52 | result = mManager->switchToBranch( |
| 53 | mFolder, |
| 54 | branch, |
| 55 | ui->chkCreate->isChecked(), |
| 56 | ui->chkForce->isChecked(), |
| 57 | ui->chkMerge->isChecked(), |
| 58 | ui->rbForceTrack->isChecked(), |
| 59 | ui->rbForceNoTrack->isChecked(), |
| 60 | ui->chkForceCreation->isChecked(), |
| 61 | output); |
| 62 | } |
| 63 | if (result) { |
| 64 | accept(); |
| 65 | } else if (!output.isEmpty()) { |
| 66 | InfoMessageBox box; |
| 67 | box.setMessage(output); |
| 68 | box.exec(); |
| 69 | reject(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | |
| 74 | void GitBranchDialog::on_lstBranches_currentIndexChanged(int /*index*/) |
| 75 | { |
| 76 | ui->txtNewBranch->setText("branch_" +ui->lstBranches->currentText()); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void GitBranchDialog::on_chkCreate_stateChanged(int /*arg1*/) |
| 81 | { |
| 82 | ui->txtNewBranch->setEnabled(ui->chkCreate->isChecked()); |
| 83 | } |
| 84 | |
| 85 | void GitBranchDialog::closeEvent(QCloseEvent */* event */) |
| 86 | { |
| 87 | reject(); |
| 88 | } |
| 89 | |
| 90 | |