forked from qt-creator/qt-creator
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:
committed by
Orgad Shaneh
parent
9877221a3d
commit
dcd3b958cf
@@ -52,4 +52,5 @@
|
||||
<style name="DiffSourceChar" foreground="#000000" background="#c34141"/>
|
||||
<style name="DiffDestLine" background="#2d8c2d"/>
|
||||
<style name="DiffDestChar" foreground="#000000" background="#41c341"/>
|
||||
<style name="LogChangeLine" foreground="#808000"/>
|
||||
</style-scheme>
|
||||
|
||||
@@ -60,5 +60,6 @@
|
||||
<style name="DiffSourceChar" background="#c34141"/>
|
||||
<style name="DiffDestLine" background="#277027"/>
|
||||
<style name="DiffDestChar" background="#339d33"/>
|
||||
<style name="LogChangeLine" foreground="#dcdc00"/>
|
||||
</style-scheme>
|
||||
|
||||
|
||||
@@ -96,6 +96,8 @@ const char *nameForStyle(TextStyle style)
|
||||
case C_DIFF_DEST_LINE: return "DiffDestLine";
|
||||
case C_DIFF_DEST_CHAR: return "DiffDestChar";
|
||||
|
||||
case C_LOG_CHANGE_LINE: return "LogChangeLine";
|
||||
|
||||
case C_LAST_STYLE_SENTINEL: return "LastStyleSentinel";
|
||||
|
||||
}
|
||||
|
||||
@@ -95,6 +95,8 @@ enum TextStyle {
|
||||
C_DIFF_DEST_LINE,
|
||||
C_DIFF_DEST_CHAR,
|
||||
|
||||
C_LOG_CHANGE_LINE,
|
||||
|
||||
C_LAST_STYLE_SENTINEL
|
||||
};
|
||||
|
||||
|
||||
@@ -268,6 +268,10 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
|
||||
"in differences (in side-by-side diff editor)."),
|
||||
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,
|
||||
Constants::TEXT_EDITOR_FONT_SETTINGS,
|
||||
this);
|
||||
|
||||
@@ -56,6 +56,12 @@
|
||||
@@ -10,6 +10,7 @@ SUBDIRS = plugin_coreplugin
|
||||
\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.
|
||||
*/
|
||||
|
||||
@@ -72,7 +78,8 @@ enum DiffFormats {
|
||||
DiffInFormat,
|
||||
DiffOutFormat,
|
||||
DiffFileFormat,
|
||||
DiffLocationFormat
|
||||
DiffLocationFormat,
|
||||
ChangeTextFormat
|
||||
};
|
||||
|
||||
enum FoldingState {
|
||||
@@ -98,12 +105,13 @@ class DiffAndLogHighlighterPrivate
|
||||
DiffAndLogHighlighter *q_ptr;
|
||||
Q_DECLARE_PUBLIC(DiffAndLogHighlighter)
|
||||
public:
|
||||
DiffAndLogHighlighterPrivate(const QRegExp &filePattern);
|
||||
DiffAndLogHighlighterPrivate(const QRegExp &filePattern, const QRegExp &changePattern);
|
||||
|
||||
Internal::DiffFormats analyzeLine(const QString &block) const;
|
||||
void updateOtherFormats();
|
||||
|
||||
mutable QRegExp m_filePattern;
|
||||
mutable QRegExp m_changePattern;
|
||||
const QString m_locationIndicator;
|
||||
const QChar m_diffInIndicator;
|
||||
const QChar m_diffOutIndicator;
|
||||
@@ -112,9 +120,10 @@ public:
|
||||
Internal::FoldingState m_foldingState;
|
||||
};
|
||||
|
||||
DiffAndLogHighlighterPrivate::DiffAndLogHighlighterPrivate(const QRegExp &filePattern) :
|
||||
DiffAndLogHighlighterPrivate::DiffAndLogHighlighterPrivate(const QRegExp &filePattern, const QRegExp &changePattern) :
|
||||
q_ptr(0),
|
||||
m_filePattern(filePattern),
|
||||
m_changePattern(changePattern),
|
||||
m_locationIndicator(QLatin1String("@@")),
|
||||
m_diffInIndicator(QLatin1Char('+')),
|
||||
m_diffOutIndicator(QLatin1Char('-')),
|
||||
@@ -129,6 +138,8 @@ Internal::DiffFormats DiffAndLogHighlighterPrivate::analyzeLine(const QString &t
|
||||
// file first
|
||||
if (m_filePattern.indexIn(text) == 0)
|
||||
return Internal::DiffFileFormat;
|
||||
if (m_changePattern.indexIn(text) == 0)
|
||||
return Internal::ChangeTextFormat;
|
||||
if (text.startsWith(m_diffInIndicator))
|
||||
return Internal::DiffInFormat;
|
||||
if (text.startsWith(m_diffOutIndicator))
|
||||
@@ -147,9 +158,9 @@ void DiffAndLogHighlighterPrivate::updateOtherFormats()
|
||||
}
|
||||
|
||||
// --- DiffAndLogHighlighter
|
||||
DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern) :
|
||||
DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern, const QRegExp &changePattern) :
|
||||
TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(0)),
|
||||
d_ptr(new DiffAndLogHighlighterPrivate(filePattern))
|
||||
d_ptr(new DiffAndLogHighlighterPrivate(filePattern, changePattern))
|
||||
{
|
||||
d_ptr->q_ptr = this;
|
||||
Q_D(DiffAndLogHighlighter);
|
||||
@@ -160,7 +171,8 @@ DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern) :
|
||||
<< TextEditor::C_ADDED_LINE
|
||||
<< TextEditor::C_REMOVED_LINE
|
||||
<< TextEditor::C_DIFF_FILE
|
||||
<< TextEditor::C_DIFF_LOCATION;
|
||||
<< TextEditor::C_DIFF_LOCATION
|
||||
<< TextEditor::C_LOG_CHANGE_LINE;
|
||||
}
|
||||
setTextFormatCategories(categories);
|
||||
d->updateOtherFormats();
|
||||
|
||||
@@ -52,7 +52,7 @@ class VCSBASE_EXPORT DiffAndLogHighlighter : public TextEditor::SyntaxHighlighte
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(DiffAndLogHighlighter)
|
||||
public:
|
||||
explicit DiffAndLogHighlighter(const QRegExp &filePattern);
|
||||
explicit DiffAndLogHighlighter(const QRegExp &filePattern, const QRegExp &changePattern);
|
||||
~DiffAndLogHighlighter();
|
||||
|
||||
void highlightBlock(const QString &text);
|
||||
|
||||
@@ -736,7 +736,7 @@ void VcsBaseEditorWidget::init()
|
||||
break;
|
||||
}
|
||||
if (hasDiff()) {
|
||||
auto dh = new DiffAndLogHighlighter(d->m_diffFilePattern);
|
||||
auto dh = new DiffAndLogHighlighter(d->m_diffFilePattern, d->m_logEntryPattern);
|
||||
setCodeFoldingSupported(true);
|
||||
textDocument()->setSyntaxHighlighter(dh);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user