forked from qt-creator/qt-creator
GitBaseDiffEditorController: Remove interactive branch expansion
Branches are now being automatically expanded. Change-Id: I6c8986f39fe0ceb71841a2fea46b6038123240b7 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
add_qtc_plugin(DiffEditor
|
add_qtc_plugin(DiffEditor
|
||||||
PLUGIN_DEPENDS Core TextEditor
|
PLUGIN_DEPENDS Core TextEditor
|
||||||
SOURCES
|
SOURCES
|
||||||
descriptionwidgetwatcher.cpp descriptionwidgetwatcher.h
|
|
||||||
diffeditor.cpp diffeditor.h
|
diffeditor.cpp diffeditor.h
|
||||||
diffeditor.qrc
|
diffeditor.qrc
|
||||||
diffeditor_global.h
|
diffeditor_global.h
|
||||||
|
@@ -1,56 +0,0 @@
|
|||||||
// Copyright (C) 2018 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#include "descriptionwidgetwatcher.h"
|
|
||||||
#include "diffeditor.h"
|
|
||||||
#include "diffeditorcontroller.h"
|
|
||||||
|
|
||||||
#include <coreplugin/editormanager/documentmodel.h>
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
#include <texteditor/texteditor.h>
|
|
||||||
|
|
||||||
using namespace Core;
|
|
||||||
|
|
||||||
namespace DiffEditor {
|
|
||||||
|
|
||||||
DescriptionWidgetWatcher::DescriptionWidgetWatcher(DiffEditorController *controller)
|
|
||||||
: QObject(controller), m_document(controller->document())
|
|
||||||
{
|
|
||||||
const QList<IEditor *> editors = DocumentModel::editorsForDocument(controller->document());
|
|
||||||
for (auto *editor : editors) {
|
|
||||||
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor))
|
|
||||||
m_widgets.append(widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(EditorManager::instance(), &EditorManager::editorOpened, this,
|
|
||||||
[this](IEditor *editor) {
|
|
||||||
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) {
|
|
||||||
m_widgets.append(widget);
|
|
||||||
emit descriptionWidgetAdded(widget);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(EditorManager::instance(), &EditorManager::editorAboutToClose, this,
|
|
||||||
[this](IEditor *editor) {
|
|
||||||
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) {
|
|
||||||
emit descriptionWidgetRemoved(widget);
|
|
||||||
m_widgets.removeAll(widget);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<TextEditor::TextEditorWidget *> DescriptionWidgetWatcher::descriptionWidgets() const
|
|
||||||
{
|
|
||||||
return m_widgets;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEditor::TextEditorWidget *DescriptionWidgetWatcher::descriptionWidget(Core::IEditor *editor) const
|
|
||||||
{
|
|
||||||
if (auto diffEditor = qobject_cast<const Internal::DiffEditor *>(editor)) {
|
|
||||||
if (diffEditor->document() == m_document)
|
|
||||||
return diffEditor->descriptionWidget();
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace DiffEditor
|
|
@@ -1,38 +0,0 @@
|
|||||||
// Copyright (C) 2018 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "diffeditor_global.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
class IDocument;
|
|
||||||
class IEditor;
|
|
||||||
}
|
|
||||||
namespace TextEditor { class TextEditorWidget; }
|
|
||||||
|
|
||||||
namespace DiffEditor {
|
|
||||||
|
|
||||||
class DiffEditorController;
|
|
||||||
|
|
||||||
class DIFFEDITOR_EXPORT DescriptionWidgetWatcher : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit DescriptionWidgetWatcher(DiffEditorController *controller);
|
|
||||||
QList<TextEditor::TextEditorWidget *> descriptionWidgets() const;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void descriptionWidgetAdded(TextEditor::TextEditorWidget *editor);
|
|
||||||
void descriptionWidgetRemoved(TextEditor::TextEditorWidget *editor);
|
|
||||||
|
|
||||||
private:
|
|
||||||
TextEditor::TextEditorWidget *descriptionWidget(Core::IEditor *editor) const;
|
|
||||||
|
|
||||||
QList<TextEditor::TextEditorWidget *> m_widgets;
|
|
||||||
Core::IDocument *m_document = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace DiffEditor
|
|
@@ -14,8 +14,6 @@ QtcPlugin {
|
|||||||
]
|
]
|
||||||
|
|
||||||
files: [
|
files: [
|
||||||
"descriptionwidgetwatcher.cpp",
|
|
||||||
"descriptionwidgetwatcher.h",
|
|
||||||
"diffeditor.cpp",
|
"diffeditor.cpp",
|
||||||
"diffeditor.h",
|
"diffeditor.h",
|
||||||
"diffeditor.qrc",
|
"diffeditor.qrc",
|
||||||
|
@@ -42,7 +42,6 @@
|
|||||||
#include <vcsbase/vcscommand.h>
|
#include <vcsbase/vcscommand.h>
|
||||||
#include <vcsbase/vcsoutputwindow.h>
|
#include <vcsbase/vcsoutputwindow.h>
|
||||||
|
|
||||||
#include <diffeditor/descriptionwidgetwatcher.h>
|
|
||||||
#include <diffeditor/diffeditorconstants.h>
|
#include <diffeditor/diffeditorconstants.h>
|
||||||
|
|
||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
@@ -120,125 +119,6 @@ static QString branchesDisplay(const QString &prefix, QStringList *branches, boo
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DescriptionWidgetDecorator : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
DescriptionWidgetDecorator(DescriptionWidgetWatcher *watcher);
|
|
||||||
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void branchListRequested();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool checkContentsUnderCursor(const QTextCursor &cursor) const;
|
|
||||||
void highlightCurrentContents(TextEditor::TextEditorWidget *textEditor,
|
|
||||||
const QTextCursor &cursor);
|
|
||||||
void handleCurrentContents(const QTextCursor &cursor);
|
|
||||||
void addWatch(TextEditor::TextEditorWidget *widget);
|
|
||||||
void removeWatch(TextEditor::TextEditorWidget *widget);
|
|
||||||
|
|
||||||
DescriptionWidgetWatcher *m_watcher;
|
|
||||||
QHash<QObject *, TextEditor::TextEditorWidget *> m_viewportToTextEditor;
|
|
||||||
};
|
|
||||||
|
|
||||||
DescriptionWidgetDecorator::DescriptionWidgetDecorator(DescriptionWidgetWatcher *watcher)
|
|
||||||
: QObject(),
|
|
||||||
m_watcher(watcher)
|
|
||||||
{
|
|
||||||
QList<TextEditor::TextEditorWidget *> widgets = m_watcher->descriptionWidgets();
|
|
||||||
for (auto *widget : widgets)
|
|
||||||
addWatch(widget);
|
|
||||||
|
|
||||||
connect(m_watcher, &DescriptionWidgetWatcher::descriptionWidgetAdded,
|
|
||||||
this, &DescriptionWidgetDecorator::addWatch);
|
|
||||||
connect(m_watcher, &DescriptionWidgetWatcher::descriptionWidgetRemoved,
|
|
||||||
this, &DescriptionWidgetDecorator::removeWatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DescriptionWidgetDecorator::eventFilter(QObject *watched, QEvent *event)
|
|
||||||
{
|
|
||||||
TextEditor::TextEditorWidget *textEditor = m_viewportToTextEditor.value(watched);
|
|
||||||
if (!textEditor)
|
|
||||||
return QObject::eventFilter(watched, event);
|
|
||||||
|
|
||||||
if (event->type() == QEvent::MouseMove) {
|
|
||||||
auto mouseEvent = static_cast<QMouseEvent *>(event);
|
|
||||||
if (mouseEvent->buttons())
|
|
||||||
return QObject::eventFilter(watched, event);
|
|
||||||
|
|
||||||
Qt::CursorShape cursorShape;
|
|
||||||
|
|
||||||
const QTextCursor cursor = textEditor->cursorForPosition(mouseEvent->pos());
|
|
||||||
if (checkContentsUnderCursor(cursor)) {
|
|
||||||
highlightCurrentContents(textEditor, cursor);
|
|
||||||
cursorShape = Qt::PointingHandCursor;
|
|
||||||
} else {
|
|
||||||
textEditor->setExtraSelections(TextEditor::TextEditorWidget::OtherSelection,
|
|
||||||
QList<QTextEdit::ExtraSelection>());
|
|
||||||
cursorShape = Qt::IBeamCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ret = QObject::eventFilter(watched, event);
|
|
||||||
textEditor->viewport()->setCursor(cursorShape);
|
|
||||||
return ret;
|
|
||||||
} else if (event->type() == QEvent::MouseButtonRelease) {
|
|
||||||
auto mouseEvent = static_cast<QMouseEvent *>(event);
|
|
||||||
|
|
||||||
if (mouseEvent->button() == Qt::LeftButton && !(mouseEvent->modifiers() & Qt::ShiftModifier)) {
|
|
||||||
const QTextCursor cursor = textEditor->cursorForPosition(mouseEvent->pos());
|
|
||||||
if (checkContentsUnderCursor(cursor)) {
|
|
||||||
handleCurrentContents(cursor);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QObject::eventFilter(watched, event);
|
|
||||||
}
|
|
||||||
return QObject::eventFilter(watched, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DescriptionWidgetDecorator::checkContentsUnderCursor(const QTextCursor &cursor) const
|
|
||||||
{
|
|
||||||
return cursor.block().text() == Constants::EXPAND_BRANCHES;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptionWidgetDecorator::highlightCurrentContents(
|
|
||||||
TextEditor::TextEditorWidget *textEditor, const QTextCursor &cursor)
|
|
||||||
{
|
|
||||||
QTextEdit::ExtraSelection sel;
|
|
||||||
sel.cursor = cursor;
|
|
||||||
sel.cursor.select(QTextCursor::LineUnderCursor);
|
|
||||||
sel.format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
|
||||||
const QColor textColor = TextEditor::TextEditorSettings::fontSettings().formatFor(TextEditor::C_TEXT).foreground();
|
|
||||||
sel.format.setUnderlineColor(textColor.isValid() ? textColor : textEditor->palette().color(QPalette::WindowText));
|
|
||||||
textEditor->setExtraSelections(TextEditor::TextEditorWidget::OtherSelection,
|
|
||||||
QList<QTextEdit::ExtraSelection>() << sel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptionWidgetDecorator::handleCurrentContents(const QTextCursor &cursor)
|
|
||||||
{
|
|
||||||
QTextCursor copy = cursor;
|
|
||||||
|
|
||||||
copy.select(QTextCursor::LineUnderCursor);
|
|
||||||
copy.removeSelectedText();
|
|
||||||
copy.insertText("Branches: Expanding...");
|
|
||||||
emit branchListRequested();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptionWidgetDecorator::addWatch(TextEditor::TextEditorWidget *widget)
|
|
||||||
{
|
|
||||||
m_viewportToTextEditor.insert(widget->viewport(), widget);
|
|
||||||
widget->viewport()->installEventFilter(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptionWidgetDecorator::removeWatch(TextEditor::TextEditorWidget *widget)
|
|
||||||
{
|
|
||||||
widget->viewport()->removeEventFilter(this);
|
|
||||||
m_viewportToTextEditor.remove(widget->viewport());
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
class GitBaseDiffEditorController : public VcsBaseDiffEditorController
|
class GitBaseDiffEditorController : public VcsBaseDiffEditorController
|
||||||
@@ -259,10 +139,6 @@ public:
|
|||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateBranchList();
|
|
||||||
|
|
||||||
DescriptionWidgetWatcher m_watcher;
|
|
||||||
DescriptionWidgetDecorator m_decorator;
|
|
||||||
QString m_leftCommit;
|
QString m_leftCommit;
|
||||||
QString m_rightCommit;
|
QString m_rightCommit;
|
||||||
};
|
};
|
||||||
@@ -287,13 +163,9 @@ GitBaseDiffEditorController::GitBaseDiffEditorController(IDocument *document,
|
|||||||
const QString &leftCommit,
|
const QString &leftCommit,
|
||||||
const QString &rightCommit) :
|
const QString &rightCommit) :
|
||||||
VcsBaseDiffEditorController(document),
|
VcsBaseDiffEditorController(document),
|
||||||
m_watcher(this),
|
|
||||||
m_decorator(&m_watcher),
|
|
||||||
m_leftCommit(leftCommit),
|
m_leftCommit(leftCommit),
|
||||||
m_rightCommit(rightCommit)
|
m_rightCommit(rightCommit)
|
||||||
{
|
{
|
||||||
connect(&m_decorator, &DescriptionWidgetDecorator::branchListRequested,
|
|
||||||
this, &GitBaseDiffEditorController::updateBranchList);
|
|
||||||
setDisplayName("Git Diff");
|
setDisplayName("Git Diff");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,55 +182,6 @@ void GitBaseDiffEditorController::initialize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitBaseDiffEditorController::updateBranchList()
|
|
||||||
{
|
|
||||||
const QString revision = description().mid(7, 12);
|
|
||||||
if (revision.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto commandHandler = [this](const CommandResult &result) {
|
|
||||||
const QString remotePrefix = "remotes/";
|
|
||||||
const QString localPrefix = "<Local>";
|
|
||||||
const int prefixLength = remotePrefix.length();
|
|
||||||
QString output = BRANCHES_PREFIX;
|
|
||||||
QStringList branches;
|
|
||||||
QString previousRemote = localPrefix;
|
|
||||||
bool first = true;
|
|
||||||
for (const QString &branch : result.cleanedStdOut().split('\n')) {
|
|
||||||
const QString b = branch.mid(2).trimmed();
|
|
||||||
if (b.isEmpty())
|
|
||||||
continue;
|
|
||||||
if (b.startsWith(remotePrefix)) {
|
|
||||||
const int nextSlash = b.indexOf('/', prefixLength);
|
|
||||||
if (nextSlash < 0)
|
|
||||||
continue;
|
|
||||||
const QString remote = b.mid(prefixLength, nextSlash - prefixLength);
|
|
||||||
if (remote != previousRemote) {
|
|
||||||
output += branchesDisplay(previousRemote, &branches, &first) + '\n';
|
|
||||||
branches.clear();
|
|
||||||
previousRemote = remote;
|
|
||||||
}
|
|
||||||
branches << b.mid(nextSlash + 1);
|
|
||||||
} else {
|
|
||||||
branches << b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (branches.isEmpty()) {
|
|
||||||
if (previousRemote == localPrefix)
|
|
||||||
output += Tr::tr("<None>");
|
|
||||||
} else {
|
|
||||||
output += branchesDisplay(previousRemote, &branches, &first);
|
|
||||||
}
|
|
||||||
const QString branchList = output.trimmed();
|
|
||||||
QString newDescription = description();
|
|
||||||
newDescription.replace(Constants::EXPAND_BRANCHES, branchList);
|
|
||||||
setDescription(newDescription);
|
|
||||||
};
|
|
||||||
m_instance->vcsExecWithHandler(baseDirectory(),
|
|
||||||
{"branch", noColorOption, "-a", "--contains", revision},
|
|
||||||
this, commandHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
void GitBaseDiffEditorController::runCommand(const QList<QStringList> &args, QTextCodec *codec)
|
void GitBaseDiffEditorController::runCommand(const QList<QStringList> &args, QTextCodec *codec)
|
||||||
|
Reference in New Issue
Block a user