Commit 725ecc5f authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

VCS: Refactor createDiffHighlighter



All plugins do the same...

Change-Id: I21e5a1d7507292add91199a3db75df74165b63b1
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 6dd8726a
......@@ -111,9 +111,9 @@ QString BazaarEditor::changeUnderCursor(const QTextCursor &cursorIn) const
return QString();
}
VcsBase::DiffHighlighter *BazaarEditor::createDiffHighlighter() const
QRegExp BazaarEditor::diffFilePattern() const
{
return new VcsBase::DiffHighlighter(m_diffFileId);
return m_diffFileId;
}
VcsBase::BaseAnnotationHighlighter *BazaarEditor::createAnnotationHighlighter(const QSet<QString> &changes,
......
......@@ -46,7 +46,7 @@ public:
private:
QSet<QString> annotationChanges() const;
QString changeUnderCursor(const QTextCursor &cursor) const;
VcsBase::DiffHighlighter *createDiffHighlighter() const;
QRegExp diffFilePattern() const;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const;
......
......@@ -93,11 +93,9 @@ QString ClearCaseEditor::changeUnderCursor(const QTextCursor &c) const
+++ main.cpp@@\main\1
@@ -6,6 +6,5 @@
*/
VcsBase::DiffHighlighter *ClearCaseEditor::createDiffHighlighter() const
QRegExp ClearCaseEditor::diffFilePattern() const
{
const QRegExp filePattern(QLatin1String("^[-+][-+][-+] "));
QTC_CHECK(filePattern.isValid());
return new VcsBase::DiffHighlighter(filePattern);
return QRegExp(QLatin1String("^[-+][-+][-+] "));
}
VcsBase::BaseAnnotationHighlighter *ClearCaseEditor::createAnnotationHighlighter(const QSet<QString> &changes,
......
......@@ -49,7 +49,7 @@ public:
private:
QSet<QString> annotationChanges() const;
QString changeUnderCursor(const QTextCursor &) const;
VcsBase::DiffHighlighter *createDiffHighlighter() const;
QRegExp diffFilePattern() const;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
......
......@@ -120,12 +120,9 @@ cvs diff -d -u -r1.1 -r1.2:
@@ -6,6 +6,5 @@
\endcode
*/
VcsBase::DiffHighlighter *CvsEditor::createDiffHighlighter() const
QRegExp CvsEditor::diffFilePattern() const
{
const QRegExp filePattern(QLatin1String("^[-+][-+][-+] .*1\\.[\\d\\.]+$"));
QTC_CHECK(filePattern.isValid());
return new VcsBase::DiffHighlighter(filePattern);
return QRegExp(QLatin1String("^[-+][-+][-+] .*1\\.[\\d\\.]+$"));
}
VcsBase::BaseAnnotationHighlighter *CvsEditor::createAnnotationHighlighter(const QSet<QString> &changes,
......
......@@ -48,7 +48,7 @@ public:
private:
QSet<QString> annotationChanges() const;
QString changeUnderCursor(const QTextCursor &) const;
VcsBase::DiffHighlighter *createDiffHighlighter() const;
QRegExp diffFilePattern() const;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
QStringList annotationPreviousVersions(const QString &revision) const;
......
......@@ -107,10 +107,9 @@ QString GitEditor::changeUnderCursor(const QTextCursor &c) const
return QString();
}
VcsBase::DiffHighlighter *GitEditor::createDiffHighlighter() const
QRegExp GitEditor::diffFilePattern() const
{
const QRegExp filePattern(QLatin1String("^(diff --git a/|index |[+-][+-][+-] [ab/]).*$"));
return new VcsBase::DiffHighlighter(filePattern);
return QRegExp(QLatin1String("^(diff --git a/|index |[+-][+-][+-] [ab/]).*$"));
}
VcsBase::BaseAnnotationHighlighter *GitEditor::createAnnotationHighlighter(const QSet<QString> &changes,
......
......@@ -57,7 +57,7 @@ public slots:
private:
QSet<QString> annotationChanges() const;
QString changeUnderCursor(const QTextCursor &) const;
VcsBase::DiffHighlighter *createDiffHighlighter() const;
QRegExp diffFilePattern() const;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
QString decorateVersion(const QString &revision) const;
......
......@@ -88,9 +88,9 @@ QString MercurialEditor::changeUnderCursor(const QTextCursor &cursorIn) const
return QString();
}
VcsBase::DiffHighlighter *MercurialEditor::createDiffHighlighter() const
QRegExp MercurialEditor::diffFilePattern() const
{
return new VcsBase::DiffHighlighter(diffIdentifier);
return diffIdentifier;
}
VcsBase::BaseAnnotationHighlighter *MercurialEditor::createAnnotationHighlighter(const QSet<QString> &changes,
......
......@@ -46,7 +46,7 @@ public:
private:
QSet<QString> annotationChanges() const;
QString changeUnderCursor(const QTextCursor &cursor) const;
VcsBase::DiffHighlighter *createDiffHighlighter() const;
QRegExp diffFilePattern() const;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const;
QString decorateVersion(const QString &revision) const;
......
......@@ -103,10 +103,9 @@ QString PerforceEditor::changeUnderCursor(const QTextCursor &c) const
return m_changeNumberPattern.exactMatch(change) ? change : QString();
}
VcsBase::DiffHighlighter *PerforceEditor::createDiffHighlighter() const
QRegExp PerforceEditor::diffFilePattern() const
{
const QRegExp filePattern(QLatin1String("^====.*"));
return new VcsBase::DiffHighlighter(filePattern);
return QRegExp(QLatin1String("^====.*"));
}
VcsBase::BaseAnnotationHighlighter *PerforceEditor::createAnnotationHighlighter(const QSet<QString> &changes,
......
......@@ -50,7 +50,7 @@ public:
private:
QSet<QString> annotationChanges() const;
QString changeUnderCursor(const QTextCursor &) const;
VcsBase::DiffHighlighter *createDiffHighlighter() const;
QRegExp diffFilePattern() const;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
QStringList annotationPreviousVersions(const QString &v) const;
......
......@@ -106,12 +106,9 @@ QString SubversionEditor::changeUnderCursor(const QTextCursor &c) const
@@ -6,6 +6,5 @@
\endcode
*/
VcsBase::DiffHighlighter *SubversionEditor::createDiffHighlighter() const
QRegExp SubversionEditor::diffFilePattern() const
{
const QRegExp filePattern(QLatin1String("^[-+][-+][-+] .*|^Index: .*|^==*$"));
QTC_CHECK(filePattern.isValid());
return new VcsBase::DiffHighlighter(filePattern);
return QRegExp(QLatin1String("^[-+][-+][-+] .*|^Index: .*|^==*$"));
}
VcsBase::BaseAnnotationHighlighter *SubversionEditor::createAnnotationHighlighter(const QSet<QString> &changes,
......
......@@ -48,7 +48,7 @@ public:
private:
QSet<QString> annotationChanges() const;
QString changeUnderCursor(const QTextCursor &) const;
VcsBase::DiffHighlighter *createDiffHighlighter() const;
QRegExp diffFilePattern() const;
VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
QString fileNameFromDiffSpecification(const QTextBlock &diffFileName) const;
QStringList annotationPreviousVersions(const QString &) const;
......
......@@ -130,9 +130,8 @@ DiffFormats DiffHighlighterPrivate::analyzeLine(const QString &text) const
} // namespace Internal
// --- DiffHighlighter
DiffHighlighter::DiffHighlighter(const QRegExp &filePattern,
QTextDocument *document) :
TextEditor::SyntaxHighlighter(document),
DiffHighlighter::DiffHighlighter(const QRegExp &filePattern) :
TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(0)),
d(new Internal::DiffHighlighterPrivate(filePattern))
{
}
......
......@@ -51,8 +51,7 @@ class VCSBASE_EXPORT DiffHighlighter : public TextEditor::SyntaxHighlighter
Q_OBJECT
public:
explicit DiffHighlighter(const QRegExp &filePattern,
QTextDocument *document = 0);
explicit DiffHighlighter(const QRegExp &filePattern);
~DiffHighlighter();
void highlightBlock(const QString &text);
......
......@@ -678,10 +678,10 @@ void VcsBaseEditorWidget::init()
connect(this, SIGNAL(textChanged()), this, SLOT(slotActivateAnnotation()));
break;
case DiffOutput: {
DiffHighlighter *dh = createDiffHighlighter();
d->m_diffFilePattern = diffFilePattern();
DiffHighlighter *dh = new DiffHighlighter(d->m_diffFilePattern);
setCodeFoldingSupported(true);
baseTextDocument()->setSyntaxHighlighter(dh);
d->m_diffFilePattern = dh->filePattern();
connect(this, SIGNAL(textChanged()), this, SLOT(slotPopulateDiffBrowser()));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(slotDiffCursorPositionChanged()));
}
......
......@@ -240,7 +240,7 @@ private:
// Implement to identify a change number at the cursor position
virtual QString changeUnderCursor(const QTextCursor &) const = 0;
// Factory functions for highlighters
virtual DiffHighlighter *createDiffHighlighter() const = 0;
virtual QRegExp diffFilePattern() const = 0;
virtual BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes,
const QColor &bg) const = 0;
// Implement to return a local file name from the diff file specification
......
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