mirror of
https://github.com/Murmele/Gittyup.git
synced 2024-09-11 10:45:39 +03:00
Merge pull request #667 from Murmele/work/templateManualApply
Template: Apply with filenames from diff
This commit is contained in:
commit
bbb6b88aff
@ -258,7 +258,27 @@ CommitEditor::CommitEditor(const git::Repository &repo, QWidget *parent)
|
||||
mTemplate = new TemplateButton(this);
|
||||
mTemplate->setText(tr("T"));
|
||||
connect(mTemplate, &TemplateButton::templateChanged, this,
|
||||
QOverload<const QString &>::of(&CommitEditor::applyTemplate));
|
||||
[this](const QString &t) {
|
||||
QStringList files;
|
||||
if (mDiff.isValid()) {
|
||||
int count = mDiff.count();
|
||||
git::Index index = mDiff.index();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
QString name = mDiff.name(i);
|
||||
switch (index.isStaged(name)) {
|
||||
case git::Index::PartiallyStaged:
|
||||
case git::Index::Staged:
|
||||
files.append(QFileInfo(name).fileName());
|
||||
break;
|
||||
case git::Index::Conflicted:
|
||||
case git::Index::Disabled:
|
||||
case git::Index::Unstaged:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
applyTemplate(t, files);
|
||||
});
|
||||
|
||||
QLabel *label = new QLabel(tr("<b>Commit Message:</b>"), this);
|
||||
|
||||
@ -585,11 +605,11 @@ QString CommitEditor::createFileList(const QStringList &list, int maxFiles) {
|
||||
return msg;
|
||||
}
|
||||
|
||||
void CommitEditor::setMessage(const QStringList &list) {
|
||||
void CommitEditor::setMessage(const QStringList &files) {
|
||||
if (mTemplate->templates().count() > 0) {
|
||||
applyTemplate(mTemplate->templates().first().value, list);
|
||||
applyTemplate(mTemplate->templates().first().value, files);
|
||||
} else {
|
||||
QString msg = createFileList(list, 3);
|
||||
QString msg = createFileList(files, 3);
|
||||
if (!msg.isEmpty())
|
||||
msg = QStringLiteral("Update ") + msg;
|
||||
setMessage(msg);
|
||||
@ -710,7 +730,7 @@ void CommitEditor::updateButtons(bool yieldFocus) {
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList list;
|
||||
QStringList files;
|
||||
int staged = 0;
|
||||
int partial = 0;
|
||||
int conflicted = 0;
|
||||
@ -724,12 +744,12 @@ void CommitEditor::updateButtons(bool yieldFocus) {
|
||||
break;
|
||||
|
||||
case git::Index::PartiallyStaged:
|
||||
list.append(QFileInfo(name).fileName());
|
||||
files.append(QFileInfo(name).fileName());
|
||||
++partial;
|
||||
break;
|
||||
|
||||
case git::Index::Staged:
|
||||
list.append(QFileInfo(name).fileName());
|
||||
files.append(QFileInfo(name).fileName());
|
||||
++staged;
|
||||
break;
|
||||
|
||||
@ -743,7 +763,7 @@ void CommitEditor::updateButtons(bool yieldFocus) {
|
||||
QSignalBlocker blocker(mMessage);
|
||||
(void)blocker;
|
||||
|
||||
setMessage(list);
|
||||
setMessage(files);
|
||||
if (yieldFocus && !mMessage->toPlainText().isEmpty())
|
||||
mMessage->setFocus();
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
void unstage();
|
||||
bool isUnstageEnabled() const;
|
||||
static QString createFileList(const QStringList &list, int maxFiles);
|
||||
void setMessage(const QStringList &list);
|
||||
void setMessage(const QStringList &files);
|
||||
void setMessage(const QString &message);
|
||||
QString message() const;
|
||||
void setDiff(const git::Diff &diff);
|
||||
|
@ -68,6 +68,8 @@ TemplateDialog::TemplateDialog(QList<TemplateButton::Template> &templates,
|
||||
hBox->addItem(spacer);
|
||||
hBox->addWidget(mRemove);
|
||||
QVBoxLayout *vBox2 = new QVBoxLayout();
|
||||
vBox2->addWidget(
|
||||
new QLabel(tr("First template will be applied automatically"), this));
|
||||
vBox2->addWidget(mTemplateList);
|
||||
vBox2->addLayout(hBox);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user