forked from qt-creator/qt-creator
Move git specific stuff out of diff editor plugin
Move it to the git plugin. Change-Id: I8151573ed50df70776f7ebf0475dd41fb84fae83 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
78
src/plugins/diffeditor/descriptionwidgetwatcher.cpp
Normal file
78
src/plugins/diffeditor/descriptionwidgetwatcher.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2018 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#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](IEditor *editor) {
|
||||||
|
if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) {
|
||||||
|
m_widgets.append(widget);
|
||||||
|
emit descriptionWidgetAdded(widget);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
|
||||||
|
[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 (Internal::DiffEditor *diffEditor = qobject_cast<Internal::DiffEditor *>(editor)) {
|
||||||
|
if (diffEditor->document() == m_document)
|
||||||
|
return diffEditor->descriptionWidget();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace DiffEditor
|
60
src/plugins/diffeditor/descriptionwidgetwatcher.h
Normal file
60
src/plugins/diffeditor/descriptionwidgetwatcher.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2018 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#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
|
@@ -81,22 +81,11 @@ public:
|
|||||||
|
|
||||||
virtual QSize sizeHint() const override;
|
virtual QSize sizeHint() const override;
|
||||||
|
|
||||||
signals:
|
|
||||||
void requestBranchList();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QMouseEvent *e) override;
|
|
||||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
||||||
|
|
||||||
void setDisplaySettings(const DisplaySettings &ds) override;
|
void setDisplaySettings(const DisplaySettings &ds) override;
|
||||||
void setMarginSettings(const MarginSettings &ms) override;
|
void setMarginSettings(const MarginSettings &ms) override;
|
||||||
|
|
||||||
bool findContentsUnderCursor(const QTextCursor &cursor);
|
|
||||||
void highlightCurrentContents();
|
|
||||||
void handleCurrentContents();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTextCursor m_currentCursor;
|
|
||||||
Core::IContext *m_context;
|
Core::IContext *m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -153,68 +142,6 @@ void DescriptionEditorWidget::setMarginSettings(const MarginSettings &ms)
|
|||||||
TextEditorWidget::setMarginSettings(MarginSettings());
|
TextEditorWidget::setMarginSettings(MarginSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptionEditorWidget::mouseMoveEvent(QMouseEvent *e)
|
|
||||||
{
|
|
||||||
if (e->buttons()) {
|
|
||||||
TextEditorWidget::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;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEditorWidget::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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEditorWidget::mouseReleaseEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DescriptionEditorWidget::findContentsUnderCursor(const QTextCursor &cursor)
|
|
||||||
{
|
|
||||||
m_currentCursor = cursor;
|
|
||||||
return cursor.block().text() == Constants::EXPAND_BRANCHES;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptionEditorWidget::highlightCurrentContents()
|
|
||||||
{
|
|
||||||
QTextEdit::ExtraSelection sel;
|
|
||||||
sel.cursor = m_currentCursor;
|
|
||||||
sel.cursor.select(QTextCursor::LineUnderCursor);
|
|
||||||
sel.format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
|
||||||
const QColor textColor = TextEditorSettings::fontSettings().formatFor(C_TEXT).foreground();
|
|
||||||
sel.format.setUnderlineColor(textColor.isValid() ? textColor : palette().color(QPalette::Foreground));
|
|
||||||
setExtraSelections(TextEditorWidget::OtherSelection,
|
|
||||||
QList<QTextEdit::ExtraSelection>() << sel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DescriptionEditorWidget::handleCurrentContents()
|
|
||||||
{
|
|
||||||
m_currentCursor.select(QTextCursor::LineUnderCursor);
|
|
||||||
m_currentCursor.removeSelectedText();
|
|
||||||
m_currentCursor.insertText("Branches: Expanding...");
|
|
||||||
emit requestBranchList();
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////// DiffEditor //////////////////////////////////
|
///////////////////////////////// DiffEditor //////////////////////////////////
|
||||||
|
|
||||||
DiffEditor::DiffEditor()
|
DiffEditor::DiffEditor()
|
||||||
@@ -296,8 +223,6 @@ void DiffEditor::setDocument(QSharedPointer<DiffEditorDocument> doc)
|
|||||||
|
|
||||||
m_document = doc;
|
m_document = doc;
|
||||||
|
|
||||||
connect(m_descriptionWidget, &DescriptionEditorWidget::requestBranchList,
|
|
||||||
m_document.data(), &DiffEditorDocument::requestMoreInformation);
|
|
||||||
connect(m_document.data(), &DiffEditorDocument::documentChanged,
|
connect(m_document.data(), &DiffEditorDocument::documentChanged,
|
||||||
this, &DiffEditor::documentHasChanged);
|
this, &DiffEditor::documentHasChanged);
|
||||||
connect(m_document.data(), &DiffEditorDocument::descriptionChanged,
|
connect(m_document.data(), &DiffEditorDocument::descriptionChanged,
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
DEFINES += DIFFEDITOR_LIBRARY
|
DEFINES += DIFFEDITOR_LIBRARY
|
||||||
include(../../qtcreatorplugin.pri)
|
include(../../qtcreatorplugin.pri)
|
||||||
|
|
||||||
HEADERS += diffeditor_global.h \
|
HEADERS += \
|
||||||
|
descriptionwidgetwatcher.h \
|
||||||
|
diffeditor_global.h \
|
||||||
diffeditor.h \
|
diffeditor.h \
|
||||||
diffeditorconstants.h \
|
diffeditorconstants.h \
|
||||||
diffeditorcontroller.h \
|
diffeditorcontroller.h \
|
||||||
@@ -17,7 +19,9 @@ HEADERS += diffeditor_global.h \
|
|||||||
unifieddiffeditorwidget.h \
|
unifieddiffeditorwidget.h \
|
||||||
diffeditoricons.h
|
diffeditoricons.h
|
||||||
|
|
||||||
SOURCES += diffeditor.cpp \
|
SOURCES += \
|
||||||
|
descriptionwidgetwatcher.cpp \
|
||||||
|
diffeditor.cpp \
|
||||||
diffeditorcontroller.cpp \
|
diffeditorcontroller.cpp \
|
||||||
diffeditordocument.cpp \
|
diffeditordocument.cpp \
|
||||||
diffeditorfactory.cpp \
|
diffeditorfactory.cpp \
|
||||||
|
@@ -14,6 +14,8 @@ QtcPlugin {
|
|||||||
]
|
]
|
||||||
|
|
||||||
files: [
|
files: [
|
||||||
|
"descriptionwidgetwatcher.cpp",
|
||||||
|
"descriptionwidgetwatcher.h",
|
||||||
"diffeditor.cpp",
|
"diffeditor.cpp",
|
||||||
"diffeditor.h",
|
"diffeditor.h",
|
||||||
"diffeditor.qrc",
|
"diffeditor.qrc",
|
||||||
|
@@ -41,7 +41,5 @@ const char UNIFIED_VIEW_ID[] = "DiffEditor.Unified";
|
|||||||
|
|
||||||
const char G_TOOLS_DIFF[] = "QtCreator.Group.Tools.Options";
|
const char G_TOOLS_DIFF[] = "QtCreator.Group.Tools.Options";
|
||||||
|
|
||||||
const char EXPAND_BRANCHES[] = "Branches: <Expand>";
|
|
||||||
|
|
||||||
} // namespace Constants
|
} // namespace Constants
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
@@ -65,12 +65,6 @@ bool DiffEditorController::ignoreWhitespace() const
|
|||||||
return m_document->ignoreWhitespace();
|
return m_document->ignoreWhitespace();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DiffEditorController::revisionFromDescription() const
|
|
||||||
{
|
|
||||||
// TODO: This is specific for git and does not belong here at all!
|
|
||||||
return m_document->description().mid(7, 12);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DiffEditorController::makePatch(int fileIndex, int chunkIndex,
|
QString DiffEditorController::makePatch(int fileIndex, int chunkIndex,
|
||||||
PatchOptions options) const
|
PatchOptions options) const
|
||||||
{
|
{
|
||||||
@@ -105,18 +99,9 @@ void DiffEditorController::setDescription(const QString &description)
|
|||||||
m_document->setDescription(description);
|
m_document->setDescription(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorController::branchesReceived(const QString &branches)
|
QString DiffEditorController::description() const
|
||||||
{
|
{
|
||||||
QString tmp = m_document->description();
|
return m_document->description();
|
||||||
tmp.replace(Constants::EXPAND_BRANCHES, branches);
|
|
||||||
m_document->setDescription(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiffEditorController::requestMoreInformation()
|
|
||||||
{
|
|
||||||
const QString rev = revisionFromDescription();
|
|
||||||
if (!rev.isEmpty())
|
|
||||||
emit requestInformationForCommit(rev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -51,8 +51,6 @@ public:
|
|||||||
int contextLineCount() const;
|
int contextLineCount() const;
|
||||||
bool ignoreWhitespace() const;
|
bool ignoreWhitespace() const;
|
||||||
|
|
||||||
QString revisionFromDescription() const;
|
|
||||||
|
|
||||||
enum PatchOption {
|
enum PatchOption {
|
||||||
NoOption = 0,
|
NoOption = 0,
|
||||||
Revert = 1,
|
Revert = 1,
|
||||||
@@ -65,13 +63,12 @@ public:
|
|||||||
const QString &displayName);
|
const QString &displayName);
|
||||||
static DiffEditorController *controller(Core::IDocument *document);
|
static DiffEditorController *controller(Core::IDocument *document);
|
||||||
|
|
||||||
void branchesReceived(const QString &branches);
|
|
||||||
void requestChunkActions(QMenu *menu, int fileIndex, int chunkIndex);
|
void requestChunkActions(QMenu *menu, int fileIndex, int chunkIndex);
|
||||||
bool chunkExists(int fileIndex, int chunkIndex) const;
|
bool chunkExists(int fileIndex, int chunkIndex) const;
|
||||||
|
Core::IDocument *document() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex);
|
void chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex);
|
||||||
void requestInformationForCommit(const QString &revision);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// reloadFinished() should be called
|
// reloadFinished() should be called
|
||||||
@@ -84,14 +81,11 @@ protected:
|
|||||||
const QString &baseDirectory = QString(),
|
const QString &baseDirectory = QString(),
|
||||||
const QString &startupFile = QString());
|
const QString &startupFile = QString());
|
||||||
void setDescription(const QString &description);
|
void setDescription(const QString &description);
|
||||||
|
QString description() const;
|
||||||
void forceContextLineCount(int lines);
|
void forceContextLineCount(int lines);
|
||||||
Core::IDocument *document() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void requestMoreInformation();
|
|
||||||
|
|
||||||
Internal::DiffEditorDocument *const m_document;
|
Internal::DiffEditorDocument *const m_document;
|
||||||
|
|
||||||
bool m_isReloading = false;
|
bool m_isReloading = false;
|
||||||
|
|
||||||
friend class Internal::DiffEditorDocument;
|
friend class Internal::DiffEditorDocument;
|
||||||
|
@@ -69,11 +69,6 @@ void DiffEditorDocument::setController(DiffEditorController *controller)
|
|||||||
if (m_controller)
|
if (m_controller)
|
||||||
m_controller->deleteLater();
|
m_controller->deleteLater();
|
||||||
m_controller = controller;
|
m_controller = controller;
|
||||||
|
|
||||||
if (m_controller) {
|
|
||||||
connect(this, &DiffEditorDocument::requestMoreInformation,
|
|
||||||
m_controller, &DiffEditorController::requestMoreInformation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditorController *DiffEditorDocument::controller() const
|
DiffEditorController *DiffEditorDocument::controller() const
|
||||||
|
@@ -90,7 +90,6 @@ signals:
|
|||||||
void temporaryStateChanged();
|
void temporaryStateChanged();
|
||||||
void documentChanged();
|
void documentChanged();
|
||||||
void descriptionChanged();
|
void descriptionChanged();
|
||||||
void requestMoreInformation();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void beginReload();
|
void beginReload();
|
||||||
|
@@ -62,9 +62,14 @@
|
|||||||
#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 <diffeditor/diffeditorcontroller.h>
|
#include <diffeditor/diffeditorcontroller.h>
|
||||||
#include <diffeditor/diffutils.h>
|
#include <diffeditor/diffutils.h>
|
||||||
|
|
||||||
|
#include <texteditor/fontsettings.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
@@ -76,8 +81,9 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QTextCodec>
|
#include <QTextBlock>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
#include <QTextCodec>
|
||||||
|
|
||||||
const char GIT_DIRECTORY[] = ".git";
|
const char GIT_DIRECTORY[] = ".git";
|
||||||
const char graphLogFormatC[] = "%h %d %an %s %ci";
|
const char graphLogFormatC[] = "%h %d %an %s %ci";
|
||||||
@@ -112,6 +118,153 @@ const unsigned silentFlags = unsigned(VcsCommand::SuppressCommandLogging
|
|||||||
| VcsCommand::SuppressStdErr
|
| VcsCommand::SuppressStdErr
|
||||||
| VcsCommand::SuppressFailMessage);
|
| VcsCommand::SuppressFailMessage);
|
||||||
|
|
||||||
|
static QString branchesDisplay(const QString &prefix, QStringList *branches, bool *first)
|
||||||
|
{
|
||||||
|
const int limit = 12;
|
||||||
|
const int count = branches->count();
|
||||||
|
int more = 0;
|
||||||
|
QString output;
|
||||||
|
if (*first)
|
||||||
|
*first = false;
|
||||||
|
else
|
||||||
|
output += QString(sizeof(BRANCHES_PREFIX) - 1, ' '); // Align
|
||||||
|
output += prefix + ": ";
|
||||||
|
// If there are more than 'limit' branches, list limit/2 (first limit/4 and last limit/4)
|
||||||
|
if (count > limit) {
|
||||||
|
const int leave = limit / 2;
|
||||||
|
more = count - leave;
|
||||||
|
branches->erase(branches->begin() + leave / 2 + 1, branches->begin() + count - leave / 2);
|
||||||
|
(*branches)[leave / 2] = "...";
|
||||||
|
}
|
||||||
|
output += branches->join(", ");
|
||||||
|
//: Displayed after the untranslated message "Branches: branch1, branch2 'and %n more'"
|
||||||
|
// in git show.
|
||||||
|
if (more > 0)
|
||||||
|
output += ' ' + GitClient::tr("and %n more", 0, more);
|
||||||
|
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) {
|
||||||
|
QMouseEvent *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) {
|
||||||
|
QMouseEvent *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::Foreground));
|
||||||
|
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 GitDiffEditorController : public VcsBaseDiffEditorController
|
class GitDiffEditorController : public VcsBaseDiffEditorController
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -124,13 +277,75 @@ protected:
|
|||||||
|
|
||||||
QStringList addConfigurationArguments(const QStringList &args) const;
|
QStringList addConfigurationArguments(const QStringList &args) const;
|
||||||
QStringList addHeadWhenCommandInProgress() const;
|
QStringList addHeadWhenCommandInProgress() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateBranchList();
|
||||||
|
|
||||||
|
DescriptionWidgetWatcher m_watcher;
|
||||||
|
DescriptionWidgetDecorator m_decorator;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitDiffEditorController::GitDiffEditorController(IDocument *document, const QString &workingDirectory) :
|
GitDiffEditorController::GitDiffEditorController(IDocument *document, const QString &workingDirectory) :
|
||||||
VcsBaseDiffEditorController(document, GitPlugin::client(), workingDirectory)
|
VcsBaseDiffEditorController(document, GitPlugin::client(), workingDirectory),
|
||||||
|
m_watcher(this),
|
||||||
|
m_decorator(&m_watcher)
|
||||||
{
|
{
|
||||||
|
connect(&m_decorator, &DescriptionWidgetDecorator::branchListRequested,
|
||||||
|
this, &GitDiffEditorController::updateBranchList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GitDiffEditorController::updateBranchList()
|
||||||
|
{
|
||||||
|
const QString revision = description().mid(7, 12);
|
||||||
|
if (revision.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const QString workingDirectory = baseDirectory();
|
||||||
|
VcsCommand *command = GitPlugin::client()->vcsExec(
|
||||||
|
workingDirectory, {"branch", noColorOption, "-a", "--contains", revision}, nullptr,
|
||||||
|
false, 0, workingDirectory);
|
||||||
|
connect(command, &VcsCommand::stdOutText, [this](const QString &text) {
|
||||||
|
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 : text.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("<None>");
|
||||||
|
} else {
|
||||||
|
output += branchesDisplay(previousRemote, &branches, &first);
|
||||||
|
}
|
||||||
|
const QString branchList = output.trimmed();
|
||||||
|
QString newDescription = description();
|
||||||
|
newDescription.replace(Constants::EXPAND_BRANCHES, branchList);
|
||||||
|
setDescription(newDescription);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
|
||||||
void GitDiffEditorController::runCommand(const QList<QStringList> &args, QTextCodec *codec)
|
void GitDiffEditorController::runCommand(const QList<QStringList> &args, QTextCodec *codec)
|
||||||
{
|
{
|
||||||
VcsBaseDiffEditorController::runCommand(args, diffExecutionFlags(), codec);
|
VcsBaseDiffEditorController::runCommand(args, diffExecutionFlags(), codec);
|
||||||
@@ -679,8 +894,6 @@ void GitClient::requestReload(const QString &documentId, const QString &source,
|
|||||||
|
|
||||||
connect(controller, &DiffEditorController::chunkActionsRequested,
|
connect(controller, &DiffEditorController::chunkActionsRequested,
|
||||||
this, &GitClient::chunkActionsRequested, Qt::DirectConnection);
|
this, &GitClient::chunkActionsRequested, Qt::DirectConnection);
|
||||||
connect(controller, &DiffEditorController::requestInformationForCommit,
|
|
||||||
this, &GitClient::branchesForCommit);
|
|
||||||
|
|
||||||
VcsBasePlugin::setSource(document, sourceCopy);
|
VcsBasePlugin::setSource(document, sourceCopy);
|
||||||
EditorManager::activateEditorForDocument(document);
|
EditorManager::activateEditorForDocument(document);
|
||||||
@@ -1379,76 +1592,6 @@ void GitClient::synchronousTagsForCommit(const QString &workingDirectory, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString branchesDisplay(const QString &prefix, QStringList *branches, bool *first)
|
|
||||||
{
|
|
||||||
const int limit = 12;
|
|
||||||
const int count = branches->count();
|
|
||||||
int more = 0;
|
|
||||||
QString output;
|
|
||||||
if (*first)
|
|
||||||
*first = false;
|
|
||||||
else
|
|
||||||
output += QString(sizeof(BRANCHES_PREFIX) - 1, ' '); // Align
|
|
||||||
output += prefix + ": ";
|
|
||||||
// If there are more than 'limit' branches, list limit/2 (first limit/4 and last limit/4)
|
|
||||||
if (count > limit) {
|
|
||||||
const int leave = limit / 2;
|
|
||||||
more = count - leave;
|
|
||||||
branches->erase(branches->begin() + leave / 2 + 1, branches->begin() + count - leave / 2);
|
|
||||||
(*branches)[leave / 2] = "...";
|
|
||||||
}
|
|
||||||
output += branches->join(", ");
|
|
||||||
//: Displayed after the untranslated message "Branches: branch1, branch2 'and %n more'"
|
|
||||||
// in git show.
|
|
||||||
if (more > 0)
|
|
||||||
output += ' ' + GitClient::tr("and %n more", 0, more);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GitClient::branchesForCommit(const QString &revision)
|
|
||||||
{
|
|
||||||
auto controller = qobject_cast<DiffEditorController *>(sender());
|
|
||||||
QString workingDirectory = controller->baseDirectory();
|
|
||||||
VcsCommand *command = vcsExec(
|
|
||||||
workingDirectory, {"branch", noColorOption, "-a", "--contains", revision}, nullptr,
|
|
||||||
false, 0, workingDirectory);
|
|
||||||
connect(command, &VcsCommand::stdOutText, controller, [controller](const QString &text) {
|
|
||||||
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 : text.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("<None>");
|
|
||||||
} else {
|
|
||||||
output += branchesDisplay(previousRemote, &branches, &first);
|
|
||||||
}
|
|
||||||
controller->branchesReceived(output.trimmed());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GitClient::isRemoteCommit(const QString &workingDirectory, const QString &commit)
|
bool GitClient::isRemoteCommit(const QString &workingDirectory, const QString &commit)
|
||||||
{
|
{
|
||||||
return !vcsFullySynchronousExec(
|
return !vcsFullySynchronousExec(
|
||||||
@@ -2110,7 +2253,7 @@ QString GitClient::extendedShowDescription(const QString &workingDirectory, cons
|
|||||||
// Empty line before headers and commit message
|
// Empty line before headers and commit message
|
||||||
const int emptyLine = modText.indexOf("\n\n");
|
const int emptyLine = modText.indexOf("\n\n");
|
||||||
if (emptyLine != -1)
|
if (emptyLine != -1)
|
||||||
modText.insert(emptyLine, QString('\n') + DiffEditor::Constants::EXPAND_BRANCHES);
|
modText.insert(emptyLine, QString('\n') + Constants::EXPAND_BRANCHES);
|
||||||
|
|
||||||
return modText;
|
return modText;
|
||||||
}
|
}
|
||||||
|
@@ -330,7 +330,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
void finishSubmoduleUpdate();
|
void finishSubmoduleUpdate();
|
||||||
void chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex);
|
void chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex);
|
||||||
void branchesForCommit(const QString &revision);
|
|
||||||
|
|
||||||
void stage(DiffEditor::DiffEditorController *diffController,
|
void stage(DiffEditor::DiffEditorController *diffController,
|
||||||
const QString &patch, bool revert);
|
const QString &patch, bool revert);
|
||||||
|
@@ -53,5 +53,7 @@ const char C_GITEDITORID[] = "Git Editor";
|
|||||||
|
|
||||||
const int OBSOLETE_COMMIT_AGE_IN_DAYS = 90;
|
const int OBSOLETE_COMMIT_AGE_IN_DAYS = 90;
|
||||||
|
|
||||||
|
const char EXPAND_BRANCHES[] = "Branches: <Expand>";
|
||||||
|
|
||||||
} // namespace Constants
|
} // namespace Constants
|
||||||
} // namespace Git
|
} // namespace Git
|
||||||
|
Reference in New Issue
Block a user