forked from qt-creator/qt-creator
Add DiffEditorController
Change-Id: Ic2f4a38d2ed08426ca7e5229d959b10fa545c129 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -49,15 +49,19 @@ namespace DiffEditor {
|
|||||||
///////////////////////////////// DiffEditor //////////////////////////////////
|
///////////////////////////////// DiffEditor //////////////////////////////////
|
||||||
|
|
||||||
DiffEditor::DiffEditor(DiffEditorWidget *editorWidget)
|
DiffEditor::DiffEditor(DiffEditorWidget *editorWidget)
|
||||||
: IEditor(0),
|
: IEditor(0)
|
||||||
m_toolWidget(0),
|
, m_toolWidget(0)
|
||||||
m_file(new Internal::DiffEditorFile(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE), this)),
|
, m_file(new Internal::DiffEditorFile(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE), this))
|
||||||
m_editorWidget(editorWidget),
|
, m_editorWidget(editorWidget)
|
||||||
m_entriesComboBox(0)
|
, m_diffEditorController(0)
|
||||||
|
, m_entriesComboBox(0)
|
||||||
{
|
{
|
||||||
setWidget(editorWidget);
|
setWidget(editorWidget);
|
||||||
connect(m_editorWidget, SIGNAL(navigatedToDiffFile(int)),
|
m_diffEditorController = editorWidget ? editorWidget->diffEditorController() : 0;
|
||||||
this, SLOT(activateEntry(int)));
|
if (m_diffEditorController) {
|
||||||
|
connect(m_diffEditorController, SIGNAL(currentDiffFileIndexChanged(int)),
|
||||||
|
this, SLOT(activateEntry(int)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditor::~DiffEditor()
|
DiffEditor::~DiffEditor()
|
||||||
@@ -123,8 +127,6 @@ QWidget *DiffEditor::toolBar()
|
|||||||
whitespaceButton->setText(tr("Ignore Whitespace"));
|
whitespaceButton->setText(tr("Ignore Whitespace"));
|
||||||
whitespaceButton->setCheckable(true);
|
whitespaceButton->setCheckable(true);
|
||||||
whitespaceButton->setChecked(true);
|
whitespaceButton->setChecked(true);
|
||||||
connect(whitespaceButton, SIGNAL(clicked(bool)),
|
|
||||||
m_editorWidget, SLOT(setIgnoreWhitespaces(bool)));
|
|
||||||
m_toolWidget->addWidget(whitespaceButton);
|
m_toolWidget->addWidget(whitespaceButton);
|
||||||
|
|
||||||
QLabel *contextLabel = new QLabel(m_toolWidget);
|
QLabel *contextLabel = new QLabel(m_toolWidget);
|
||||||
@@ -137,8 +139,6 @@ QWidget *DiffEditor::toolBar()
|
|||||||
contextSpinBox->setValue(3);
|
contextSpinBox->setValue(3);
|
||||||
contextSpinBox->setFrame(false);
|
contextSpinBox->setFrame(false);
|
||||||
contextSpinBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); // Mac Qt5
|
contextSpinBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); // Mac Qt5
|
||||||
connect(contextSpinBox, SIGNAL(valueChanged(int)),
|
|
||||||
m_editorWidget, SLOT(setContextLinesNumber(int)));
|
|
||||||
m_toolWidget->addWidget(contextSpinBox);
|
m_toolWidget->addWidget(contextSpinBox);
|
||||||
|
|
||||||
QToolButton *toggleSync = new QToolButton(m_toolWidget);
|
QToolButton *toggleSync = new QToolButton(m_toolWidget);
|
||||||
@@ -146,21 +146,29 @@ QWidget *DiffEditor::toolBar()
|
|||||||
toggleSync->setCheckable(true);
|
toggleSync->setCheckable(true);
|
||||||
toggleSync->setChecked(true);
|
toggleSync->setChecked(true);
|
||||||
toggleSync->setToolTip(tr("Synchronize Horizontal Scroll Bars"));
|
toggleSync->setToolTip(tr("Synchronize Horizontal Scroll Bars"));
|
||||||
connect(toggleSync, SIGNAL(clicked(bool)),
|
|
||||||
m_editorWidget, SLOT(setHorizontalScrollBarSynchronization(bool)));
|
|
||||||
m_toolWidget->addWidget(toggleSync);
|
m_toolWidget->addWidget(toggleSync);
|
||||||
|
|
||||||
|
if (m_diffEditorController) {
|
||||||
|
connect(whitespaceButton, SIGNAL(clicked(bool)),
|
||||||
|
m_diffEditorController, SLOT(setIgnoreWhitespaces(bool)));
|
||||||
|
connect(contextSpinBox, SIGNAL(valueChanged(int)),
|
||||||
|
m_diffEditorController, SLOT(setContextLinesNumber(int)));
|
||||||
|
connect(toggleSync, SIGNAL(clicked(bool)),
|
||||||
|
m_diffEditorController, SLOT(setHorizontalScrollBarSynchronization(bool)));
|
||||||
|
// TODO: synchronize in opposite direction too
|
||||||
|
}
|
||||||
|
|
||||||
return m_toolWidget;
|
return m_toolWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::setDiff(const QList<DiffEditorWidget::DiffFilesContents> &diffFileList,
|
void DiffEditor::setDiff(const QList<DiffEditorController::DiffFilesContents> &diffFileList,
|
||||||
const QString &workingDirectory)
|
const QString &workingDirectory)
|
||||||
{
|
{
|
||||||
m_entriesComboBox->clear();
|
m_entriesComboBox->clear();
|
||||||
const int count = diffFileList.count();
|
const int count = diffFileList.count();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
const DiffEditorWidget::DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
|
const DiffEditorController::DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
|
||||||
const DiffEditorWidget::DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
|
const DiffEditorController::DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
|
||||||
const QString leftShortFileName = QFileInfo(leftEntry.fileName).fileName();
|
const QString leftShortFileName = QFileInfo(leftEntry.fileName).fileName();
|
||||||
const QString rightShortFileName = QFileInfo(rightEntry.fileName).fileName();
|
const QString rightShortFileName = QFileInfo(rightEntry.fileName).fileName();
|
||||||
QString itemText;
|
QString itemText;
|
||||||
@@ -194,14 +202,16 @@ void DiffEditor::setDiff(const QList<DiffEditorWidget::DiffFilesContents> &diffF
|
|||||||
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1, itemToolTip, Qt::ToolTipRole);
|
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1, itemToolTip, Qt::ToolTipRole);
|
||||||
}
|
}
|
||||||
updateEntryToolTip();
|
updateEntryToolTip();
|
||||||
m_editorWidget->setDiff(diffFileList, workingDirectory);
|
if (m_diffEditorController)
|
||||||
|
m_diffEditorController->setDiffContents(diffFileList, workingDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::clear(const QString &message)
|
void DiffEditor::clear(const QString &message)
|
||||||
{
|
{
|
||||||
m_entriesComboBox->clear();
|
m_entriesComboBox->clear();
|
||||||
updateEntryToolTip();
|
updateEntryToolTip();
|
||||||
m_editorWidget->clear(message);
|
if (m_diffEditorController)
|
||||||
|
m_diffEditorController->clear(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::updateEntryToolTip()
|
void DiffEditor::updateEntryToolTip()
|
||||||
@@ -214,7 +224,8 @@ void DiffEditor::updateEntryToolTip()
|
|||||||
void DiffEditor::entryActivated(int index)
|
void DiffEditor::entryActivated(int index)
|
||||||
{
|
{
|
||||||
updateEntryToolTip();
|
updateEntryToolTip();
|
||||||
m_editorWidget->navigateToDiffFile(index);
|
if (m_diffEditorController)
|
||||||
|
m_diffEditorController->setCurrentDiffFileIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::activateEntry(int index)
|
void DiffEditor::activateEntry(int index)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#define DIFFEDITOR_H
|
#define DIFFEDITOR_H
|
||||||
|
|
||||||
#include "diffeditor_global.h"
|
#include "diffeditor_global.h"
|
||||||
#include "diffeditorwidget.h"
|
#include "diffeditorcontroller.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/idocument.h>
|
#include <coreplugin/idocument.h>
|
||||||
@@ -42,6 +42,7 @@ class QComboBox;
|
|||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
class DiffEditorWidget;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
class DiffEditorFile;
|
class DiffEditorFile;
|
||||||
@@ -55,7 +56,7 @@ public:
|
|||||||
virtual ~DiffEditor();
|
virtual ~DiffEditor();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setDiff(const QList<DiffEditorWidget::DiffFilesContents> &diffFileList,
|
void setDiff(const QList<DiffEditorController::DiffFilesContents> &diffFileList,
|
||||||
const QString &workingDirectory = QString());
|
const QString &workingDirectory = QString());
|
||||||
void clear(const QString &message);
|
void clear(const QString &message);
|
||||||
|
|
||||||
@@ -81,6 +82,7 @@ private:
|
|||||||
|
|
||||||
Internal::DiffEditorFile *m_file;
|
Internal::DiffEditorFile *m_file;
|
||||||
DiffEditorWidget *m_editorWidget;
|
DiffEditorWidget *m_editorWidget;
|
||||||
|
DiffEditorController *m_diffEditorController;
|
||||||
QComboBox *m_entriesComboBox;
|
QComboBox *m_entriesComboBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ DEFINES += DIFFEDITOR_LIBRARY
|
|||||||
include(../../qtcreatorplugin.pri)
|
include(../../qtcreatorplugin.pri)
|
||||||
|
|
||||||
HEADERS += diffeditor_global.h \
|
HEADERS += diffeditor_global.h \
|
||||||
diffeditorconstants.h \
|
|
||||||
diffeditor.h \
|
diffeditor.h \
|
||||||
|
diffeditorconstants.h \
|
||||||
|
diffeditorcontroller.h \
|
||||||
diffeditorfactory.h \
|
diffeditorfactory.h \
|
||||||
diffeditorfile.h \
|
diffeditorfile.h \
|
||||||
diffeditorplugin.h \
|
diffeditorplugin.h \
|
||||||
@@ -13,6 +14,7 @@ HEADERS += diffeditor_global.h \
|
|||||||
diffshoweditorfactory.h
|
diffshoweditorfactory.h
|
||||||
|
|
||||||
SOURCES += diffeditor.cpp \
|
SOURCES += diffeditor.cpp \
|
||||||
|
diffeditorcontroller.cpp \
|
||||||
diffeditorfactory.cpp \
|
diffeditorfactory.cpp \
|
||||||
diffeditorfile.cpp \
|
diffeditorfile.cpp \
|
||||||
diffeditorplugin.cpp \
|
diffeditorplugin.cpp \
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ QtcPlugin {
|
|||||||
"diffeditor.h",
|
"diffeditor.h",
|
||||||
"diffeditor_global.h",
|
"diffeditor_global.h",
|
||||||
"diffeditorconstants.h",
|
"diffeditorconstants.h",
|
||||||
|
"diffeditorcontroller.cpp",
|
||||||
|
"diffeditorcontroller.h",
|
||||||
"diffeditorfactory.cpp",
|
"diffeditorfactory.cpp",
|
||||||
"diffeditorfactory.h",
|
"diffeditorfactory.h",
|
||||||
"diffeditorfile.cpp",
|
"diffeditorfile.cpp",
|
||||||
|
|||||||
160
src/plugins/diffeditor/diffeditorcontroller.cpp
Normal file
160
src/plugins/diffeditor/diffeditorcontroller.cpp
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** 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 Digia. For licensing terms and
|
||||||
|
** conditions see http://qt.digia.com/licensing. For further information
|
||||||
|
** use the contact form at http://qt.digia.com/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "diffeditorcontroller.h"
|
||||||
|
|
||||||
|
namespace DiffEditor {
|
||||||
|
|
||||||
|
DiffEditorController::DiffEditorController(QObject *parent)
|
||||||
|
: QObject(parent),
|
||||||
|
m_contextLinesNumber(3),
|
||||||
|
m_ignoreWhitespaces(true),
|
||||||
|
m_syncScrollBars(true)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
DiffEditorController::~DiffEditorController()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DiffEditorController::clearMessage() const
|
||||||
|
{
|
||||||
|
return m_clearMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<DiffEditorController::DiffFilesContents> DiffEditorController::diffContents() const
|
||||||
|
{
|
||||||
|
return m_diffFileList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DiffEditorController::workingDirectory() const
|
||||||
|
{
|
||||||
|
return m_workingDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DiffEditorController::contextLinesNumber() const
|
||||||
|
{
|
||||||
|
return m_contextLinesNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DiffEditorController::isIgnoreWhitespaces() const
|
||||||
|
{
|
||||||
|
return m_ignoreWhitespaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DiffEditorController::horizontalScrollBarSynchronization() const
|
||||||
|
{
|
||||||
|
return m_syncScrollBars;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DiffEditorController::currentDiffFileIndex() const
|
||||||
|
{
|
||||||
|
return m_currentDiffFileIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorController::clear()
|
||||||
|
{
|
||||||
|
clear(tr("No difference"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorController::clear(const QString &message)
|
||||||
|
{
|
||||||
|
m_clearMessage = message;
|
||||||
|
m_currentDiffFileIndex = -1;
|
||||||
|
emit cleared(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorController::setDiffContents(const QList<DiffFilesContents> &diffFileList, const QString &workingDirectory)
|
||||||
|
{
|
||||||
|
m_diffFileList = diffFileList;
|
||||||
|
m_workingDirectory = workingDirectory;
|
||||||
|
m_currentDiffFileIndex = (diffFileList.isEmpty() ? -1 : 0);
|
||||||
|
emit diffContentsChanged(diffFileList, workingDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorController::setContextLinesNumber(int lines)
|
||||||
|
{
|
||||||
|
const int l = qMax(lines, -1);
|
||||||
|
if (m_contextLinesNumber == l)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_contextLinesNumber = l;
|
||||||
|
emit contextLinesNumberChanged(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorController::setIgnoreWhitespaces(bool ignore)
|
||||||
|
{
|
||||||
|
if (m_ignoreWhitespaces == ignore)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_ignoreWhitespaces = ignore;
|
||||||
|
emit ignoreWhitespacesChanged(ignore);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorController::setHorizontalScrollBarSynchronization(bool on)
|
||||||
|
{
|
||||||
|
if (m_syncScrollBars == on)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_syncScrollBars = on;
|
||||||
|
emit horizontalScrollBarSynchronizationChanged(on);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorController::setCurrentDiffFileIndex(int diffFileIndex)
|
||||||
|
{
|
||||||
|
if (!m_diffFileList.count())
|
||||||
|
return; // -1 is the only valid value in this case
|
||||||
|
|
||||||
|
const int newIndex = qBound(0, diffFileIndex, m_diffFileList.count() - 1);
|
||||||
|
|
||||||
|
if (m_currentDiffFileIndex == newIndex)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_currentDiffFileIndex = newIndex;
|
||||||
|
emit currentDiffFileIndexChanged(newIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace DiffEditor
|
||||||
|
|
||||||
|
//QTextCodec *DiffEditorWidget::codec() const
|
||||||
|
//{
|
||||||
|
//}
|
||||||
|
|
||||||
|
//QString DiffEditorWidget::source() const
|
||||||
|
//{
|
||||||
|
// return m_source;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void DiffEditorWidget::setSource(const QString &source)
|
||||||
|
//{
|
||||||
|
// m_source = source;
|
||||||
|
//}
|
||||||
|
|
||||||
114
src/plugins/diffeditor/diffeditorcontroller.h
Normal file
114
src/plugins/diffeditor/diffeditorcontroller.h
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** 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 Digia. For licensing terms and
|
||||||
|
** conditions see http://qt.digia.com/licensing. For further information
|
||||||
|
** use the contact form at http://qt.digia.com/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DIFFEDITORCONTROLLER_H
|
||||||
|
#define DIFFEDITORCONTROLLER_H
|
||||||
|
|
||||||
|
#include "diffeditor_global.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace DiffEditor {
|
||||||
|
|
||||||
|
class DIFFEDITOR_EXPORT DiffEditorController : public QObject
|
||||||
|
{
|
||||||
|
// Q_PROPERTY(QString source READ source WRITE setSource)
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
class DiffFileInfo {
|
||||||
|
public:
|
||||||
|
DiffFileInfo() {}
|
||||||
|
DiffFileInfo(const QString &file) : fileName(file) {}
|
||||||
|
DiffFileInfo(const QString &file, const QString &type) : fileName(file), typeInfo(type) {}
|
||||||
|
QString fileName;
|
||||||
|
QString typeInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DiffFilesContents {
|
||||||
|
public:
|
||||||
|
DiffFileInfo leftFileInfo;
|
||||||
|
QString leftText;
|
||||||
|
DiffFileInfo rightFileInfo;
|
||||||
|
QString rightText;
|
||||||
|
};
|
||||||
|
|
||||||
|
DiffEditorController(QObject *parent = 0);
|
||||||
|
~DiffEditorController();
|
||||||
|
|
||||||
|
// QTextCodec *codec() const;
|
||||||
|
|
||||||
|
// QString source() const;
|
||||||
|
// void setSource(const QString &source);
|
||||||
|
|
||||||
|
QString clearMessage() const;
|
||||||
|
|
||||||
|
QList<DiffFilesContents> diffContents() const;
|
||||||
|
QString workingDirectory() const;
|
||||||
|
|
||||||
|
int contextLinesNumber() const;
|
||||||
|
bool isIgnoreWhitespaces() const;
|
||||||
|
bool horizontalScrollBarSynchronization() const;
|
||||||
|
int currentDiffFileIndex() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void clear();
|
||||||
|
void clear(const QString &message);
|
||||||
|
void setDiffContents(const QList<DiffEditorController::DiffFilesContents> &diffFileList, const QString &workingDirectory = QString());
|
||||||
|
|
||||||
|
void setContextLinesNumber(int lines);
|
||||||
|
void setIgnoreWhitespaces(bool ignore);
|
||||||
|
void setHorizontalScrollBarSynchronization(bool on);
|
||||||
|
void setCurrentDiffFileIndex(int diffFileIndex);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
// This sets the current diff file index to -1
|
||||||
|
void cleared(const QString message);
|
||||||
|
// This sets the current diff file index to 0 (unless diffFileList is empty)
|
||||||
|
void diffContentsChanged(const QList<DiffEditorController::DiffFilesContents> &diffFileList, const QString &workingDirectory);
|
||||||
|
|
||||||
|
void contextLinesNumberChanged(int lines);
|
||||||
|
void ignoreWhitespacesChanged(bool ignore);
|
||||||
|
void horizontalScrollBarSynchronizationChanged(bool on);
|
||||||
|
void currentDiffFileIndexChanged(int diffFileIndex);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_clearMessage;
|
||||||
|
|
||||||
|
QList<DiffFilesContents> m_diffFileList;
|
||||||
|
QString m_workingDirectory;
|
||||||
|
|
||||||
|
int m_contextLinesNumber;
|
||||||
|
bool m_ignoreWhitespaces;
|
||||||
|
bool m_syncScrollBars;
|
||||||
|
int m_currentDiffFileIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace DiffEditor
|
||||||
|
|
||||||
|
#endif // DIFFEDITORCONTROLLER_H
|
||||||
@@ -49,6 +49,8 @@ DiffEditorFactory::DiffEditorFactory(QObject *parent)
|
|||||||
Core::IEditor *DiffEditorFactory::createEditor()
|
Core::IEditor *DiffEditorFactory::createEditor()
|
||||||
{
|
{
|
||||||
DiffEditorWidget *editorWidget = new DiffEditorWidget();
|
DiffEditorWidget *editorWidget = new DiffEditorWidget();
|
||||||
|
DiffEditorController *editorController = new DiffEditorController(editorWidget);
|
||||||
|
editorWidget->setDiffEditorController(editorController);
|
||||||
DiffEditor *editor = new DiffEditor(editorWidget);
|
DiffEditor *editor = new DiffEditor(editorWidget);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,12 +114,12 @@ void DiffEditorPlugin::diff()
|
|||||||
const QString text1 = getFileContents(fileName1, codec);
|
const QString text1 = getFileContents(fileName1, codec);
|
||||||
const QString text2 = getFileContents(fileName2, codec);
|
const QString text2 = getFileContents(fileName2, codec);
|
||||||
|
|
||||||
DiffEditorWidget::DiffFilesContents dfc;
|
DiffEditorController::DiffFilesContents dfc;
|
||||||
dfc.leftFileInfo = fileName1;
|
dfc.leftFileInfo = fileName1;
|
||||||
dfc.leftText = text1;
|
dfc.leftText = text1;
|
||||||
dfc.rightFileInfo = fileName2;
|
dfc.rightFileInfo = fileName2;
|
||||||
dfc.rightText = text2;
|
dfc.rightText = text2;
|
||||||
QList<DiffEditorWidget::DiffFilesContents> list;
|
QList<DiffEditorController::DiffFilesContents> list;
|
||||||
list.append(dfc);
|
list.append(dfc);
|
||||||
|
|
||||||
editor->setDiff(list);
|
editor->setDiff(list);
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ using namespace TextEditor;
|
|||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
struct TextLineData {
|
class TextLineData {
|
||||||
|
public:
|
||||||
enum TextLineType {
|
enum TextLineType {
|
||||||
TextLine,
|
TextLine,
|
||||||
Separator,
|
Separator,
|
||||||
@@ -77,7 +78,8 @@ struct TextLineData {
|
|||||||
QString text;
|
QString text;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RowData {
|
class RowData {
|
||||||
|
public:
|
||||||
RowData() : equal(true) {}
|
RowData() : equal(true) {}
|
||||||
RowData(const TextLineData &l)
|
RowData(const TextLineData &l)
|
||||||
: leftLine(l), rightLine(l), equal(true) {}
|
: leftLine(l), rightLine(l), equal(true) {}
|
||||||
@@ -88,7 +90,8 @@ struct RowData {
|
|||||||
bool equal; // true if left and right lines are equal, taking whitespaces into account (or both invalid)
|
bool equal; // true if left and right lines are equal, taking whitespaces into account (or both invalid)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ChunkData {
|
class ChunkData {
|
||||||
|
public:
|
||||||
ChunkData() : contextChunk(false) {}
|
ChunkData() : contextChunk(false) {}
|
||||||
QList<RowData> rows;
|
QList<RowData> rows;
|
||||||
bool contextChunk;
|
bool contextChunk;
|
||||||
@@ -96,12 +99,13 @@ struct ChunkData {
|
|||||||
QMap<int, int> changedRightPositions; // counting from the beginning of the chunk
|
QMap<int, int> changedRightPositions; // counting from the beginning of the chunk
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FileData {
|
class FileData {
|
||||||
|
public:
|
||||||
FileData() {}
|
FileData() {}
|
||||||
FileData(const ChunkData &chunkData) { chunks.append(chunkData); }
|
FileData(const ChunkData &chunkData) { chunks.append(chunkData); }
|
||||||
QList<ChunkData> chunks;
|
QList<ChunkData> chunks;
|
||||||
DiffEditorWidget::DiffFileInfo leftFileInfo;
|
DiffEditorController::DiffFileInfo leftFileInfo;
|
||||||
DiffEditorWidget::DiffFileInfo rightFileInfo;
|
DiffEditorController::DiffFileInfo rightFileInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
@@ -132,7 +136,7 @@ public:
|
|||||||
~MultiHighlighter();
|
~MultiHighlighter();
|
||||||
|
|
||||||
virtual void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
virtual void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
||||||
void setDocuments(const QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > &documents);
|
void setDocuments(const QList<QPair<DiffEditorController::DiffFileInfo, QString> > &documents);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void highlightBlock(const QString &text);
|
virtual void highlightBlock(const QString &text);
|
||||||
@@ -150,9 +154,9 @@ class DiffViewEditorWidget : public BaseTextEditorWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
struct ExtendedFileInfo
|
class ExtendedFileInfo {
|
||||||
{
|
public:
|
||||||
DiffEditorWidget::DiffFileInfo fileInfo;
|
DiffEditorController::DiffFileInfo fileInfo;
|
||||||
TextEditor::SyntaxHighlighter *highlighter;
|
TextEditor::SyntaxHighlighter *highlighter;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -164,21 +168,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// block number, file info
|
// block number, file info
|
||||||
QMap<int, DiffEditorWidget::DiffFileInfo> fileInfo() const { return m_fileInfo; }
|
QMap<int, DiffEditorController::DiffFileInfo> fileInfo() const { return m_fileInfo; }
|
||||||
|
|
||||||
void setLineNumber(int blockNumber, int lineNumber);
|
void setLineNumber(int blockNumber, int lineNumber);
|
||||||
void setFileInfo(int blockNumber, const DiffEditorWidget::DiffFileInfo &fileInfo);
|
void setFileInfo(int blockNumber, const DiffEditorController::DiffFileInfo &fileInfo);
|
||||||
void setSkippedLines(int blockNumber, int skippedLines) { m_skippedLines[blockNumber] = skippedLines; setSeparator(blockNumber, true); }
|
void setSkippedLines(int blockNumber, int skippedLines) { m_skippedLines[blockNumber] = skippedLines; setSeparator(blockNumber, true); }
|
||||||
void setSeparator(int blockNumber, bool separator) { m_separators[blockNumber] = separator; }
|
void setSeparator(int blockNumber, bool separator) { m_separators[blockNumber] = separator; }
|
||||||
bool isFileLine(int blockNumber) const { return m_fileInfo.contains(blockNumber); }
|
bool isFileLine(int blockNumber) const { return m_fileInfo.contains(blockNumber); }
|
||||||
int blockNumberForFileIndex(int fileIndex) const;
|
int blockNumberForFileIndex(int fileIndex) const;
|
||||||
int fileIndexForBlockNumber(int blockNumber) const;
|
int fileIndexForBlockNumber(int blockNumber) const;
|
||||||
bool isChunkLine(int blockNumber) const { return m_skippedLines.contains(blockNumber); }
|
bool isChunkLine(int blockNumber) const { return m_skippedLines.contains(blockNumber); }
|
||||||
void clearAll();
|
|
||||||
void clearAll(const QString &message);
|
void clearAll(const QString &message);
|
||||||
void clearAllData();
|
void clearAllData();
|
||||||
QTextBlock firstVisibleBlock() const { return BaseTextEditorWidget::firstVisibleBlock(); }
|
QTextBlock firstVisibleBlock() const { return BaseTextEditorWidget::firstVisibleBlock(); }
|
||||||
void setDocuments(const QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > &documents);
|
void setDocuments(const QList<QPair<DiffEditorController::DiffFileInfo, QString> > &documents);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setDisplaySettings(const DisplaySettings &ds);
|
void setDisplaySettings(const DisplaySettings &ds);
|
||||||
@@ -216,7 +219,7 @@ private:
|
|||||||
QMap<int, int> m_lineNumbers;
|
QMap<int, int> m_lineNumbers;
|
||||||
int m_lineNumberDigits;
|
int m_lineNumberDigits;
|
||||||
// block number, fileInfo. Set for file lines only.
|
// block number, fileInfo. Set for file lines only.
|
||||||
QMap<int, DiffEditorWidget::DiffFileInfo> m_fileInfo;
|
QMap<int, DiffEditorController::DiffFileInfo> m_fileInfo;
|
||||||
// block number, skipped lines. Set for chunk lines only.
|
// block number, skipped lines. Set for chunk lines only.
|
||||||
QMap<int, int> m_skippedLines;
|
QMap<int, int> m_skippedLines;
|
||||||
// block number, separator. Set for file, chunk or span line.
|
// block number, separator. Set for file, chunk or span line.
|
||||||
@@ -243,7 +246,7 @@ MultiHighlighter::MultiHighlighter(DiffViewEditorWidget *editor, QTextDocument *
|
|||||||
|
|
||||||
MultiHighlighter::~MultiHighlighter()
|
MultiHighlighter::~MultiHighlighter()
|
||||||
{
|
{
|
||||||
setDocuments(QList<QPair<DiffEditorWidget::DiffFileInfo, QString> >());
|
setDocuments(QList<QPair<DiffEditorController::DiffFileInfo, QString> >());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiHighlighter::setFontSettings(const TextEditor::FontSettings &fontSettings)
|
void MultiHighlighter::setFontSettings(const TextEditor::FontSettings &fontSettings)
|
||||||
@@ -256,7 +259,7 @@ void MultiHighlighter::setFontSettings(const TextEditor::FontSettings &fontSetti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiHighlighter::setDocuments(const QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > &documents)
|
void MultiHighlighter::setDocuments(const QList<QPair<DiffEditorController::DiffFileInfo, QString> > &documents)
|
||||||
{
|
{
|
||||||
// clear old documents
|
// clear old documents
|
||||||
qDeleteAll(m_documents);
|
qDeleteAll(m_documents);
|
||||||
@@ -266,7 +269,7 @@ void MultiHighlighter::setDocuments(const QList<QPair<DiffEditorWidget::DiffFile
|
|||||||
|
|
||||||
// create new documents
|
// create new documents
|
||||||
for (int i = 0; i < documents.count(); i++) {
|
for (int i = 0; i < documents.count(); i++) {
|
||||||
DiffEditorWidget::DiffFileInfo fileInfo = documents.at(i).first;
|
DiffEditorController::DiffFileInfo fileInfo = documents.at(i).first;
|
||||||
const QString contents = documents.at(i).second;
|
const QString contents = documents.at(i).second;
|
||||||
QTextDocument *document = new QTextDocument(contents);
|
QTextDocument *document = new QTextDocument(contents);
|
||||||
const MimeType mimeType = MimeDatabase::findByFile(QFileInfo(fileInfo.fileName));
|
const MimeType mimeType = MimeDatabase::findByFile(QFileInfo(fileInfo.fileName));
|
||||||
@@ -316,8 +319,8 @@ void DiffViewEditorEditable::slotTooltipRequested(TextEditor::ITextEditor *edito
|
|||||||
if (!ew)
|
if (!ew)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QMap<int, DiffEditorWidget::DiffFileInfo> fi = ew->fileInfo();
|
QMap<int, DiffEditorController::DiffFileInfo> fi = ew->fileInfo();
|
||||||
QMap<int, DiffEditorWidget::DiffFileInfo>::const_iterator it
|
QMap<int, DiffEditorController::DiffFileInfo>::const_iterator it
|
||||||
= fi.constFind(ew->document()->findBlock(position).blockNumber());
|
= fi.constFind(ew->document()->findBlock(position).blockNumber());
|
||||||
if (it != fi.constEnd()) {
|
if (it != fi.constEnd()) {
|
||||||
Utils::ToolTip::show(globalPoint, Utils::TextContent(it.value().fileName),
|
Utils::ToolTip::show(globalPoint, Utils::TextContent(it.value().fileName),
|
||||||
@@ -433,7 +436,7 @@ void DiffViewEditorWidget::setLineNumber(int blockNumber, int lineNumber)
|
|||||||
m_lineNumberDigits = qMax(m_lineNumberDigits, lineNumberString.count());
|
m_lineNumberDigits = qMax(m_lineNumberDigits, lineNumberString.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffViewEditorWidget::setFileInfo(int blockNumber, const DiffEditorWidget::DiffFileInfo &fileInfo)
|
void DiffViewEditorWidget::setFileInfo(int blockNumber, const DiffEditorController::DiffFileInfo &fileInfo)
|
||||||
{
|
{
|
||||||
m_fileInfo[blockNumber] = fileInfo;
|
m_fileInfo[blockNumber] = fileInfo;
|
||||||
setSeparator(blockNumber, true);
|
setSeparator(blockNumber, true);
|
||||||
@@ -444,7 +447,7 @@ int DiffViewEditorWidget::blockNumberForFileIndex(int fileIndex) const
|
|||||||
if (fileIndex < 0 || fileIndex >= m_fileInfo.count())
|
if (fileIndex < 0 || fileIndex >= m_fileInfo.count())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
QMap<int, DiffEditorWidget::DiffFileInfo>::const_iterator it
|
QMap<int, DiffEditorController::DiffFileInfo>::const_iterator it
|
||||||
= m_fileInfo.constBegin();
|
= m_fileInfo.constBegin();
|
||||||
for (int i = 0; i < fileIndex; i++)
|
for (int i = 0; i < fileIndex; i++)
|
||||||
++it;
|
++it;
|
||||||
@@ -454,9 +457,9 @@ int DiffViewEditorWidget::blockNumberForFileIndex(int fileIndex) const
|
|||||||
|
|
||||||
int DiffViewEditorWidget::fileIndexForBlockNumber(int blockNumber) const
|
int DiffViewEditorWidget::fileIndexForBlockNumber(int blockNumber) const
|
||||||
{
|
{
|
||||||
QMap<int, DiffEditorWidget::DiffFileInfo>::const_iterator it
|
QMap<int, DiffEditorController::DiffFileInfo>::const_iterator it
|
||||||
= m_fileInfo.constBegin();
|
= m_fileInfo.constBegin();
|
||||||
QMap<int, DiffEditorWidget::DiffFileInfo>::const_iterator itEnd
|
QMap<int, DiffEditorController::DiffFileInfo>::const_iterator itEnd
|
||||||
= m_fileInfo.constEnd();
|
= m_fileInfo.constEnd();
|
||||||
|
|
||||||
int i = -1;
|
int i = -1;
|
||||||
@@ -469,18 +472,13 @@ int DiffViewEditorWidget::fileIndexForBlockNumber(int blockNumber) const
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffViewEditorWidget::clearAll()
|
|
||||||
{
|
|
||||||
clearAll(tr("No difference"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiffViewEditorWidget::clearAll(const QString &message)
|
void DiffViewEditorWidget::clearAll(const QString &message)
|
||||||
{
|
{
|
||||||
setBlockSelection(false);
|
setBlockSelection(false);
|
||||||
clear();
|
clear();
|
||||||
clearAllData();
|
clearAllData();
|
||||||
setPlainText(message);
|
setPlainText(message);
|
||||||
m_highlighter->setDocuments(QList<QPair<DiffEditorWidget::DiffFileInfo, QString> >());
|
m_highlighter->setDocuments(QList<QPair<DiffEditorController::DiffFileInfo, QString> >());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffViewEditorWidget::clearAllData()
|
void DiffViewEditorWidget::clearAllData()
|
||||||
@@ -492,7 +490,7 @@ void DiffViewEditorWidget::clearAllData()
|
|||||||
m_separators.clear();
|
m_separators.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffViewEditorWidget::setDocuments(const QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > &documents)
|
void DiffViewEditorWidget::setDocuments(const QList<QPair<DiffEditorController::DiffFileInfo, QString> > &documents)
|
||||||
{
|
{
|
||||||
m_highlighter->setDocuments(documents);
|
m_highlighter->setDocuments(documents);
|
||||||
}
|
}
|
||||||
@@ -597,7 +595,7 @@ void DiffViewEditorWidget::paintEvent(QPaintEvent *e)
|
|||||||
skippedRowsText, currentBlock, top);
|
skippedRowsText, currentBlock, top);
|
||||||
}
|
}
|
||||||
|
|
||||||
const DiffEditorWidget::DiffFileInfo fileInfo = m_fileInfo.value(blockNumber);
|
const DiffEditorController::DiffFileInfo fileInfo = m_fileInfo.value(blockNumber);
|
||||||
if (!fileInfo.fileName.isEmpty()) {
|
if (!fileInfo.fileName.isEmpty()) {
|
||||||
const QString fileNameText = fileInfo.typeInfo.isEmpty()
|
const QString fileNameText = fileInfo.typeInfo.isEmpty()
|
||||||
? fileInfo.fileName
|
? fileInfo.fileName
|
||||||
@@ -716,11 +714,9 @@ void DiffViewEditorWidget::drawCollapsedBlockPopup(QPainter &painter,
|
|||||||
//////////////////
|
//////////////////
|
||||||
|
|
||||||
DiffEditorWidget::DiffEditorWidget(QWidget *parent)
|
DiffEditorWidget::DiffEditorWidget(QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent)
|
||||||
m_contextLinesNumber(3),
|
, m_controller(0)
|
||||||
m_ignoreWhitespaces(true),
|
, m_foldingBlocker(false)
|
||||||
m_syncScrollBars(true),
|
|
||||||
m_foldingBlocker(false)
|
|
||||||
{
|
{
|
||||||
m_leftEditor = new DiffViewEditorWidget(this);
|
m_leftEditor = new DiffViewEditorWidget(this);
|
||||||
m_leftEditor->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_leftEditor->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
@@ -785,7 +781,7 @@ DiffEditorWidget::DiffEditorWidget(QWidget *parent)
|
|||||||
l->setMargin(0);
|
l->setMargin(0);
|
||||||
l->addWidget(m_splitter);
|
l->addWidget(m_splitter);
|
||||||
|
|
||||||
clear();
|
clear(tr("No controller"));
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditorWidget::~DiffEditorWidget()
|
DiffEditorWidget::~DiffEditorWidget()
|
||||||
@@ -793,10 +789,40 @@ DiffEditorWidget::~DiffEditorWidget()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidget::clear()
|
void DiffEditorWidget::setDiffEditorController(DiffEditorController *controller)
|
||||||
{
|
{
|
||||||
m_leftEditor->clearAll();
|
if (m_controller) {
|
||||||
m_rightEditor->clearAll();
|
disconnect(m_controller, SIGNAL(cleared(QString)), this, SLOT(clear(QString)));
|
||||||
|
disconnect(m_controller, SIGNAL(diffContentsChanged(QList<DiffEditorController::DiffFilesContents>,QString)),
|
||||||
|
this, SLOT(setDiff(QList<DiffEditorController::DiffFilesContents>,QString)));
|
||||||
|
disconnect(m_controller, SIGNAL(contextLinesNumberChanged(int)),
|
||||||
|
this, SLOT(setContextLinesNumber(int)));
|
||||||
|
disconnect(m_controller, SIGNAL(ignoreWhitespacesChanged(bool)),
|
||||||
|
this, SLOT(setIgnoreWhitespaces(bool)));
|
||||||
|
disconnect(m_controller, SIGNAL(currentDiffFileIndexChanged(int)),
|
||||||
|
this, SLOT(setCurrentDiffFileIndex(int)));
|
||||||
|
|
||||||
|
clear(tr("No controller"));
|
||||||
|
}
|
||||||
|
m_controller = controller;
|
||||||
|
if (m_controller) {
|
||||||
|
connect(m_controller, SIGNAL(cleared(QString)), this, SLOT(clear(QString)));
|
||||||
|
connect(m_controller, SIGNAL(diffContentsChanged(QList<DiffEditorController::DiffFilesContents>,QString)),
|
||||||
|
this, SLOT(setDiff(QList<DiffEditorController::DiffFilesContents>,QString)));
|
||||||
|
connect(m_controller, SIGNAL(contextLinesNumberChanged(int)),
|
||||||
|
this, SLOT(setContextLinesNumber(int)));
|
||||||
|
connect(m_controller, SIGNAL(ignoreWhitespacesChanged(bool)),
|
||||||
|
this, SLOT(setIgnoreWhitespaces(bool)));
|
||||||
|
connect(m_controller, SIGNAL(currentDiffFileIndexChanged(int)),
|
||||||
|
this, SLOT(setCurrentDiffFileIndex(int)));
|
||||||
|
|
||||||
|
setDiff(m_controller->diffContents(), m_controller->workingDirectory());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DiffEditorController *DiffEditorWidget::diffEditorController() const
|
||||||
|
{
|
||||||
|
return m_controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidget::clear(const QString &message)
|
void DiffEditorWidget::clear(const QString &message)
|
||||||
@@ -805,13 +831,14 @@ void DiffEditorWidget::clear(const QString &message)
|
|||||||
m_rightEditor->clearAll(message);
|
m_rightEditor->clearAll(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidget::setDiff(const QList<DiffFilesContents> &diffFileList, const QString &workingDirectory)
|
void DiffEditorWidget::setDiff(const QList<DiffEditorController::DiffFilesContents> &diffFileList, const QString &workingDirectory)
|
||||||
{
|
{
|
||||||
m_workingDirectory = workingDirectory;
|
Q_UNUSED(workingDirectory)
|
||||||
|
|
||||||
Differ differ;
|
Differ differ;
|
||||||
QList<DiffList> diffList;
|
QList<DiffList> diffList;
|
||||||
for (int i = 0; i < diffFileList.count(); i++) {
|
for (int i = 0; i < diffFileList.count(); i++) {
|
||||||
DiffFilesContents dfc = diffFileList.at(i);
|
DiffEditorController::DiffFilesContents dfc = diffFileList.at(i);
|
||||||
DiffList dl;
|
DiffList dl;
|
||||||
dl.leftFileInfo = dfc.leftFileInfo;
|
dl.leftFileInfo = dfc.leftFileInfo;
|
||||||
dl.rightFileInfo = dfc.rightFileInfo;
|
dl.rightFileInfo = dfc.rightFileInfo;
|
||||||
@@ -841,10 +868,8 @@ void DiffEditorWidget::setDiff(const QList<DiffList> &diffList)
|
|||||||
|
|
||||||
void DiffEditorWidget::setContextLinesNumber(int lines)
|
void DiffEditorWidget::setContextLinesNumber(int lines)
|
||||||
{
|
{
|
||||||
if (m_contextLinesNumber == lines)
|
Q_UNUSED(lines)
|
||||||
return;
|
|
||||||
|
|
||||||
m_contextLinesNumber = lines;
|
|
||||||
for (int i = 0; i < m_diffList.count(); i++) {
|
for (int i = 0; i < m_diffList.count(); i++) {
|
||||||
const FileData oldFileData = m_contextFileData.at(i);
|
const FileData oldFileData = m_contextFileData.at(i);
|
||||||
FileData newFileData = calculateContextData(m_originalChunkData.at(i));
|
FileData newFileData = calculateContextData(m_originalChunkData.at(i));
|
||||||
@@ -858,14 +883,12 @@ void DiffEditorWidget::setContextLinesNumber(int lines)
|
|||||||
|
|
||||||
void DiffEditorWidget::setIgnoreWhitespaces(bool ignore)
|
void DiffEditorWidget::setIgnoreWhitespaces(bool ignore)
|
||||||
{
|
{
|
||||||
if (m_ignoreWhitespaces == ignore)
|
Q_UNUSED(ignore)
|
||||||
return;
|
|
||||||
|
|
||||||
m_ignoreWhitespaces = ignore;
|
|
||||||
setDiff(m_diffList);
|
setDiff(m_diffList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidget::navigateToDiffFile(int diffFileIndex)
|
void DiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex)
|
||||||
{
|
{
|
||||||
const int blockNumber = m_leftEditor->blockNumberForFileIndex(diffFileIndex);
|
const int blockNumber = m_leftEditor->blockNumberForFileIndex(diffFileIndex);
|
||||||
|
|
||||||
@@ -888,16 +911,6 @@ QTextCodec *DiffEditorWidget::codec() const
|
|||||||
return const_cast<QTextCodec *>(m_leftEditor->codec());
|
return const_cast<QTextCodec *>(m_leftEditor->codec());
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTextEditorWidget *DiffEditorWidget::leftEditor() const
|
|
||||||
{
|
|
||||||
return m_leftEditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseTextEditorWidget *DiffEditorWidget::rightEditor() const
|
|
||||||
{
|
|
||||||
return m_rightEditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DiffEditorWidget::isWhitespace(const QChar &c) const
|
bool DiffEditorWidget::isWhitespace(const QChar &c) const
|
||||||
{
|
{
|
||||||
if (c == QLatin1Char(' ') || c == QLatin1Char('\t'))
|
if (c == QLatin1Char(' ') || c == QLatin1Char('\t'))
|
||||||
@@ -926,7 +939,7 @@ bool DiffEditorWidget::isEqual(const QList<Diff> &diffList, int diffNumber) cons
|
|||||||
if (diff.text.count() == 0)
|
if (diff.text.count() == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!m_ignoreWhitespaces)
|
if (m_controller && !m_controller->isIgnoreWhitespaces())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isWhitespace(diff) == false)
|
if (isWhitespace(diff) == false)
|
||||||
@@ -1177,7 +1190,8 @@ ChunkData DiffEditorWidget::calculateOriginalData(const QList<Diff> &diffList) c
|
|||||||
|
|
||||||
FileData DiffEditorWidget::calculateContextData(const ChunkData &originalData) const
|
FileData DiffEditorWidget::calculateContextData(const ChunkData &originalData) const
|
||||||
{
|
{
|
||||||
if (m_contextLinesNumber < 0)
|
const int contextLinesNumber = m_controller ? m_controller->contextLinesNumber() : 3;
|
||||||
|
if (contextLinesNumber < 0)
|
||||||
return FileData(originalData);
|
return FileData(originalData);
|
||||||
|
|
||||||
const int joinChunkThreshold = 1;
|
const int joinChunkThreshold = 1;
|
||||||
@@ -1199,8 +1213,8 @@ FileData DiffEditorWidget::calculateContextData(const ChunkData &originalData) c
|
|||||||
const bool first = equalRowStart == 0; // includes first line?
|
const bool first = equalRowStart == 0; // includes first line?
|
||||||
const bool last = i == originalData.rows.count(); // includes last line?
|
const bool last = i == originalData.rows.count(); // includes last line?
|
||||||
|
|
||||||
const int firstLine = first ? 0 : equalRowStart + m_contextLinesNumber;
|
const int firstLine = first ? 0 : equalRowStart + contextLinesNumber;
|
||||||
const int lastLine = last ? originalData.rows.count() : i - m_contextLinesNumber;
|
const int lastLine = last ? originalData.rows.count() : i - contextLinesNumber;
|
||||||
|
|
||||||
if (firstLine < lastLine - joinChunkThreshold) {
|
if (firstLine < lastLine - joinChunkThreshold) {
|
||||||
for (int j = firstLine; j < lastLine; j++) {
|
for (int j = firstLine; j < lastLine; j++) {
|
||||||
@@ -1280,9 +1294,9 @@ void DiffEditorWidget::showDiff()
|
|||||||
const int leftHorizontalValue = m_leftEditor->horizontalScrollBar()->value();
|
const int leftHorizontalValue = m_leftEditor->horizontalScrollBar()->value();
|
||||||
const int rightHorizontalValue = m_rightEditor->horizontalScrollBar()->value();
|
const int rightHorizontalValue = m_rightEditor->horizontalScrollBar()->value();
|
||||||
|
|
||||||
clear();
|
clear(tr("No difference"));
|
||||||
|
|
||||||
QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > leftDocs, rightDocs;
|
QList<QPair<DiffEditorController::DiffFileInfo, QString> > leftDocs, rightDocs;
|
||||||
QString leftTexts, rightTexts;
|
QString leftTexts, rightTexts;
|
||||||
int blockNumber = 0;
|
int blockNumber = 0;
|
||||||
QChar separator = QLatin1Char('\n');
|
QChar separator = QLatin1Char('\n');
|
||||||
@@ -1629,7 +1643,10 @@ void DiffEditorWidget::slotRightJumpToOriginalFileRequested(int diffFileIndex,
|
|||||||
void DiffEditorWidget::jumpToOriginalFile(const QString &fileName,
|
void DiffEditorWidget::jumpToOriginalFile(const QString &fileName,
|
||||||
int lineNumber, int columnNumber)
|
int lineNumber, int columnNumber)
|
||||||
{
|
{
|
||||||
const QDir dir(m_workingDirectory);
|
if (!m_controller)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const QDir dir(m_controller->workingDirectory());
|
||||||
const QString absoluteFileName = dir.absoluteFilePath(fileName);
|
const QString absoluteFileName = dir.absoluteFilePath(fileName);
|
||||||
Core::EditorManager::openEditorAt(absoluteFileName, lineNumber, columnNumber);
|
Core::EditorManager::openEditorAt(absoluteFileName, lineNumber, columnNumber);
|
||||||
}
|
}
|
||||||
@@ -1646,13 +1663,13 @@ void DiffEditorWidget::rightVSliderChanged()
|
|||||||
|
|
||||||
void DiffEditorWidget::leftHSliderChanged()
|
void DiffEditorWidget::leftHSliderChanged()
|
||||||
{
|
{
|
||||||
if (m_syncScrollBars)
|
if (!m_controller || m_controller->horizontalScrollBarSynchronization())
|
||||||
m_rightEditor->horizontalScrollBar()->setValue(m_leftEditor->horizontalScrollBar()->value());
|
m_rightEditor->horizontalScrollBar()->setValue(m_leftEditor->horizontalScrollBar()->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidget::rightHSliderChanged()
|
void DiffEditorWidget::rightHSliderChanged()
|
||||||
{
|
{
|
||||||
if (m_syncScrollBars)
|
if (!m_controller || m_controller->horizontalScrollBarSynchronization())
|
||||||
m_leftEditor->horizontalScrollBar()->setValue(m_rightEditor->horizontalScrollBar()->value());
|
m_leftEditor->horizontalScrollBar()->setValue(m_rightEditor->horizontalScrollBar()->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1660,14 +1677,22 @@ void DiffEditorWidget::leftCursorPositionChanged()
|
|||||||
{
|
{
|
||||||
leftVSliderChanged();
|
leftVSliderChanged();
|
||||||
leftHSliderChanged();
|
leftHSliderChanged();
|
||||||
emit navigatedToDiffFile(m_leftEditor->fileIndexForBlockNumber(m_leftEditor->textCursor().blockNumber()));
|
|
||||||
|
if (!m_controller)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_controller->setCurrentDiffFileIndex(m_leftEditor->fileIndexForBlockNumber(m_leftEditor->textCursor().blockNumber()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidget::rightCursorPositionChanged()
|
void DiffEditorWidget::rightCursorPositionChanged()
|
||||||
{
|
{
|
||||||
rightVSliderChanged();
|
rightVSliderChanged();
|
||||||
rightHSliderChanged();
|
rightHSliderChanged();
|
||||||
emit navigatedToDiffFile(m_rightEditor->fileIndexForBlockNumber(m_rightEditor->textCursor().blockNumber()));
|
|
||||||
|
if (!m_controller)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_controller->setCurrentDiffFileIndex(m_rightEditor->fileIndexForBlockNumber(m_rightEditor->textCursor().blockNumber()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidget::leftDocumentSizeChanged()
|
void DiffEditorWidget::leftDocumentSizeChanged()
|
||||||
@@ -1680,11 +1705,6 @@ void DiffEditorWidget::rightDocumentSizeChanged()
|
|||||||
synchronizeFoldings(m_rightEditor, m_leftEditor);
|
synchronizeFoldings(m_rightEditor, m_leftEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidget::setHorizontalScrollBarSynchronization(bool on)
|
|
||||||
{
|
|
||||||
m_syncScrollBars = on;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Special version of that method (original: TextEditor::BaseTextDocumentLayout::doFoldOrUnfold())
|
/* Special version of that method (original: TextEditor::BaseTextDocumentLayout::doFoldOrUnfold())
|
||||||
The hack lies in fact, that when unfolding all direct sub-blocks are made visible,
|
The hack lies in fact, that when unfolding all direct sub-blocks are made visible,
|
||||||
while some of them need to stay invisible (i.e. unfolded chunk lines)
|
while some of them need to stay invisible (i.e. unfolded chunk lines)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "diffeditor_global.h"
|
#include "diffeditor_global.h"
|
||||||
#include "differ.h"
|
#include "differ.h"
|
||||||
|
#include "diffeditorcontroller.h"
|
||||||
|
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
|
||||||
@@ -60,47 +61,26 @@ class DIFFEDITOR_EXPORT DiffEditorWidget : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
struct DiffFileInfo {
|
|
||||||
DiffFileInfo() {}
|
|
||||||
DiffFileInfo(const QString &file) : fileName(file) {}
|
|
||||||
DiffFileInfo(const QString &file, const QString &type) : fileName(file), typeInfo(type) {}
|
|
||||||
QString fileName;
|
|
||||||
QString typeInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DiffFilesContents {
|
|
||||||
DiffFileInfo leftFileInfo;
|
|
||||||
QString leftText;
|
|
||||||
DiffFileInfo rightFileInfo;
|
|
||||||
QString rightText;
|
|
||||||
};
|
|
||||||
|
|
||||||
DiffEditorWidget(QWidget *parent = 0);
|
DiffEditorWidget(QWidget *parent = 0);
|
||||||
~DiffEditorWidget();
|
~DiffEditorWidget();
|
||||||
|
|
||||||
void clear();
|
void setDiffEditorController(DiffEditorController *controller);
|
||||||
void clear(const QString &message);
|
DiffEditorController *diffEditorController() const;
|
||||||
void setDiff(const QList<DiffFilesContents> &diffFileList, const QString &workingDirectory = QString());
|
|
||||||
QTextCodec *codec() const;
|
QTextCodec *codec() const;
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
void testAssemblyRows();
|
void testAssemblyRows();
|
||||||
#endif // WITH_TESTS
|
#endif // WITH_TESTS
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
|
void clear(const QString &message = QString());
|
||||||
|
void setDiff(const QList<DiffEditorController::DiffFilesContents> &diffFileList, const QString &workingDirectory);
|
||||||
|
|
||||||
void setContextLinesNumber(int lines);
|
void setContextLinesNumber(int lines);
|
||||||
void setIgnoreWhitespaces(bool ignore);
|
void setIgnoreWhitespaces(bool ignore);
|
||||||
void setHorizontalScrollBarSynchronization(bool on);
|
void setCurrentDiffFileIndex(int diffFileIndex);
|
||||||
void navigateToDiffFile(int diffFileIndex);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void navigatedToDiffFile(int diffFileIndex);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
TextEditor::BaseTextEditorWidget *leftEditor() const;
|
|
||||||
TextEditor::BaseTextEditorWidget *rightEditor() const;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
||||||
void slotLeftJumpToOriginalFileRequested(int diffFileIndex, int lineNumber, int columnNumber);
|
void slotLeftJumpToOriginalFileRequested(int diffFileIndex, int lineNumber, int columnNumber);
|
||||||
void slotRightJumpToOriginalFileRequested(int diffFileIndex, int lineNumber, int columnNumber);
|
void slotRightJumpToOriginalFileRequested(int diffFileIndex, int lineNumber, int columnNumber);
|
||||||
@@ -114,9 +94,10 @@ private slots:
|
|||||||
void rightDocumentSizeChanged();
|
void rightDocumentSizeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct DiffList {
|
class DiffList {
|
||||||
DiffFileInfo leftFileInfo;
|
public:
|
||||||
DiffFileInfo rightFileInfo;
|
DiffEditorController::DiffFileInfo leftFileInfo;
|
||||||
|
DiffEditorController::DiffFileInfo rightFileInfo;
|
||||||
QList<Diff> diffList;
|
QList<Diff> diffList;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -138,6 +119,7 @@ private:
|
|||||||
void synchronizeFoldings(DiffViewEditorWidget *source, DiffViewEditorWidget *destination);
|
void synchronizeFoldings(DiffViewEditorWidget *source, DiffViewEditorWidget *destination);
|
||||||
void jumpToOriginalFile(const QString &fileName, int lineNumber, int columnNumber);
|
void jumpToOriginalFile(const QString &fileName, int lineNumber, int columnNumber);
|
||||||
|
|
||||||
|
DiffEditorController *m_controller;
|
||||||
DiffViewEditorWidget *m_leftEditor;
|
DiffViewEditorWidget *m_leftEditor;
|
||||||
DiffViewEditorWidget *m_rightEditor;
|
DiffViewEditorWidget *m_rightEditor;
|
||||||
QSplitter *m_splitter;
|
QSplitter *m_splitter;
|
||||||
@@ -145,10 +127,6 @@ private:
|
|||||||
QList<DiffList> m_diffList; // list of original outputs from differ
|
QList<DiffList> m_diffList; // list of original outputs from differ
|
||||||
QList<ChunkData> m_originalChunkData; // one big chunk for every file, ignoreWhitespaces taken into account
|
QList<ChunkData> m_originalChunkData; // one big chunk for every file, ignoreWhitespaces taken into account
|
||||||
QList<FileData> m_contextFileData; // ultimate data to be shown, contextLinesNumber taken into account
|
QList<FileData> m_contextFileData; // ultimate data to be shown, contextLinesNumber taken into account
|
||||||
QString m_workingDirectory;
|
|
||||||
int m_contextLinesNumber;
|
|
||||||
bool m_ignoreWhitespaces;
|
|
||||||
bool m_syncScrollBars;
|
|
||||||
|
|
||||||
bool m_foldingBlocker;
|
bool m_foldingBlocker;
|
||||||
QString m_source;
|
QString m_source;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "diffshoweditor.h"
|
#include "diffshoweditor.h"
|
||||||
#include "diffeditorconstants.h"
|
#include "diffeditorconstants.h"
|
||||||
|
#include "diffeditorwidget.h"
|
||||||
|
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QToolButton;
|
class QToolButton;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace TextEditor { class BaseTextEditorWidget; }
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
class DIFFEDITOR_EXPORT DiffShowEditor : public DiffEditor
|
class DIFFEDITOR_EXPORT DiffShowEditor : public DiffEditor
|
||||||
|
|||||||
@@ -60,6 +60,7 @@
|
|||||||
#include <vcsbase/vcsbaseplugin.h>
|
#include <vcsbase/vcsbaseplugin.h>
|
||||||
|
|
||||||
#include <diffeditor/diffeditor.h>
|
#include <diffeditor/diffeditor.h>
|
||||||
|
#include <diffeditor/diffeditorwidget.h>
|
||||||
#include <diffeditor/diffshoweditor.h>
|
#include <diffeditor/diffshoweditor.h>
|
||||||
#include <diffeditor/diffeditorconstants.h>
|
#include <diffeditor/diffeditorconstants.h>
|
||||||
|
|
||||||
@@ -512,7 +513,7 @@ void GitDiffHandler::slotFileContentsReceived(const QString &contents)
|
|||||||
|
|
||||||
void GitDiffHandler::feedEditor()
|
void GitDiffHandler::feedEditor()
|
||||||
{
|
{
|
||||||
QList<DiffEditor::DiffEditorWidget::DiffFilesContents> list;
|
QList<DiffEditor::DiffEditorController::DiffFilesContents> list;
|
||||||
|
|
||||||
QMap<QString, QList<RevisionRange> >::const_iterator itFile
|
QMap<QString, QList<RevisionRange> >::const_iterator itFile
|
||||||
= m_requestedRevisionRanges.constBegin();
|
= m_requestedRevisionRanges.constBegin();
|
||||||
@@ -525,10 +526,10 @@ void GitDiffHandler::feedEditor()
|
|||||||
const Revision leftRevision = ranges.at(i).begin;
|
const Revision leftRevision = ranges.at(i).begin;
|
||||||
const Revision rightRevision = ranges.at(i).end;
|
const Revision rightRevision = ranges.at(i).end;
|
||||||
|
|
||||||
DiffEditor::DiffEditorWidget::DiffFilesContents dfc;
|
DiffEditor::DiffEditorController::DiffFilesContents dfc;
|
||||||
dfc.leftFileInfo = DiffEditor::DiffEditorWidget::DiffFileInfo(fileName, leftRevision.infoText());
|
dfc.leftFileInfo = DiffEditor::DiffEditorController::DiffFileInfo(fileName, leftRevision.infoText());
|
||||||
dfc.leftText = m_collectedRevisions[fileName][leftRevision];
|
dfc.leftText = m_collectedRevisions[fileName][leftRevision];
|
||||||
dfc.rightFileInfo = DiffEditor::DiffEditorWidget::DiffFileInfo(fileName, rightRevision.infoText());
|
dfc.rightFileInfo = DiffEditor::DiffEditorController::DiffFileInfo(fileName, rightRevision.infoText());
|
||||||
dfc.rightText = m_collectedRevisions[fileName][rightRevision];
|
dfc.rightText = m_collectedRevisions[fileName][rightRevision];
|
||||||
list.append(dfc);
|
list.append(dfc);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user