VCS: Highlight log with diff

Change-Id: I46abd51e5764571138c54df81cc3adbeadb26840
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2013-01-22 14:50:22 +02:00
committed by Orgad Shaneh
parent 8d9710c074
commit 64018aed8a
2 changed files with 36 additions and 20 deletions

View File

@@ -684,14 +684,15 @@ void VcsBaseEditorWidget::init()
// Annotation highlighting depends on contents, which is set later on // Annotation highlighting depends on contents, which is set later on
connect(this, SIGNAL(textChanged()), this, SLOT(slotActivateAnnotation())); connect(this, SIGNAL(textChanged()), this, SLOT(slotActivateAnnotation()));
break; break;
case DiffOutput: { case DiffOutput:
connect(this, SIGNAL(textChanged()), this, SLOT(slotPopulateDiffBrowser()));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(slotDiffCursorPositionChanged()));
break;
}
if (hasDiff()) {
DiffHighlighter *dh = new DiffHighlighter(d->m_diffFilePattern); DiffHighlighter *dh = new DiffHighlighter(d->m_diffFilePattern);
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
baseTextDocument()->setSyntaxHighlighter(dh); baseTextDocument()->setSyntaxHighlighter(dh);
connect(this, SIGNAL(textChanged()), this, SLOT(slotPopulateDiffBrowser()));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(slotDiffCursorPositionChanged()));
}
break;
} }
TextEditor::TextEditorSettings::instance()->initializeEditor(this); TextEditor::TextEditorSettings::instance()->initializeEditor(this);
// override revisions display (green or red bar on the left, marking changes): // override revisions display (green or red bar on the left, marking changes):
@@ -905,6 +906,8 @@ void VcsBaseEditorWidget::contextMenuEvent(QContextMenuEvent *e)
Internal::AbstractTextCursorHandler *handler = d->findTextCursorHandler(cursor); Internal::AbstractTextCursorHandler *handler = d->findTextCursorHandler(cursor);
if (handler != 0) if (handler != 0)
handler->fillContextMenu(menu, d->m_parameters->type); handler->fillContextMenu(menu, d->m_parameters->type);
// Fall-through for log (might have diff)
if (d->m_parameters->type != LogOutput)
break; break;
} }
case DiffOutput: { case DiffOutput: {
@@ -989,20 +992,17 @@ void VcsBaseEditorWidget::mouseReleaseEvent(QMouseEvent *e)
void VcsBaseEditorWidget::mouseDoubleClickEvent(QMouseEvent *e) void VcsBaseEditorWidget::mouseDoubleClickEvent(QMouseEvent *e)
{ {
if (d->m_parameters->type == DiffOutput) { if (hasDiff() && e->button() == Qt::LeftButton && !(e->modifiers() & Qt::ShiftModifier)) {
if (e->button() == Qt::LeftButton &&!(e->modifiers() & Qt::ShiftModifier)) {
QTextCursor cursor = cursorForPosition(e->pos()); QTextCursor cursor = cursorForPosition(e->pos());
jumpToChangeFromDiff(cursor); jumpToChangeFromDiff(cursor);
} }
}
TextEditor::BaseTextEditorWidget::mouseDoubleClickEvent(e); TextEditor::BaseTextEditorWidget::mouseDoubleClickEvent(e);
} }
void VcsBaseEditorWidget::keyPressEvent(QKeyEvent *e) void VcsBaseEditorWidget::keyPressEvent(QKeyEvent *e)
{ {
// Do not intercept return in editable patches. // Do not intercept return in editable patches.
if (d->m_parameters->type == DiffOutput && isReadOnly() if (hasDiff() && isReadOnly() && (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)) {
&& (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)) {
jumpToChangeFromDiff(textCursor()); jumpToChangeFromDiff(textCursor());
return; return;
} }
@@ -1109,7 +1109,7 @@ void VcsBaseEditorWidget::jumpToChangeFromDiff(QTextCursor cursor)
DiffChunk VcsBaseEditorWidget::diffChunk(QTextCursor cursor) const DiffChunk VcsBaseEditorWidget::diffChunk(QTextCursor cursor) const
{ {
DiffChunk rc; DiffChunk rc;
QTC_ASSERT(d->m_parameters->type == DiffOutput, return rc); QTC_ASSERT(hasDiff(), return rc);
// Search back for start of chunk. // Search back for start of chunk.
QTextBlock block = cursor.block(); QTextBlock block = cursor.block();
if (block.isValid() && TextEditor::BaseTextDocumentLayout::foldingIndent(block) <= 1) if (block.isValid() && TextEditor::BaseTextDocumentLayout::foldingIndent(block) <= 1)
@@ -1158,7 +1158,12 @@ void VcsBaseEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
d->m_backgroundColor = fs.toTextCharFormat(TextEditor::C_TEXT) d->m_backgroundColor = fs.toTextCharFormat(TextEditor::C_TEXT)
.brushProperty(QTextFormat::BackgroundBrush).color(); .brushProperty(QTextFormat::BackgroundBrush).color();
if (d->m_parameters->type == DiffOutput) { if (d->m_parameters->type == AnnotateOutput) {
if (BaseAnnotationHighlighter *highlighter = qobject_cast<BaseAnnotationHighlighter *>(baseTextDocument()->syntaxHighlighter())) {
highlighter->setBackgroundColor(d->m_backgroundColor);
highlighter->rehighlight();
}
} else if (hasDiff()) {
if (DiffHighlighter *highlighter = qobject_cast<DiffHighlighter*>(baseTextDocument()->syntaxHighlighter())) { if (DiffHighlighter *highlighter = qobject_cast<DiffHighlighter*>(baseTextDocument()->syntaxHighlighter())) {
static QVector<TextEditor::TextStyle> categories; static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) { if (categories.isEmpty()) {
@@ -1171,11 +1176,6 @@ void VcsBaseEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
highlighter->setFormats(fs.toTextCharFormats(categories)); highlighter->setFormats(fs.toTextCharFormats(categories));
highlighter->rehighlight(); highlighter->rehighlight();
} }
} else if (d->m_parameters->type == AnnotateOutput) {
if (BaseAnnotationHighlighter *highlighter = qobject_cast<BaseAnnotationHighlighter *>(baseTextDocument()->syntaxHighlighter())) {
highlighter->setBackgroundColor(d->m_backgroundColor);
highlighter->rehighlight();
}
} }
} }
@@ -1460,6 +1460,17 @@ bool VcsBaseEditorWidget::isValidRevision(const QString &revision) const
return true; return true;
} }
bool VcsBaseEditorWidget::hasDiff() const
{
switch (d->m_parameters->type) {
case DiffOutput:
case LogOutput:
return true;
default:
return false;
}
}
void VcsBaseEditorWidget::slotApplyDiffChunk() void VcsBaseEditorWidget::slotApplyDiffChunk()
{ {
const QAction *a = qobject_cast<QAction *>(sender()); const QAction *a = qobject_cast<QAction *>(sender());

View File

@@ -257,6 +257,11 @@ protected:
virtual bool isValidRevision(const QString &revision) const; virtual bool isValidRevision(const QString &revision) const;
private: private:
// Indicates if the editor has diff contents. If true, an appropriate
// highlighter is used and double-click inside a diff chunk jumps to
// the relevant file and line
bool hasDiff() const;
// cut out chunk and determine file name. // cut out chunk and determine file name.
DiffChunk diffChunk(QTextCursor cursor) const; DiffChunk diffChunk(QTextCursor cursor) const;