Commit e0149612 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Implement DiffEditorDocument::suggestedFileName().



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

Change-Id: I581f4ba87a5ac4b82ca6519be8aa13fb4b4ebe43
Reviewed-by: default avatarOrgad Shaneh <orgads@gmail.com>
parent 8fbd8c41
......@@ -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
......@@ -50,7 +50,7 @@ public:
bool setContents(const QByteArray &contents);
QString defaultPath() const;
QString suggestedFileName() const { return QString(); }
QString suggestedFileName() const Q_DECL_OVERRIDE;
bool isModified() const { return false; }
bool isSaveAsAllowed() const { return true; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment