Implement DiffEditorDocument::suggestedFileName().

Try to derive a git-format-patch type file name from
the description.

Change-Id: I581f4ba87a5ac4b82ca6519be8aa13fb4b4ebe43
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Friedemann Kleint
2014-11-12 15:30:06 +01:00
parent 8fbd8c4105
commit e01496122d
2 changed files with 26 additions and 1 deletions

View File

@@ -127,4 +127,29 @@ bool DiffEditorDocument::open(QString *errorString, const QString &fileName)
return true;
}
QString DiffEditorDocument::suggestedFileName() const
{
QString result = QStringLiteral("0001");
const QString description = m_controller->description();
if (!description.isEmpty()) {
// Derive "git format-patch-type" file name from subject.
const int pos = description.indexOf(QLatin1String("\n\n "));
const int endPos = pos >= 0 ? description.indexOf(QLatin1Char('\n'), pos + 6) : -1;
if (endPos > pos) {
const QChar space(QLatin1Char(' '));
const QChar dash(QLatin1Char('-'));
QString subject = description.mid(pos, endPos - pos);
for (int i = 0; i < subject.size(); ++i) {
if (!subject.at(i).isLetterOrNumber())
subject[i] = space;
}
subject = subject.simplified();
subject.replace(space, dash);
result += dash;
result += subject;
}
}
return result + QStringLiteral(".patch");
}
} // namespace DiffEditor