-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #621 from mwerle/feature/rename_branch_menu
Feature/rename branch menu
- Loading branch information
Showing
11 changed files
with
205 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ build | |
CMakeLists.txt.user | ||
cmake-build-debug/ | ||
cmake-build-release/ | ||
build | ||
.idea/ | ||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This software is licensed under the MIT License. The LICENSE.md file | ||
// describes the conditions under which this software may be distributed. | ||
// | ||
// Author: Michael WERLE | ||
// | ||
|
||
#include "RenameBranchDialog.h" | ||
#include "git/Branch.h" | ||
#include "ui/ExpandButton.h" | ||
#include "ui/ReferenceList.h" | ||
#include "ui/RepoView.h" | ||
#include <QApplication> | ||
#include <QCheckBox> | ||
#include <QDialogButtonBox> | ||
#include <QFormLayout> | ||
#include <QLineEdit> | ||
#include <QPushButton> | ||
#include <QVBoxLayout> | ||
|
||
RenameBranchDialog::RenameBranchDialog(const git::Repository &repo, | ||
const git::Branch &branch, | ||
QWidget *parent) | ||
: QDialog(parent) { | ||
Q_ASSERT(branch.isValid() && branch.isLocalBranch()); | ||
setAttribute(Qt::WA_DeleteOnClose); | ||
|
||
mName = new QLineEdit(branch.name(), this); | ||
mName->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); | ||
mName->setMinimumWidth(QFontMetrics(mName->font()).averageCharWidth() * 40); | ||
|
||
QFormLayout *form = new QFormLayout; | ||
form->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); | ||
form->addRow(tr("Name:"), mName); | ||
|
||
QDialogButtonBox *buttons = new QDialogButtonBox(this); | ||
buttons->addButton(QDialogButtonBox::Cancel); | ||
QPushButton *rename = | ||
buttons->addButton(tr("Rename Branch"), QDialogButtonBox::AcceptRole); | ||
rename->setEnabled(false); | ||
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); | ||
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); | ||
|
||
QVBoxLayout *layout = new QVBoxLayout(this); | ||
layout->addLayout(form); | ||
layout->addWidget(buttons); | ||
|
||
// Update button when name text changes. | ||
connect(mName, &QLineEdit::textChanged, [repo, rename](const QString &text) { | ||
rename->setEnabled(git::Branch::isNameValid(text) && | ||
!repo.lookupBranch(text, GIT_BRANCH_LOCAL).isValid()); | ||
}); | ||
|
||
// Perform the rename when the button is clicked | ||
connect(rename, &QPushButton::clicked, | ||
[this, branch] { git::Branch(branch).rename(mName->text()); }); | ||
} | ||
|
||
QString RenameBranchDialog::name() const { return mName->text(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// This software is licensed under the MIT License. The LICENSE.md file | ||
// describes the conditions under which this software may be distributed. | ||
// | ||
// Author: Michael WERLE | ||
// | ||
|
||
#ifndef RENAMEBRANCHDIALOG_H | ||
#define RENAMEBRANCHDIALOG_H | ||
|
||
#include "git/Branch.h" | ||
#include <QDialog> | ||
|
||
class QLineEdit; | ||
|
||
namespace git { | ||
class Reference; | ||
class Repository; | ||
} // namespace git | ||
|
||
class RenameBranchDialog : public QDialog { | ||
Q_OBJECT | ||
|
||
public: | ||
RenameBranchDialog(const git::Repository &repo, const git::Branch &branch, | ||
QWidget *parent = nullptr); | ||
|
||
QString name() const; | ||
|
||
private: | ||
QLineEdit *mName; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters