VCS: Highlight commit lines in log editor

Task-number: QTCREATORBUG-13997
Change-Id: I7d9a85cd6022a20a487010a35164ff100b72218d
Reviewed-by: Thorben Kroeger <thorbenkroeger@gmail.com>
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-03-25 10:30:24 +02:00
committed by Orgad Shaneh
parent 9877221a3d
commit dcd3b958cf
8 changed files with 30 additions and 8 deletions

View File

@@ -52,4 +52,5 @@
<style name="DiffSourceChar" foreground="#000000" background="#c34141"/> <style name="DiffSourceChar" foreground="#000000" background="#c34141"/>
<style name="DiffDestLine" background="#2d8c2d"/> <style name="DiffDestLine" background="#2d8c2d"/>
<style name="DiffDestChar" foreground="#000000" background="#41c341"/> <style name="DiffDestChar" foreground="#000000" background="#41c341"/>
<style name="LogChangeLine" foreground="#808000"/>
</style-scheme> </style-scheme>

View File

@@ -60,5 +60,6 @@
<style name="DiffSourceChar" background="#c34141"/> <style name="DiffSourceChar" background="#c34141"/>
<style name="DiffDestLine" background="#277027"/> <style name="DiffDestLine" background="#277027"/>
<style name="DiffDestChar" background="#339d33"/> <style name="DiffDestChar" background="#339d33"/>
<style name="LogChangeLine" foreground="#dcdc00"/>
</style-scheme> </style-scheme>

View File

@@ -96,6 +96,8 @@ const char *nameForStyle(TextStyle style)
case C_DIFF_DEST_LINE: return "DiffDestLine"; case C_DIFF_DEST_LINE: return "DiffDestLine";
case C_DIFF_DEST_CHAR: return "DiffDestChar"; case C_DIFF_DEST_CHAR: return "DiffDestChar";
case C_LOG_CHANGE_LINE: return "LogChangeLine";
case C_LAST_STYLE_SENTINEL: return "LastStyleSentinel"; case C_LAST_STYLE_SENTINEL: return "LastStyleSentinel";
} }

View File

@@ -95,6 +95,8 @@ enum TextStyle {
C_DIFF_DEST_LINE, C_DIFF_DEST_LINE,
C_DIFF_DEST_CHAR, C_DIFF_DEST_CHAR,
C_LOG_CHANGE_LINE,
C_LAST_STYLE_SENTINEL C_LAST_STYLE_SENTINEL
}; };

View File

@@ -268,6 +268,10 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
"in differences (in side-by-side diff editor)."), "in differences (in side-by-side diff editor)."),
Format(QColor(), QColor(175, 255, 175)))); Format(QColor(), QColor(175, 255, 175))));
formatDescr.append(FormatDescription(C_LOG_CHANGE_LINE, tr("Log Change Line"),
tr("Applied to lines describing changes in VCS log"),
Format(QColor(192, 0, 0), QColor())));
d->m_fontSettingsPage = new FontSettingsPage(formatDescr, d->m_fontSettingsPage = new FontSettingsPage(formatDescr,
Constants::TEXT_EDITOR_FONT_SETTINGS, Constants::TEXT_EDITOR_FONT_SETTINGS,
this); this);

View File

@@ -56,6 +56,12 @@
@@ -10,6 +10,7 @@ SUBDIRS = plugin_coreplugin @@ -10,6 +10,7 @@ SUBDIRS = plugin_coreplugin
\endcode \endcode
Log is parametrizable by change indicator. For example '^commit ([0-9a-f]{8})[0-9a-f]{32}'
in Git:
\code
commit a3398841a24b24c73b47759c4bffdc8b78a34936 (HEAD, master)
\code
Also highlights trailing blanks. Also highlights trailing blanks.
*/ */
@@ -72,7 +78,8 @@ enum DiffFormats {
DiffInFormat, DiffInFormat,
DiffOutFormat, DiffOutFormat,
DiffFileFormat, DiffFileFormat,
DiffLocationFormat DiffLocationFormat,
ChangeTextFormat
}; };
enum FoldingState { enum FoldingState {
@@ -98,12 +105,13 @@ class DiffAndLogHighlighterPrivate
DiffAndLogHighlighter *q_ptr; DiffAndLogHighlighter *q_ptr;
Q_DECLARE_PUBLIC(DiffAndLogHighlighter) Q_DECLARE_PUBLIC(DiffAndLogHighlighter)
public: public:
DiffAndLogHighlighterPrivate(const QRegExp &filePattern); DiffAndLogHighlighterPrivate(const QRegExp &filePattern, const QRegExp &changePattern);
Internal::DiffFormats analyzeLine(const QString &block) const; Internal::DiffFormats analyzeLine(const QString &block) const;
void updateOtherFormats(); void updateOtherFormats();
mutable QRegExp m_filePattern; mutable QRegExp m_filePattern;
mutable QRegExp m_changePattern;
const QString m_locationIndicator; const QString m_locationIndicator;
const QChar m_diffInIndicator; const QChar m_diffInIndicator;
const QChar m_diffOutIndicator; const QChar m_diffOutIndicator;
@@ -112,9 +120,10 @@ public:
Internal::FoldingState m_foldingState; Internal::FoldingState m_foldingState;
}; };
DiffAndLogHighlighterPrivate::DiffAndLogHighlighterPrivate(const QRegExp &filePattern) : DiffAndLogHighlighterPrivate::DiffAndLogHighlighterPrivate(const QRegExp &filePattern, const QRegExp &changePattern) :
q_ptr(0), q_ptr(0),
m_filePattern(filePattern), m_filePattern(filePattern),
m_changePattern(changePattern),
m_locationIndicator(QLatin1String("@@")), m_locationIndicator(QLatin1String("@@")),
m_diffInIndicator(QLatin1Char('+')), m_diffInIndicator(QLatin1Char('+')),
m_diffOutIndicator(QLatin1Char('-')), m_diffOutIndicator(QLatin1Char('-')),
@@ -129,6 +138,8 @@ Internal::DiffFormats DiffAndLogHighlighterPrivate::analyzeLine(const QString &t
// file first // file first
if (m_filePattern.indexIn(text) == 0) if (m_filePattern.indexIn(text) == 0)
return Internal::DiffFileFormat; return Internal::DiffFileFormat;
if (m_changePattern.indexIn(text) == 0)
return Internal::ChangeTextFormat;
if (text.startsWith(m_diffInIndicator)) if (text.startsWith(m_diffInIndicator))
return Internal::DiffInFormat; return Internal::DiffInFormat;
if (text.startsWith(m_diffOutIndicator)) if (text.startsWith(m_diffOutIndicator))
@@ -147,9 +158,9 @@ void DiffAndLogHighlighterPrivate::updateOtherFormats()
} }
// --- DiffAndLogHighlighter // --- DiffAndLogHighlighter
DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern) : DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern, const QRegExp &changePattern) :
TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(0)), TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(0)),
d_ptr(new DiffAndLogHighlighterPrivate(filePattern)) d_ptr(new DiffAndLogHighlighterPrivate(filePattern, changePattern))
{ {
d_ptr->q_ptr = this; d_ptr->q_ptr = this;
Q_D(DiffAndLogHighlighter); Q_D(DiffAndLogHighlighter);
@@ -160,7 +171,8 @@ DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern) :
<< TextEditor::C_ADDED_LINE << TextEditor::C_ADDED_LINE
<< TextEditor::C_REMOVED_LINE << TextEditor::C_REMOVED_LINE
<< TextEditor::C_DIFF_FILE << TextEditor::C_DIFF_FILE
<< TextEditor::C_DIFF_LOCATION; << TextEditor::C_DIFF_LOCATION
<< TextEditor::C_LOG_CHANGE_LINE;
} }
setTextFormatCategories(categories); setTextFormatCategories(categories);
d->updateOtherFormats(); d->updateOtherFormats();

View File

@@ -52,7 +52,7 @@ class VCSBASE_EXPORT DiffAndLogHighlighter : public TextEditor::SyntaxHighlighte
Q_OBJECT Q_OBJECT
Q_DECLARE_PRIVATE(DiffAndLogHighlighter) Q_DECLARE_PRIVATE(DiffAndLogHighlighter)
public: public:
explicit DiffAndLogHighlighter(const QRegExp &filePattern); explicit DiffAndLogHighlighter(const QRegExp &filePattern, const QRegExp &changePattern);
~DiffAndLogHighlighter(); ~DiffAndLogHighlighter();
void highlightBlock(const QString &text); void highlightBlock(const QString &text);

View File

@@ -736,7 +736,7 @@ void VcsBaseEditorWidget::init()
break; break;
} }
if (hasDiff()) { if (hasDiff()) {
auto dh = new DiffAndLogHighlighter(d->m_diffFilePattern); auto dh = new DiffAndLogHighlighter(d->m_diffFilePattern, d->m_logEntryPattern);
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
textDocument()->setSyntaxHighlighter(dh); textDocument()->setSyntaxHighlighter(dh);
} }