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;
|
||||
|
||||
signals:
|
||||
void requestBranchList();
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
|
||||
void setDisplaySettings(const DisplaySettings &ds) override;
|
||||
void setMarginSettings(const MarginSettings &ms) override;
|
||||
|
||||
bool findContentsUnderCursor(const QTextCursor &cursor);
|
||||
void highlightCurrentContents();
|
||||
void handleCurrentContents();
|
||||
|
||||
private:
|
||||
QTextCursor m_currentCursor;
|
||||
Core::IContext *m_context;
|
||||
};
|
||||
|
||||
@@ -153,68 +142,6 @@ void DescriptionEditorWidget::setMarginSettings(const MarginSettings &ms)
|
||||
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()
|
||||
@@ -296,8 +223,6 @@ void DiffEditor::setDocument(QSharedPointer<DiffEditorDocument> doc)
|
||||
|
||||
m_document = doc;
|
||||
|
||||
connect(m_descriptionWidget, &DescriptionEditorWidget::requestBranchList,
|
||||
m_document.data(), &DiffEditorDocument::requestMoreInformation);
|
||||
connect(m_document.data(), &DiffEditorDocument::documentChanged,
|
||||
this, &DiffEditor::documentHasChanged);
|
||||
connect(m_document.data(), &DiffEditorDocument::descriptionChanged,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
DEFINES += DIFFEDITOR_LIBRARY
|
||||
include(../../qtcreatorplugin.pri)
|
||||
|
||||
HEADERS += diffeditor_global.h \
|
||||
HEADERS += \
|
||||
descriptionwidgetwatcher.h \
|
||||
diffeditor_global.h \
|
||||
diffeditor.h \
|
||||
diffeditorconstants.h \
|
||||
diffeditorcontroller.h \
|
||||
@@ -17,7 +19,9 @@ HEADERS += diffeditor_global.h \
|
||||
unifieddiffeditorwidget.h \
|
||||
diffeditoricons.h
|
||||
|
||||
SOURCES += diffeditor.cpp \
|
||||
SOURCES += \
|
||||
descriptionwidgetwatcher.cpp \
|
||||
diffeditor.cpp \
|
||||
diffeditorcontroller.cpp \
|
||||
diffeditordocument.cpp \
|
||||
diffeditorfactory.cpp \
|
||||
|
||||
@@ -14,6 +14,8 @@ QtcPlugin {
|
||||
]
|
||||
|
||||
files: [
|
||||
"descriptionwidgetwatcher.cpp",
|
||||
"descriptionwidgetwatcher.h",
|
||||
"diffeditor.cpp",
|
||||
"diffeditor.h",
|
||||
"diffeditor.qrc",
|
||||
|
||||
@@ -41,7 +41,5 @@ const char UNIFIED_VIEW_ID[] = "DiffEditor.Unified";
|
||||
|
||||
const char G_TOOLS_DIFF[] = "QtCreator.Group.Tools.Options";
|
||||
|
||||
const char EXPAND_BRANCHES[] = "Branches: <Expand>";
|
||||
|
||||
} // namespace Constants
|
||||
} // namespace DiffEditor
|
||||
|
||||
@@ -65,12 +65,6 @@ bool DiffEditorController::ignoreWhitespace() const
|
||||
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,
|
||||
PatchOptions options) const
|
||||
{
|
||||
@@ -105,18 +99,9 @@ void DiffEditorController::setDescription(const QString &description)
|
||||
m_document->setDescription(description);
|
||||
}
|
||||
|
||||
void DiffEditorController::branchesReceived(const QString &branches)
|
||||
QString DiffEditorController::description() const
|
||||
{
|
||||
QString tmp = 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);
|
||||
return m_document->description();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,8 +51,6 @@ public:
|
||||
int contextLineCount() const;
|
||||
bool ignoreWhitespace() const;
|
||||
|
||||
QString revisionFromDescription() const;
|
||||
|
||||
enum PatchOption {
|
||||
NoOption = 0,
|
||||
Revert = 1,
|
||||
@@ -65,13 +63,12 @@ public:
|
||||
const QString &displayName);
|
||||
static DiffEditorController *controller(Core::IDocument *document);
|
||||
|
||||
void branchesReceived(const QString &branches);
|
||||
void requestChunkActions(QMenu *menu, int fileIndex, int chunkIndex);
|
||||
bool chunkExists(int fileIndex, int chunkIndex) const;
|
||||
Core::IDocument *document() const;
|
||||
|
||||
signals:
|
||||
void chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex);
|
||||
void requestInformationForCommit(const QString &revision);
|
||||
|
||||
protected:
|
||||
// reloadFinished() should be called
|
||||
@@ -84,14 +81,11 @@ protected:
|
||||
const QString &baseDirectory = QString(),
|
||||
const QString &startupFile = QString());
|
||||
void setDescription(const QString &description);
|
||||
QString description() const;
|
||||
void forceContextLineCount(int lines);
|
||||
Core::IDocument *document() const;
|
||||
|
||||
private:
|
||||
void requestMoreInformation();
|
||||
|
||||
Internal::DiffEditorDocument *const m_document;
|
||||
|
||||
bool m_isReloading = false;
|
||||
|
||||
friend class Internal::DiffEditorDocument;
|
||||
|
||||
@@ -69,11 +69,6 @@ void DiffEditorDocument::setController(DiffEditorController *controller)
|
||||
if (m_controller)
|
||||
m_controller->deleteLater();
|
||||
m_controller = controller;
|
||||
|
||||
if (m_controller) {
|
||||
connect(this, &DiffEditorDocument::requestMoreInformation,
|
||||
m_controller, &DiffEditorController::requestMoreInformation);
|
||||
}
|
||||
}
|
||||
|
||||
DiffEditorController *DiffEditorDocument::controller() const
|
||||
|
||||
@@ -90,7 +90,6 @@ signals:
|
||||
void temporaryStateChanged();
|
||||
void documentChanged();
|
||||
void descriptionChanged();
|
||||
void requestMoreInformation();
|
||||
|
||||
private:
|
||||
void beginReload();
|
||||
|
||||
Reference in New Issue
Block a user