Git: Add on-demand branches expanding

Make "branches expanding" on demand and asynchronous.
After "git show" there is clickable text: "Branches: <Expand>" in
description. If user clicks this text then branches for commit is
triggered and done asynchronously.

Task-number: QTCREATORBUG-11293
Done-with: Przemyslaw Gorszkowski <pgorszkowski@gmail.com>
Change-Id: I772cfef823d3f95e2b3060dfb5973157d81fc11a
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2014-06-24 10:53:03 +03:00
committed by Orgad Shaneh
parent 281aa9e0d6
commit d6583f0f47
6 changed files with 148 additions and 17 deletions

View File

@@ -52,6 +52,7 @@
#include <QComboBox>
#include <QFileInfo>
#include <QTextCodec>
#include <QTextBlock>
static const char settingsGroupC[] = "DiffEditor";
static const char diffEditorTypeKeyC[] = "DiffEditorType";
@@ -74,6 +75,9 @@ public:
DescriptionEditorWidget(QWidget *parent = 0);
virtual QSize sizeHint() const;
signals:
void expandBranchesRequested();
public slots:
void setDisplaySettings(const DisplaySettings &ds);
@@ -84,6 +88,15 @@ protected:
editor->document()->setId("DiffEditor.DescriptionEditor");
return editor;
}
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
bool findContentsUnderCursor(const QTextCursor &cursor);
void highlightCurrentContents();
void handleCurrentContents();
private:
QTextCursor m_currentCursor;
};
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
@@ -118,6 +131,67 @@ void DescriptionEditorWidget::setDisplaySettings(const DisplaySettings &ds)
BaseTextEditorWidget::setDisplaySettings(settings);
}
void DescriptionEditorWidget::mouseMoveEvent(QMouseEvent *e)
{
if (e->buttons()) {
TextEditor::BaseTextEditorWidget::mouseMoveEvent(e);
return;
}
Qt::CursorShape cursorShape;
const QTextCursor cursor = cursorForPosition(e->pos());
if (findContentsUnderCursor(cursor)) {
highlightCurrentContents();
cursorShape = Qt::PointingHandCursor;
} else {
setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>());
cursorShape = Qt::IBeamCursor;
}
TextEditor::BaseTextEditorWidget::mouseMoveEvent(e);
viewport()->setCursor(cursorShape);
}
void DescriptionEditorWidget::mouseReleaseEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton && !(e->modifiers() & Qt::ShiftModifier)) {
const QTextCursor cursor = cursorForPosition(e->pos());
if (findContentsUnderCursor(cursor)) {
handleCurrentContents();
e->accept();
return;
}
}
TextEditor::BaseTextEditorWidget::mouseReleaseEvent(e);
}
bool DescriptionEditorWidget::findContentsUnderCursor(const QTextCursor &cursor)
{
m_currentCursor = cursor;
return cursor.block().text() == QLatin1String(Constants::EXPAND_BRANCHES);
}
void DescriptionEditorWidget::highlightCurrentContents()
{
QTextEdit::ExtraSelection sel;
sel.cursor = m_currentCursor;
sel.cursor.select(QTextCursor::LineUnderCursor);
sel.format.setFontUnderline(true);
setExtraSelections(BaseTextEditorWidget::OtherSelection,
QList<QTextEdit::ExtraSelection>() << sel);
}
void DescriptionEditorWidget::handleCurrentContents()
{
m_currentCursor.select(QTextCursor::LineUnderCursor);
m_currentCursor.removeSelectedText();
m_currentCursor.insertText(QLatin1String("Branches: Expanding..."));
emit expandBranchesRequested();
}
} // namespace Internal
///////////////////////////////// DiffEditor //////////////////////////////////
@@ -179,6 +253,8 @@ void DiffEditor::ctor()
setWidget(splitter);
connect(m_descriptionWidget, SIGNAL(expandBranchesRequested()),
m_document->controller(), SLOT(expandBranchesRequested()));
connect(TextEditorSettings::instance(),
SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)),
m_descriptionWidget,