forked from qt-creator/qt-creator
Add file list combobox to diff editor
Change-Id: I2a40207ed3c4a5c07ba544d681aed6649a0b1a11 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -39,6 +39,9 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QToolBar>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
@@ -48,9 +51,12 @@ DiffEditorEditable::DiffEditorEditable(DiffEditorWidget *editorWidget)
|
|||||||
: IEditor(0),
|
: IEditor(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_toolWidget(0)
|
m_toolWidget(0),
|
||||||
|
m_entriesComboBox(0)
|
||||||
{
|
{
|
||||||
setWidget(editorWidget);
|
setWidget(editorWidget);
|
||||||
|
connect(m_editorWidget, SIGNAL(navigatedToDiffFile(int)),
|
||||||
|
this, SLOT(activateEntry(int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditorEditable::~DiffEditorEditable()
|
DiffEditorEditable::~DiffEditorEditable()
|
||||||
@@ -115,7 +121,6 @@ static QToolBar *createToolBar(const QWidget *someWidget)
|
|||||||
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
const int size = someWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
const int size = someWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||||
toolBar->setIconSize(QSize(size, size));
|
toolBar->setIconSize(QSize(size, size));
|
||||||
toolBar->addSeparator();
|
|
||||||
|
|
||||||
return toolBar;
|
return toolBar;
|
||||||
}
|
}
|
||||||
@@ -128,12 +133,15 @@ QWidget *DiffEditorEditable::toolBar()
|
|||||||
// Create
|
// Create
|
||||||
m_toolWidget = createToolBar(m_editorWidget);
|
m_toolWidget = createToolBar(m_editorWidget);
|
||||||
|
|
||||||
QWidget *spacerWidget = new QWidget();
|
m_entriesComboBox = new QComboBox;
|
||||||
QLayout *spacerLayout = new QHBoxLayout();
|
m_entriesComboBox->setMinimumContentsLength(20);
|
||||||
spacerLayout->setMargin(0);
|
// Make the combo box prefer to expand
|
||||||
spacerLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
|
QSizePolicy policy = m_entriesComboBox->sizePolicy();
|
||||||
spacerWidget->setLayout(spacerLayout);
|
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||||
m_toolWidget->addWidget(spacerWidget);
|
m_entriesComboBox->setSizePolicy(policy);
|
||||||
|
connect(m_entriesComboBox, SIGNAL(activated(int)),
|
||||||
|
this, SLOT(entryActivated(int)));
|
||||||
|
m_toolWidget->addWidget(m_entriesComboBox);
|
||||||
|
|
||||||
QToolButton *whitespaceButton = new QToolButton(m_toolWidget);
|
QToolButton *whitespaceButton = new QToolButton(m_toolWidget);
|
||||||
whitespaceButton->setText(tr("Ignore Whitespace"));
|
whitespaceButton->setText(tr("Ignore Whitespace"));
|
||||||
@@ -156,6 +164,78 @@ QWidget *DiffEditorEditable::toolBar()
|
|||||||
return m_toolWidget;
|
return m_toolWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiffEditorEditable::setDiff(const QList<DiffEditorWidget::DiffFilesContents> &diffFileList,
|
||||||
|
const QString &workingDirectory)
|
||||||
|
{
|
||||||
|
m_entriesComboBox->clear();
|
||||||
|
const int count = diffFileList.count();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
const DiffEditorWidget::DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
|
||||||
|
const DiffEditorWidget::DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
|
||||||
|
const QString leftShortFileName = QFileInfo(leftEntry.fileName).fileName();
|
||||||
|
const QString rightShortFileName = QFileInfo(rightEntry.fileName).fileName();
|
||||||
|
QString itemText;
|
||||||
|
QString itemToolTip;
|
||||||
|
if (leftEntry.fileName == rightEntry.fileName) {
|
||||||
|
itemText = leftShortFileName;
|
||||||
|
|
||||||
|
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
|
||||||
|
itemToolTip = leftEntry.fileName;
|
||||||
|
} else {
|
||||||
|
itemToolTip = tr("[%1] vs. [%2] %3")
|
||||||
|
.arg(leftEntry.typeInfo, rightEntry.typeInfo, leftEntry.fileName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (leftShortFileName == rightShortFileName) {
|
||||||
|
itemText = leftShortFileName;
|
||||||
|
} else {
|
||||||
|
itemText = tr("%1 vs. %2")
|
||||||
|
.arg(leftShortFileName, rightShortFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
|
||||||
|
itemToolTip = tr("%1 vs. %2")
|
||||||
|
.arg(leftEntry.fileName, rightEntry.fileName);
|
||||||
|
} else {
|
||||||
|
itemToolTip = tr("[%1] %2 vs. [%3] %4")
|
||||||
|
.arg(leftEntry.typeInfo, leftEntry.fileName, rightEntry.typeInfo, rightEntry.fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_entriesComboBox->addItem(itemText);
|
||||||
|
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1, itemToolTip, Qt::ToolTipRole);
|
||||||
|
}
|
||||||
|
updateEntryToolTip();
|
||||||
|
m_editorWidget->setDiff(diffFileList, workingDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorEditable::clear(const QString &message)
|
||||||
|
{
|
||||||
|
m_entriesComboBox->clear();
|
||||||
|
updateEntryToolTip();
|
||||||
|
m_editorWidget->clear(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorEditable::updateEntryToolTip()
|
||||||
|
{
|
||||||
|
const QString &toolTip = m_entriesComboBox->itemData(
|
||||||
|
m_entriesComboBox->currentIndex(), Qt::ToolTipRole).toString();
|
||||||
|
m_entriesComboBox->setToolTip(toolTip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorEditable::entryActivated(int index)
|
||||||
|
{
|
||||||
|
updateEntryToolTip();
|
||||||
|
m_editorWidget->navigateToDiffFile(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorEditable::activateEntry(int index)
|
||||||
|
{
|
||||||
|
m_entriesComboBox->blockSignals(true);
|
||||||
|
m_entriesComboBox->setCurrentIndex(index);
|
||||||
|
m_entriesComboBox->blockSignals(false);
|
||||||
|
updateEntryToolTip();
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray DiffEditorEditable::saveState() const
|
QByteArray DiffEditorEditable::saveState() const
|
||||||
{
|
{
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
|
|||||||
@@ -31,16 +31,18 @@
|
|||||||
#define DIFFEDITOREDITABLE_H
|
#define DIFFEDITOREDITABLE_H
|
||||||
|
|
||||||
#include "diffeditor_global.h"
|
#include "diffeditor_global.h"
|
||||||
|
#include "diffeditorwidget.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/idocument.h>
|
#include <coreplugin/idocument.h>
|
||||||
|
|
||||||
#include <QToolBar>
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QToolBar;
|
||||||
|
class QComboBox;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
class DiffEditorWidget;
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
class DiffEditorFile;
|
class DiffEditorFile;
|
||||||
}
|
}
|
||||||
@@ -53,6 +55,10 @@ public:
|
|||||||
virtual ~DiffEditorEditable();
|
virtual ~DiffEditorEditable();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void setDiff(const QList<DiffEditorWidget::DiffFilesContents> &diffFileList,
|
||||||
|
const QString &workingDirectory = QString());
|
||||||
|
void clear(const QString &message);
|
||||||
|
|
||||||
// Core::IEditor
|
// Core::IEditor
|
||||||
bool createNew(const QString &contents);
|
bool createNew(const QString &contents);
|
||||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||||
@@ -69,11 +75,19 @@ public:
|
|||||||
|
|
||||||
QByteArray saveState() const;
|
QByteArray saveState() const;
|
||||||
bool restoreState(const QByteArray &state);
|
bool restoreState(const QByteArray &state);
|
||||||
|
public slots:
|
||||||
|
void activateEntry(int index);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void entryActivated(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateEntryToolTip();
|
||||||
|
|
||||||
Internal::DiffEditorFile *m_file;
|
Internal::DiffEditorFile *m_file;
|
||||||
DiffEditorWidget *m_editorWidget;
|
DiffEditorWidget *m_editorWidget;
|
||||||
QToolBar *m_toolWidget;
|
QToolBar *m_toolWidget;
|
||||||
|
QComboBox *m_entriesComboBox;
|
||||||
mutable QString m_displayName;
|
mutable QString m_displayName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -136,31 +136,28 @@ void DiffEditorPlugin::diff()
|
|||||||
const Core::Id editorId = Constants::DIFF_EDITOR_ID;
|
const Core::Id editorId = Constants::DIFF_EDITOR_ID;
|
||||||
//: Editor title
|
//: Editor title
|
||||||
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
||||||
Core::IEditor *outputEditor = Core::EditorManager::openEditorWithContents(editorId, &title, QString());
|
DiffEditorEditable *editorEditable = qobject_cast<DiffEditorEditable *>
|
||||||
Core::EditorManager::activateEditor(outputEditor, Core::EditorManager::ModeSwitch);
|
(Core::EditorManager::openEditorWithContents(editorId, &title, QString()));
|
||||||
|
|
||||||
DiffEditorWidget *editorWidget = getDiffEditorWidget(outputEditor);
|
if (!editorEditable)
|
||||||
if (editorWidget) {
|
return;
|
||||||
const QString text1 = getFileContents(fileName1, editorWidget->codec());
|
|
||||||
const QString text2 = getFileContents(fileName2, editorWidget->codec());
|
|
||||||
|
|
||||||
DiffEditorWidget::DiffFilesContents dfc;
|
Core::EditorManager::activateEditor(editorEditable, Core::EditorManager::ModeSwitch);
|
||||||
dfc.leftFileInfo = fileName1;
|
|
||||||
dfc.leftText = text1;
|
|
||||||
dfc.rightFileInfo = fileName2;
|
|
||||||
dfc.rightText = text2;
|
|
||||||
QList<DiffEditorWidget::DiffFilesContents> list;
|
|
||||||
list.append(dfc);
|
|
||||||
|
|
||||||
editorWidget->setDiff(list);
|
DiffEditorWidget *editorWidget = editorEditable->editorWidget();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DiffEditorWidget *DiffEditorPlugin::getDiffEditorWidget(const Core::IEditor *editor) const
|
const QString text1 = getFileContents(fileName1, editorWidget->codec());
|
||||||
{
|
const QString text2 = getFileContents(fileName2, editorWidget->codec());
|
||||||
if (const DiffEditorEditable *de = qobject_cast<const DiffEditorEditable *>(editor))
|
|
||||||
return de->editorWidget();
|
DiffEditorWidget::DiffFilesContents dfc;
|
||||||
return 0;
|
dfc.leftFileInfo = fileName1;
|
||||||
|
dfc.leftText = text1;
|
||||||
|
dfc.rightFileInfo = fileName2;
|
||||||
|
dfc.rightText = text2;
|
||||||
|
QList<DiffEditorWidget::DiffFilesContents> list;
|
||||||
|
list.append(dfc);
|
||||||
|
|
||||||
|
editorEditable->setDiff(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DiffEditorPlugin::getFileContents(const QString &fileName, QTextCodec *codec) const
|
QString DiffEditorPlugin::getFileContents(const QString &fileName, QTextCodec *codec) const
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ private slots:
|
|||||||
void diff();
|
void diff();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DiffEditorWidget *getDiffEditorWidget(const Core::IEditor *editor) const;
|
|
||||||
QString getFileContents(const QString &fileName, QTextCodec *codec) const;
|
QString getFileContents(const QString &fileName, QTextCodec *codec) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -131,6 +131,8 @@ public:
|
|||||||
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 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();
|
||||||
void clearAll(const QString &message);
|
void clearAll(const QString &message);
|
||||||
@@ -243,6 +245,36 @@ void DiffViewEditorWidget::setLineNumber(int blockNumber, int lineNumber)
|
|||||||
m_lineNumberDigits = qMax(m_lineNumberDigits, lineNumberString.count());
|
m_lineNumberDigits = qMax(m_lineNumberDigits, lineNumberString.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DiffViewEditorWidget::blockNumberForFileIndex(int fileIndex) const
|
||||||
|
{
|
||||||
|
if (fileIndex < 0 || fileIndex >= m_fileInfo.count())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
QMap<int, DiffEditorWidget::DiffFileInfo>::const_iterator it
|
||||||
|
= m_fileInfo.constBegin();
|
||||||
|
for (int i = 0; i < fileIndex; i++)
|
||||||
|
++it;
|
||||||
|
|
||||||
|
return it.key();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DiffViewEditorWidget::fileIndexForBlockNumber(int blockNumber) const
|
||||||
|
{
|
||||||
|
QMap<int, DiffEditorWidget::DiffFileInfo>::const_iterator it
|
||||||
|
= m_fileInfo.constBegin();
|
||||||
|
QMap<int, DiffEditorWidget::DiffFileInfo>::const_iterator itEnd
|
||||||
|
= m_fileInfo.constEnd();
|
||||||
|
|
||||||
|
int i = -1;
|
||||||
|
while (it != itEnd) {
|
||||||
|
if (it.key() > blockNumber)
|
||||||
|
break;
|
||||||
|
++it;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
void DiffViewEditorWidget::clearAll()
|
void DiffViewEditorWidget::clearAll()
|
||||||
{
|
{
|
||||||
clearAll(tr("No difference"));
|
clearAll(tr("No difference"));
|
||||||
@@ -512,16 +544,14 @@ DiffEditorWidget::DiffEditorWidget(QWidget *parent)
|
|||||||
this, SLOT(leftVSliderChanged()));
|
this, SLOT(leftVSliderChanged()));
|
||||||
connect(m_leftEditor->verticalScrollBar(), SIGNAL(actionTriggered(int)),
|
connect(m_leftEditor->verticalScrollBar(), SIGNAL(actionTriggered(int)),
|
||||||
this, SLOT(leftVSliderChanged()));
|
this, SLOT(leftVSliderChanged()));
|
||||||
connect(m_leftEditor, SIGNAL(cursorPositionChanged()),
|
|
||||||
this, SLOT(leftVSliderChanged()));
|
|
||||||
|
|
||||||
connect(m_leftEditor->horizontalScrollBar(), SIGNAL(valueChanged(int)),
|
connect(m_leftEditor->horizontalScrollBar(), SIGNAL(valueChanged(int)),
|
||||||
this, SLOT(leftHSliderChanged()));
|
this, SLOT(leftHSliderChanged()));
|
||||||
connect(m_leftEditor->horizontalScrollBar(), SIGNAL(actionTriggered(int)),
|
connect(m_leftEditor->horizontalScrollBar(), SIGNAL(actionTriggered(int)),
|
||||||
this, SLOT(leftHSliderChanged()));
|
this, SLOT(leftHSliderChanged()));
|
||||||
connect(m_leftEditor, SIGNAL(cursorPositionChanged()),
|
|
||||||
this, SLOT(leftHSliderChanged()));
|
|
||||||
|
|
||||||
|
connect(m_leftEditor, SIGNAL(cursorPositionChanged()),
|
||||||
|
this, SLOT(leftCursorPositionChanged()));
|
||||||
connect(m_leftEditor->document()->documentLayout(), SIGNAL(documentSizeChanged(QSizeF)),
|
connect(m_leftEditor->document()->documentLayout(), SIGNAL(documentSizeChanged(QSizeF)),
|
||||||
this, SLOT(leftDocumentSizeChanged()));
|
this, SLOT(leftDocumentSizeChanged()));
|
||||||
|
|
||||||
@@ -529,16 +559,14 @@ DiffEditorWidget::DiffEditorWidget(QWidget *parent)
|
|||||||
this, SLOT(rightVSliderChanged()));
|
this, SLOT(rightVSliderChanged()));
|
||||||
connect(m_rightEditor->verticalScrollBar(), SIGNAL(actionTriggered(int)),
|
connect(m_rightEditor->verticalScrollBar(), SIGNAL(actionTriggered(int)),
|
||||||
this, SLOT(rightVSliderChanged()));
|
this, SLOT(rightVSliderChanged()));
|
||||||
connect(m_rightEditor, SIGNAL(cursorPositionChanged()),
|
|
||||||
this, SLOT(rightVSliderChanged()));
|
|
||||||
|
|
||||||
connect(m_rightEditor->horizontalScrollBar(), SIGNAL(valueChanged(int)),
|
connect(m_rightEditor->horizontalScrollBar(), SIGNAL(valueChanged(int)),
|
||||||
this, SLOT(rightHSliderChanged()));
|
this, SLOT(rightHSliderChanged()));
|
||||||
connect(m_rightEditor->horizontalScrollBar(), SIGNAL(actionTriggered(int)),
|
connect(m_rightEditor->horizontalScrollBar(), SIGNAL(actionTriggered(int)),
|
||||||
this, SLOT(rightHSliderChanged()));
|
this, SLOT(rightHSliderChanged()));
|
||||||
connect(m_rightEditor, SIGNAL(cursorPositionChanged()),
|
|
||||||
this, SLOT(rightHSliderChanged()));
|
|
||||||
|
|
||||||
|
connect(m_rightEditor, SIGNAL(cursorPositionChanged()),
|
||||||
|
this, SLOT(rightCursorPositionChanged()));
|
||||||
connect(m_rightEditor->document()->documentLayout(), SIGNAL(documentSizeChanged(QSizeF)),
|
connect(m_rightEditor->document()->documentLayout(), SIGNAL(documentSizeChanged(QSizeF)),
|
||||||
this, SLOT(rightDocumentSizeChanged()));
|
this, SLOT(rightDocumentSizeChanged()));
|
||||||
|
|
||||||
@@ -630,6 +658,24 @@ void DiffEditorWidget::setIgnoreWhitespaces(bool ignore)
|
|||||||
setDiff(m_diffList);
|
setDiff(m_diffList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiffEditorWidget::navigateToDiffFile(int diffFileIndex)
|
||||||
|
{
|
||||||
|
const int blockNumber = m_leftEditor->blockNumberForFileIndex(diffFileIndex);
|
||||||
|
|
||||||
|
QTextBlock leftBlock = m_leftEditor->document()->findBlockByNumber(blockNumber);
|
||||||
|
QTextCursor leftCursor = m_leftEditor->textCursor();
|
||||||
|
leftCursor.setPosition(leftBlock.position());
|
||||||
|
m_leftEditor->setTextCursor(leftCursor);
|
||||||
|
|
||||||
|
QTextBlock rightBlock = m_rightEditor->document()->findBlockByNumber(blockNumber);
|
||||||
|
QTextCursor rightCursor = m_rightEditor->textCursor();
|
||||||
|
rightCursor.setPosition(rightBlock.position());
|
||||||
|
m_rightEditor->setTextCursor(rightCursor);
|
||||||
|
|
||||||
|
m_leftEditor->centerCursor();
|
||||||
|
m_rightEditor->centerCursor();
|
||||||
|
}
|
||||||
|
|
||||||
QTextCodec *DiffEditorWidget::codec() const
|
QTextCodec *DiffEditorWidget::codec() const
|
||||||
{
|
{
|
||||||
return const_cast<QTextCodec *>(m_leftEditor->codec());
|
return const_cast<QTextCodec *>(m_leftEditor->codec());
|
||||||
@@ -1329,6 +1375,20 @@ void DiffEditorWidget::rightHSliderChanged()
|
|||||||
m_leftEditor->horizontalScrollBar()->setValue(m_rightEditor->horizontalScrollBar()->value());
|
m_leftEditor->horizontalScrollBar()->setValue(m_rightEditor->horizontalScrollBar()->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiffEditorWidget::leftCursorPositionChanged()
|
||||||
|
{
|
||||||
|
leftVSliderChanged();
|
||||||
|
leftHSliderChanged();
|
||||||
|
emit navigatedToDiffFile(m_leftEditor->fileIndexForBlockNumber(m_leftEditor->textCursor().blockNumber()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorWidget::rightCursorPositionChanged()
|
||||||
|
{
|
||||||
|
rightVSliderChanged();
|
||||||
|
rightHSliderChanged();
|
||||||
|
emit navigatedToDiffFile(m_rightEditor->fileIndexForBlockNumber(m_rightEditor->textCursor().blockNumber()));
|
||||||
|
}
|
||||||
|
|
||||||
void DiffEditorWidget::leftDocumentSizeChanged()
|
void DiffEditorWidget::leftDocumentSizeChanged()
|
||||||
{
|
{
|
||||||
synchronizeFoldings(m_leftEditor, m_rightEditor);
|
synchronizeFoldings(m_leftEditor, m_rightEditor);
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void setContextLinesNumber(int lines);
|
void setContextLinesNumber(int lines);
|
||||||
void setIgnoreWhitespaces(bool ignore);
|
void setIgnoreWhitespaces(bool ignore);
|
||||||
|
void navigateToDiffFile(int diffFileIndex);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void navigatedToDiffFile(int diffFileIndex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TextEditor::SnippetEditorWidget *leftEditor() const;
|
TextEditor::SnippetEditorWidget *leftEditor() const;
|
||||||
@@ -96,6 +100,8 @@ private slots:
|
|||||||
void rightVSliderChanged();
|
void rightVSliderChanged();
|
||||||
void leftHSliderChanged();
|
void leftHSliderChanged();
|
||||||
void rightHSliderChanged();
|
void rightHSliderChanged();
|
||||||
|
void leftCursorPositionChanged();
|
||||||
|
void rightCursorPositionChanged();
|
||||||
void leftDocumentSizeChanged();
|
void leftDocumentSizeChanged();
|
||||||
void rightDocumentSizeChanged();
|
void rightDocumentSizeChanged();
|
||||||
void toggleScrollBarSynchronization(bool on);
|
void toggleScrollBarSynchronization(bool on);
|
||||||
|
|||||||
@@ -84,10 +84,10 @@ class GitDiffHandler : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GitDiffHandler(const QString &gitPath,
|
GitDiffHandler(DiffEditor::DiffEditorEditable *editor,
|
||||||
|
const QString &gitPath,
|
||||||
const QString &workingDirectory,
|
const QString &workingDirectory,
|
||||||
const QProcessEnvironment &environment,
|
const QProcessEnvironment &environment,
|
||||||
DiffEditor::DiffEditorWidget *editor,
|
|
||||||
int timeout);
|
int timeout);
|
||||||
|
|
||||||
// index -> working tree
|
// index -> working tree
|
||||||
@@ -110,10 +110,10 @@ private:
|
|||||||
void feedEditor();
|
void feedEditor();
|
||||||
QString workingTreeContents(const QString &fileName) const;
|
QString workingTreeContents(const QString &fileName) const;
|
||||||
|
|
||||||
|
QPointer<DiffEditor::DiffEditorEditable> m_editor;
|
||||||
const QString m_gitPath;
|
const QString m_gitPath;
|
||||||
const QString m_workingDirectory;
|
const QString m_workingDirectory;
|
||||||
const QProcessEnvironment m_processEnvironment;
|
const QProcessEnvironment m_processEnvironment;
|
||||||
QWeakPointer<DiffEditor::DiffEditorWidget> m_editor;
|
|
||||||
const int m_timeout;
|
const int m_timeout;
|
||||||
const QString m_waitMessage;
|
const QString m_waitMessage;
|
||||||
|
|
||||||
@@ -133,15 +133,15 @@ private:
|
|||||||
QStringList m_indexContents;
|
QStringList m_indexContents;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitDiffHandler::GitDiffHandler(const QString &gitPath,
|
GitDiffHandler::GitDiffHandler(DiffEditor::DiffEditorEditable *editor,
|
||||||
|
const QString &gitPath,
|
||||||
const QString &workingDirectory,
|
const QString &workingDirectory,
|
||||||
const QProcessEnvironment &environment,
|
const QProcessEnvironment &environment,
|
||||||
DiffEditor::DiffEditorWidget *editor,
|
|
||||||
int timeout)
|
int timeout)
|
||||||
: m_gitPath(gitPath),
|
: m_editor(editor),
|
||||||
|
m_gitPath(gitPath),
|
||||||
m_workingDirectory(workingDirectory),
|
m_workingDirectory(workingDirectory),
|
||||||
m_processEnvironment(environment),
|
m_processEnvironment(environment),
|
||||||
m_editor(editor),
|
|
||||||
m_timeout(timeout),
|
m_timeout(timeout),
|
||||||
m_waitMessage(tr("Waiting for data..."))
|
m_waitMessage(tr("Waiting for data..."))
|
||||||
{
|
{
|
||||||
@@ -182,7 +182,7 @@ void GitDiffHandler::diffRepository()
|
|||||||
|
|
||||||
void GitDiffHandler::collectFilesList(const QStringList &additionalArguments)
|
void GitDiffHandler::collectFilesList(const QStringList &additionalArguments)
|
||||||
{
|
{
|
||||||
m_editor.data()->clear(m_waitMessage);
|
m_editor->clear(m_waitMessage);
|
||||||
VcsBase::Command *command = new VcsBase::Command(m_gitPath, m_workingDirectory, m_processEnvironment);
|
VcsBase::Command *command = new VcsBase::Command(m_gitPath, m_workingDirectory, m_processEnvironment);
|
||||||
connect(command, SIGNAL(outputData(QByteArray)), this, SLOT(slotFileListReceived(QByteArray)));
|
connect(command, SIGNAL(outputData(QByteArray)), this, SLOT(slotFileListReceived(QByteArray)));
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
@@ -196,7 +196,7 @@ void GitDiffHandler::slotFileListReceived(const QByteArray &data)
|
|||||||
if (m_editor.isNull())
|
if (m_editor.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QString fileList = m_editor.data()->codec()->toUnicode(data);
|
const QString fileList = m_editor->editorWidget()->codec()->toUnicode(data);
|
||||||
m_requestedIndexFileNames = fileList.split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
m_requestedIndexFileNames = fileList.split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
||||||
m_requestedIndexFileNames.removeDuplicates();
|
m_requestedIndexFileNames.removeDuplicates();
|
||||||
m_indexFileNames = m_requestedIndexFileNames;
|
m_indexFileNames = m_requestedIndexFileNames;
|
||||||
@@ -237,7 +237,7 @@ void GitDiffHandler::slotFileContentsReceived(const QByteArray &data)
|
|||||||
|
|
||||||
const int headFilesReceived = m_headContents.count();
|
const int headFilesReceived = m_headContents.count();
|
||||||
const int indexFilesReceived = m_indexContents.count();
|
const int indexFilesReceived = m_indexContents.count();
|
||||||
const QString contents = m_editor.data()->codec()->toUnicode(data);
|
const QString contents = m_editor->editorWidget()->codec()->toUnicode(data);
|
||||||
if (headFilesReceived < m_headFileNames.count())
|
if (headFilesReceived < m_headFileNames.count())
|
||||||
m_headContents.append(contents);
|
m_headContents.append(contents);
|
||||||
else if (indexFilesReceived < m_indexFileNames.count())
|
else if (indexFilesReceived < m_indexFileNames.count())
|
||||||
@@ -279,7 +279,7 @@ void GitDiffHandler::feedEditor()
|
|||||||
list.append(dfc);
|
list.append(dfc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_editor.data()->setDiff(list, m_workingDirectory);
|
m_editor->setDiff(list, m_workingDirectory);
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ QString GitDiffHandler::workingTreeContents(const QString &fileName) const
|
|||||||
|
|
||||||
QFile file(absoluteFileName);
|
QFile file(absoluteFileName);
|
||||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
return m_editor.data()->codec()->toUnicode(file.readAll());
|
return m_editor->editorWidget()->codec()->toUnicode(file.readAll());
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@@ -728,10 +728,9 @@ VcsBase::VcsBaseEditorWidget *GitClient::findExistingVCSEditor(const char *regis
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditor::DiffEditorWidget *GitClient::findExistingDiffEditor(const char *registerDynamicProperty,
|
DiffEditor::DiffEditorEditable *GitClient::findExistingDiffEditor(const char *registerDynamicProperty,
|
||||||
const QString &dynamicPropertyValue) const
|
const QString &dynamicPropertyValue) const
|
||||||
{
|
{
|
||||||
DiffEditor::DiffEditorWidget *editorWidget = 0;
|
|
||||||
Core::IEditor *outputEditor = locateEditor(registerDynamicProperty, dynamicPropertyValue);
|
Core::IEditor *outputEditor = locateEditor(registerDynamicProperty, dynamicPropertyValue);
|
||||||
if (!outputEditor)
|
if (!outputEditor)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -739,9 +738,8 @@ DiffEditor::DiffEditorWidget *GitClient::findExistingDiffEditor(const char *regi
|
|||||||
// Exists already
|
// Exists already
|
||||||
Core::EditorManager::activateEditor(outputEditor, Core::EditorManager::ModeSwitch);
|
Core::EditorManager::activateEditor(outputEditor, Core::EditorManager::ModeSwitch);
|
||||||
outputEditor->createNew(m_msgWait);
|
outputEditor->createNew(m_msgWait);
|
||||||
editorWidget = diffEditorWidget(outputEditor);
|
|
||||||
|
|
||||||
return editorWidget;
|
return qobject_cast<DiffEditor::DiffEditorEditable *>(outputEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an editor associated to VCS output of a source file/directory
|
/* Create an editor associated to VCS output of a source file/directory
|
||||||
@@ -787,13 +785,6 @@ VcsBase::VcsBaseEditorWidget *GitClient::createVcsEditor(const Core::Id &id,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditor::DiffEditorWidget *GitClient::diffEditorWidget(const Core::IEditor *editor) const
|
|
||||||
{
|
|
||||||
if (const DiffEditor::DiffEditorEditable *de = qobject_cast<const DiffEditor::DiffEditorEditable *>(editor))
|
|
||||||
return de->editorWidget();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GitClient::diff(const QString &workingDirectory,
|
void GitClient::diff(const QString &workingDirectory,
|
||||||
const QStringList &diffArgs,
|
const QStringList &diffArgs,
|
||||||
const QStringList &unstagedFileNames,
|
const QStringList &unstagedFileNames,
|
||||||
@@ -803,18 +794,17 @@ void GitClient::diff(const QString &workingDirectory,
|
|||||||
const Core::Id editorId = DiffEditor::Constants::DIFF_EDITOR_ID;
|
const Core::Id editorId = DiffEditor::Constants::DIFF_EDITOR_ID;
|
||||||
QString title = tr("Git Diff");
|
QString title = tr("Git Diff");
|
||||||
|
|
||||||
DiffEditor::DiffEditorWidget *editorWidget = findExistingDiffEditor("originalFileName", workingDirectory);
|
DiffEditor::DiffEditorEditable *editorEditable = findExistingDiffEditor("originalFileName", workingDirectory);
|
||||||
|
|
||||||
if (!editorWidget) {
|
if (!editorEditable) {
|
||||||
Core::IEditor *outputEditor = Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait);
|
editorEditable = qobject_cast<DiffEditor::DiffEditorEditable *>(
|
||||||
outputEditor->document()->setProperty("originalFileName", workingDirectory);
|
Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait));
|
||||||
Core::EditorManager::activateEditor(outputEditor, Core::EditorManager::ModeSwitch); // should probably go outside this block
|
editorEditable->document()->setProperty("originalFileName", workingDirectory);
|
||||||
|
Core::EditorManager::activateEditor(editorEditable, Core::EditorManager::ModeSwitch); // should probably go outside this block
|
||||||
editorWidget = diffEditorWidget(outputEditor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int timeout = settings()->intValue(GitSettings::timeoutKey);
|
int timeout = settings()->intValue(GitSettings::timeoutKey);
|
||||||
GitDiffHandler *handler = new GitDiffHandler(gitBinaryPath(), workingDirectory, processEnvironment(), editorWidget, timeout);
|
GitDiffHandler *handler = new GitDiffHandler(editorEditable, gitBinaryPath(), workingDirectory, processEnvironment(), timeout);
|
||||||
|
|
||||||
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
||||||
// local repository diff
|
// local repository diff
|
||||||
@@ -892,18 +882,17 @@ void GitClient::diff(const QString &workingDirectory,
|
|||||||
QString title = tr("Git Diff \"%1\"").arg(fileName);
|
QString title = tr("Git Diff \"%1\"").arg(fileName);
|
||||||
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, fileName);
|
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, fileName);
|
||||||
|
|
||||||
DiffEditor::DiffEditorWidget *editorWidget = findExistingDiffEditor("originalFileName", sourceFile);
|
DiffEditor::DiffEditorEditable *editorEditable = findExistingDiffEditor("originalFileName", sourceFile);
|
||||||
if (!editorWidget) {
|
if (!editorEditable) {
|
||||||
Core::IEditor *outputEditor = Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait);
|
editorEditable = qobject_cast<DiffEditor::DiffEditorEditable *>(
|
||||||
outputEditor->document()->setProperty("originalFileName", sourceFile);
|
Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait));
|
||||||
Core::EditorManager::activateEditor(outputEditor, Core::EditorManager::ModeSwitch);
|
editorEditable->document()->setProperty("originalFileName", sourceFile);
|
||||||
|
Core::EditorManager::activateEditor(editorEditable, Core::EditorManager::ModeSwitch);
|
||||||
editorWidget = diffEditorWidget(outputEditor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
int timeout = settings()->intValue(GitSettings::timeoutKey);
|
int timeout = settings()->intValue(GitSettings::timeoutKey);
|
||||||
GitDiffHandler *handler = new GitDiffHandler(gitBinaryPath(), workingDirectory, processEnvironment(), editorWidget, timeout);
|
GitDiffHandler *handler = new GitDiffHandler(editorEditable, gitBinaryPath(), workingDirectory, processEnvironment(), timeout);
|
||||||
handler->diffFile(fileName);
|
handler->diffFile(fileName);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
class DiffEditorWidget;
|
class DiffEditorEditable;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
@@ -69,7 +69,6 @@ namespace Internal {
|
|||||||
|
|
||||||
class GitPlugin;
|
class GitPlugin;
|
||||||
class GitOutputWindow;
|
class GitOutputWindow;
|
||||||
class GitDiffEditorWidget;
|
|
||||||
class CommitData;
|
class CommitData;
|
||||||
struct GitSubmitEditorPanelData;
|
struct GitSubmitEditorPanelData;
|
||||||
class Stash;
|
class Stash;
|
||||||
@@ -133,8 +132,6 @@ public:
|
|||||||
QString findRepositoryForDirectory(const QString &dir);
|
QString findRepositoryForDirectory(const QString &dir);
|
||||||
QString findGitDirForRepository(const QString &repositoryDir) const;
|
QString findGitDirForRepository(const QString &repositoryDir) const;
|
||||||
|
|
||||||
DiffEditor::DiffEditorWidget *diffEditorWidget(const Core::IEditor *editor) const;
|
|
||||||
|
|
||||||
void diff(const QString &workingDirectory, const QStringList &diffArgs, const QString &fileName);
|
void diff(const QString &workingDirectory, const QStringList &diffArgs, const QString &fileName);
|
||||||
void diff(const QString &workingDirectory, const QStringList &diffArgs,
|
void diff(const QString &workingDirectory, const QStringList &diffArgs,
|
||||||
const QStringList &unstagedFileNames, const QStringList &stagedFileNames= QStringList());
|
const QStringList &unstagedFileNames, const QStringList &stagedFileNames= QStringList());
|
||||||
@@ -326,7 +323,7 @@ private:
|
|||||||
QTextCodec *getSourceCodec(const QString &file) const;
|
QTextCodec *getSourceCodec(const QString &file) const;
|
||||||
VcsBase::VcsBaseEditorWidget *findExistingVCSEditor(const char *registerDynamicProperty,
|
VcsBase::VcsBaseEditorWidget *findExistingVCSEditor(const char *registerDynamicProperty,
|
||||||
const QString &dynamicPropertyValue) const;
|
const QString &dynamicPropertyValue) const;
|
||||||
DiffEditor::DiffEditorWidget *findExistingDiffEditor(const char *registerDynamicProperty,
|
DiffEditor::DiffEditorEditable *findExistingDiffEditor(const char *registerDynamicProperty,
|
||||||
const QString &dynamicPropertyValue) const;
|
const QString &dynamicPropertyValue) const;
|
||||||
|
|
||||||
enum CodecType { CodecSource, CodecLogOutput, CodecNone };
|
enum CodecType { CodecSource, CodecLogOutput, CodecNone };
|
||||||
|
|||||||
Reference in New Issue
Block a user