VCS[perforce,svn,vcs]: Use convenience to tag editors for reuse.

Introduce convenience to determine editor tags to avoid
crashes on empty files arguments, etc (VCSBaseEditor).
Add diff-whitespace handling and 'Revert chunk' to Perforce.

Task-number: QTCREATORBUG-4305
This commit is contained in:
Friedemann Kleint
2011-03-31 10:57:33 +02:00
parent 938dd71e1a
commit 4ed14a1f2c
6 changed files with 165 additions and 79 deletions

View File

@@ -1068,6 +1068,49 @@ void VCSBaseEditorWidget::slotRevertDiffChunk()
emit diffChunkReverted(chunk);
}
// Tagging of editors for re-use.
QString VCSBaseEditorWidget::editorTag(EditorContentType t,
const QString &workingDirectory,
const QStringList &files,
const QString &revision)
{
const QChar colon = QLatin1Char(':');
QString rc = QString::number(t);
rc += colon;
if (!revision.isEmpty()) {
rc += revision;
rc += colon;
}
rc += workingDirectory;
if (!files.isEmpty()) {
rc += colon;
rc += files.join(QString(colon));
}
return rc;
}
static const char tagPropertyC[] = "_q_VCSBaseEditorTag";
void VCSBaseEditorWidget::tagEditor(Core::IEditor *e, const QString &tag)
{
e->setProperty(tagPropertyC, QVariant(tag));
}
Core::IEditor* VCSBaseEditorWidget::locateEditorByTag(const QString &tag)
{
Core::IEditor *rc = 0;
foreach (Core::IEditor *ed, Core::EditorManager::instance()->openedEditors()) {
const QVariant tagPropertyValue = ed->property(tagPropertyC);
if (tagPropertyValue.type() == QVariant::String && tagPropertyValue.toString() == tag) {
rc = ed;
break;
}
}
if (VCSBase::Constants::Internal::debug)
qDebug() << "locateEditorByTag " << tag << rc;
return rc;
}
} // namespace VCSBase
#include "vcsbaseeditor.moc"