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 <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QToolBar>
|
||||
#include <QComboBox>
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
@@ -48,9 +51,12 @@ DiffEditorEditable::DiffEditorEditable(DiffEditorWidget *editorWidget)
|
||||
: IEditor(0),
|
||||
m_file(new Internal::DiffEditorFile(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE), this)),
|
||||
m_editorWidget(editorWidget),
|
||||
m_toolWidget(0)
|
||||
m_toolWidget(0),
|
||||
m_entriesComboBox(0)
|
||||
{
|
||||
setWidget(editorWidget);
|
||||
connect(m_editorWidget, SIGNAL(navigatedToDiffFile(int)),
|
||||
this, SLOT(activateEntry(int)));
|
||||
}
|
||||
|
||||
DiffEditorEditable::~DiffEditorEditable()
|
||||
@@ -115,7 +121,6 @@ static QToolBar *createToolBar(const QWidget *someWidget)
|
||||
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
const int size = someWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||
toolBar->setIconSize(QSize(size, size));
|
||||
toolBar->addSeparator();
|
||||
|
||||
return toolBar;
|
||||
}
|
||||
@@ -128,12 +133,15 @@ QWidget *DiffEditorEditable::toolBar()
|
||||
// Create
|
||||
m_toolWidget = createToolBar(m_editorWidget);
|
||||
|
||||
QWidget *spacerWidget = new QWidget();
|
||||
QLayout *spacerLayout = new QHBoxLayout();
|
||||
spacerLayout->setMargin(0);
|
||||
spacerLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
|
||||
spacerWidget->setLayout(spacerLayout);
|
||||
m_toolWidget->addWidget(spacerWidget);
|
||||
m_entriesComboBox = new QComboBox;
|
||||
m_entriesComboBox->setMinimumContentsLength(20);
|
||||
// Make the combo box prefer to expand
|
||||
QSizePolicy policy = m_entriesComboBox->sizePolicy();
|
||||
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||
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);
|
||||
whitespaceButton->setText(tr("Ignore Whitespace"));
|
||||
@@ -156,6 +164,78 @@ QWidget *DiffEditorEditable::toolBar()
|
||||
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
|
||||
{
|
||||
return QByteArray();
|
||||
|
||||
@@ -31,16 +31,18 @@
|
||||
#define DIFFEDITOREDITABLE_H
|
||||
|
||||
#include "diffeditor_global.h"
|
||||
#include "diffeditorwidget.h"
|
||||
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <QToolBar>
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QToolBar;
|
||||
class QComboBox;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
class DiffEditorWidget;
|
||||
|
||||
namespace Internal {
|
||||
class DiffEditorFile;
|
||||
}
|
||||
@@ -53,6 +55,10 @@ public:
|
||||
virtual ~DiffEditorEditable();
|
||||
|
||||
public:
|
||||
void setDiff(const QList<DiffEditorWidget::DiffFilesContents> &diffFileList,
|
||||
const QString &workingDirectory = QString());
|
||||
void clear(const QString &message);
|
||||
|
||||
// Core::IEditor
|
||||
bool createNew(const QString &contents);
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
@@ -69,11 +75,19 @@ public:
|
||||
|
||||
QByteArray saveState() const;
|
||||
bool restoreState(const QByteArray &state);
|
||||
public slots:
|
||||
void activateEntry(int index);
|
||||
|
||||
private slots:
|
||||
void entryActivated(int index);
|
||||
|
||||
private:
|
||||
void updateEntryToolTip();
|
||||
|
||||
Internal::DiffEditorFile *m_file;
|
||||
DiffEditorWidget *m_editorWidget;
|
||||
QToolBar *m_toolWidget;
|
||||
QComboBox *m_entriesComboBox;
|
||||
mutable QString m_displayName;
|
||||
};
|
||||
|
||||
|
||||
@@ -136,31 +136,28 @@ void DiffEditorPlugin::diff()
|
||||
const Core::Id editorId = Constants::DIFF_EDITOR_ID;
|
||||
//: Editor title
|
||||
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
||||
Core::IEditor *outputEditor = Core::EditorManager::openEditorWithContents(editorId, &title, QString());
|
||||
Core::EditorManager::activateEditor(outputEditor, Core::EditorManager::ModeSwitch);
|
||||
DiffEditorEditable *editorEditable = qobject_cast<DiffEditorEditable *>
|
||||
(Core::EditorManager::openEditorWithContents(editorId, &title, QString()));
|
||||
|
||||
DiffEditorWidget *editorWidget = getDiffEditorWidget(outputEditor);
|
||||
if (editorWidget) {
|
||||
const QString text1 = getFileContents(fileName1, editorWidget->codec());
|
||||
const QString text2 = getFileContents(fileName2, editorWidget->codec());
|
||||
if (!editorEditable)
|
||||
return;
|
||||
|
||||
DiffEditorWidget::DiffFilesContents dfc;
|
||||
dfc.leftFileInfo = fileName1;
|
||||
dfc.leftText = text1;
|
||||
dfc.rightFileInfo = fileName2;
|
||||
dfc.rightText = text2;
|
||||
QList<DiffEditorWidget::DiffFilesContents> list;
|
||||
list.append(dfc);
|
||||
Core::EditorManager::activateEditor(editorEditable, Core::EditorManager::ModeSwitch);
|
||||
|
||||
editorWidget->setDiff(list);
|
||||
}
|
||||
}
|
||||
DiffEditorWidget *editorWidget = editorEditable->editorWidget();
|
||||
|
||||
DiffEditorWidget *DiffEditorPlugin::getDiffEditorWidget(const Core::IEditor *editor) const
|
||||
{
|
||||
if (const DiffEditorEditable *de = qobject_cast<const DiffEditorEditable *>(editor))
|
||||
return de->editorWidget();
|
||||
return 0;
|
||||
const QString text1 = getFileContents(fileName1, editorWidget->codec());
|
||||
const QString text2 = getFileContents(fileName2, editorWidget->codec());
|
||||
|
||||
DiffEditorWidget::DiffFilesContents dfc;
|
||||
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
|
||||
|
||||
@@ -66,7 +66,6 @@ private slots:
|
||||
void diff();
|
||||
|
||||
private:
|
||||
DiffEditorWidget *getDiffEditorWidget(const Core::IEditor *editor) 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 setSeparator(int blockNumber, bool separator) { m_separators[blockNumber] = separator; }
|
||||
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); }
|
||||
void clearAll();
|
||||
void clearAll(const QString &message);
|
||||
@@ -243,6 +245,36 @@ void DiffViewEditorWidget::setLineNumber(int blockNumber, int lineNumber)
|
||||
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()
|
||||
{
|
||||
clearAll(tr("No difference"));
|
||||
@@ -512,16 +544,14 @@ DiffEditorWidget::DiffEditorWidget(QWidget *parent)
|
||||
this, SLOT(leftVSliderChanged()));
|
||||
connect(m_leftEditor->verticalScrollBar(), SIGNAL(actionTriggered(int)),
|
||||
this, SLOT(leftVSliderChanged()));
|
||||
connect(m_leftEditor, SIGNAL(cursorPositionChanged()),
|
||||
this, SLOT(leftVSliderChanged()));
|
||||
|
||||
connect(m_leftEditor->horizontalScrollBar(), SIGNAL(valueChanged(int)),
|
||||
this, SLOT(leftHSliderChanged()));
|
||||
connect(m_leftEditor->horizontalScrollBar(), SIGNAL(actionTriggered(int)),
|
||||
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)),
|
||||
this, SLOT(leftDocumentSizeChanged()));
|
||||
|
||||
@@ -529,16 +559,14 @@ DiffEditorWidget::DiffEditorWidget(QWidget *parent)
|
||||
this, SLOT(rightVSliderChanged()));
|
||||
connect(m_rightEditor->verticalScrollBar(), SIGNAL(actionTriggered(int)),
|
||||
this, SLOT(rightVSliderChanged()));
|
||||
connect(m_rightEditor, SIGNAL(cursorPositionChanged()),
|
||||
this, SLOT(rightVSliderChanged()));
|
||||
|
||||
connect(m_rightEditor->horizontalScrollBar(), SIGNAL(valueChanged(int)),
|
||||
this, SLOT(rightHSliderChanged()));
|
||||
connect(m_rightEditor->horizontalScrollBar(), SIGNAL(actionTriggered(int)),
|
||||
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)),
|
||||
this, SLOT(rightDocumentSizeChanged()));
|
||||
|
||||
@@ -630,6 +658,24 @@ void DiffEditorWidget::setIgnoreWhitespaces(bool ignore)
|
||||
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
|
||||
{
|
||||
return const_cast<QTextCodec *>(m_leftEditor->codec());
|
||||
@@ -1329,6 +1375,20 @@ void DiffEditorWidget::rightHSliderChanged()
|
||||
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()
|
||||
{
|
||||
synchronizeFoldings(m_leftEditor, m_rightEditor);
|
||||
|
||||
@@ -86,6 +86,10 @@ public:
|
||||
public slots:
|
||||
void setContextLinesNumber(int lines);
|
||||
void setIgnoreWhitespaces(bool ignore);
|
||||
void navigateToDiffFile(int diffFileIndex);
|
||||
|
||||
signals:
|
||||
void navigatedToDiffFile(int diffFileIndex);
|
||||
|
||||
protected:
|
||||
TextEditor::SnippetEditorWidget *leftEditor() const;
|
||||
@@ -96,6 +100,8 @@ private slots:
|
||||
void rightVSliderChanged();
|
||||
void leftHSliderChanged();
|
||||
void rightHSliderChanged();
|
||||
void leftCursorPositionChanged();
|
||||
void rightCursorPositionChanged();
|
||||
void leftDocumentSizeChanged();
|
||||
void rightDocumentSizeChanged();
|
||||
void toggleScrollBarSynchronization(bool on);
|
||||
|
||||
@@ -84,10 +84,10 @@ class GitDiffHandler : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GitDiffHandler(const QString &gitPath,
|
||||
GitDiffHandler(DiffEditor::DiffEditorEditable *editor,
|
||||
const QString &gitPath,
|
||||
const QString &workingDirectory,
|
||||
const QProcessEnvironment &environment,
|
||||
DiffEditor::DiffEditorWidget *editor,
|
||||
int timeout);
|
||||
|
||||
// index -> working tree
|
||||
@@ -110,10 +110,10 @@ private:
|
||||
void feedEditor();
|
||||
QString workingTreeContents(const QString &fileName) const;
|
||||
|
||||
QPointer<DiffEditor::DiffEditorEditable> m_editor;
|
||||
const QString m_gitPath;
|
||||
const QString m_workingDirectory;
|
||||
const QProcessEnvironment m_processEnvironment;
|
||||
QWeakPointer<DiffEditor::DiffEditorWidget> m_editor;
|
||||
const int m_timeout;
|
||||
const QString m_waitMessage;
|
||||
|
||||
@@ -133,15 +133,15 @@ private:
|
||||
QStringList m_indexContents;
|
||||
};
|
||||
|
||||
GitDiffHandler::GitDiffHandler(const QString &gitPath,
|
||||
GitDiffHandler::GitDiffHandler(DiffEditor::DiffEditorEditable *editor,
|
||||
const QString &gitPath,
|
||||
const QString &workingDirectory,
|
||||
const QProcessEnvironment &environment,
|
||||
DiffEditor::DiffEditorWidget *editor,
|
||||
int timeout)
|
||||
: m_gitPath(gitPath),
|
||||
: m_editor(editor),
|
||||
m_gitPath(gitPath),
|
||||
m_workingDirectory(workingDirectory),
|
||||
m_processEnvironment(environment),
|
||||
m_editor(editor),
|
||||
m_timeout(timeout),
|
||||
m_waitMessage(tr("Waiting for data..."))
|
||||
{
|
||||
@@ -182,7 +182,7 @@ void GitDiffHandler::diffRepository()
|
||||
|
||||
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);
|
||||
connect(command, SIGNAL(outputData(QByteArray)), this, SLOT(slotFileListReceived(QByteArray)));
|
||||
QStringList arguments;
|
||||
@@ -196,7 +196,7 @@ void GitDiffHandler::slotFileListReceived(const QByteArray &data)
|
||||
if (m_editor.isNull())
|
||||
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.removeDuplicates();
|
||||
m_indexFileNames = m_requestedIndexFileNames;
|
||||
@@ -237,7 +237,7 @@ void GitDiffHandler::slotFileContentsReceived(const QByteArray &data)
|
||||
|
||||
const int headFilesReceived = m_headContents.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())
|
||||
m_headContents.append(contents);
|
||||
else if (indexFilesReceived < m_indexFileNames.count())
|
||||
@@ -279,7 +279,7 @@ void GitDiffHandler::feedEditor()
|
||||
list.append(dfc);
|
||||
}
|
||||
}
|
||||
m_editor.data()->setDiff(list, m_workingDirectory);
|
||||
m_editor->setDiff(list, m_workingDirectory);
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ QString GitDiffHandler::workingTreeContents(const QString &fileName) const
|
||||
|
||||
QFile file(absoluteFileName);
|
||||
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();
|
||||
}
|
||||
@@ -728,10 +728,9 @@ VcsBase::VcsBaseEditorWidget *GitClient::findExistingVCSEditor(const char *regis
|
||||
return rc;
|
||||
}
|
||||
|
||||
DiffEditor::DiffEditorWidget *GitClient::findExistingDiffEditor(const char *registerDynamicProperty,
|
||||
DiffEditor::DiffEditorEditable *GitClient::findExistingDiffEditor(const char *registerDynamicProperty,
|
||||
const QString &dynamicPropertyValue) const
|
||||
{
|
||||
DiffEditor::DiffEditorWidget *editorWidget = 0;
|
||||
Core::IEditor *outputEditor = locateEditor(registerDynamicProperty, dynamicPropertyValue);
|
||||
if (!outputEditor)
|
||||
return 0;
|
||||
@@ -739,9 +738,8 @@ DiffEditor::DiffEditorWidget *GitClient::findExistingDiffEditor(const char *regi
|
||||
// Exists already
|
||||
Core::EditorManager::activateEditor(outputEditor, Core::EditorManager::ModeSwitch);
|
||||
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
|
||||
@@ -787,13 +785,6 @@ VcsBase::VcsBaseEditorWidget *GitClient::createVcsEditor(const Core::Id &id,
|
||||
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,
|
||||
const QStringList &diffArgs,
|
||||
const QStringList &unstagedFileNames,
|
||||
@@ -803,18 +794,17 @@ void GitClient::diff(const QString &workingDirectory,
|
||||
const Core::Id editorId = DiffEditor::Constants::DIFF_EDITOR_ID;
|
||||
QString title = tr("Git Diff");
|
||||
|
||||
DiffEditor::DiffEditorWidget *editorWidget = findExistingDiffEditor("originalFileName", workingDirectory);
|
||||
DiffEditor::DiffEditorEditable *editorEditable = findExistingDiffEditor("originalFileName", workingDirectory);
|
||||
|
||||
if (!editorWidget) {
|
||||
Core::IEditor *outputEditor = Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait);
|
||||
outputEditor->document()->setProperty("originalFileName", workingDirectory);
|
||||
Core::EditorManager::activateEditor(outputEditor, Core::EditorManager::ModeSwitch); // should probably go outside this block
|
||||
|
||||
editorWidget = diffEditorWidget(outputEditor);
|
||||
if (!editorEditable) {
|
||||
editorEditable = qobject_cast<DiffEditor::DiffEditorEditable *>(
|
||||
Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait));
|
||||
editorEditable->document()->setProperty("originalFileName", workingDirectory);
|
||||
Core::EditorManager::activateEditor(editorEditable, Core::EditorManager::ModeSwitch); // should probably go outside this block
|
||||
}
|
||||
|
||||
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()) {
|
||||
// local repository diff
|
||||
@@ -892,18 +882,17 @@ void GitClient::diff(const QString &workingDirectory,
|
||||
QString title = tr("Git Diff \"%1\"").arg(fileName);
|
||||
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, fileName);
|
||||
|
||||
DiffEditor::DiffEditorWidget *editorWidget = findExistingDiffEditor("originalFileName", sourceFile);
|
||||
if (!editorWidget) {
|
||||
Core::IEditor *outputEditor = Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait);
|
||||
outputEditor->document()->setProperty("originalFileName", sourceFile);
|
||||
Core::EditorManager::activateEditor(outputEditor, Core::EditorManager::ModeSwitch);
|
||||
|
||||
editorWidget = diffEditorWidget(outputEditor);
|
||||
DiffEditor::DiffEditorEditable *editorEditable = findExistingDiffEditor("originalFileName", sourceFile);
|
||||
if (!editorEditable) {
|
||||
editorEditable = qobject_cast<DiffEditor::DiffEditorEditable *>(
|
||||
Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait));
|
||||
editorEditable->document()->setProperty("originalFileName", sourceFile);
|
||||
Core::EditorManager::activateEditor(editorEditable, Core::EditorManager::ModeSwitch);
|
||||
}
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Utils {
|
||||
}
|
||||
|
||||
namespace DiffEditor {
|
||||
class DiffEditorWidget;
|
||||
class DiffEditorEditable;
|
||||
}
|
||||
|
||||
namespace Git {
|
||||
@@ -69,7 +69,6 @@ namespace Internal {
|
||||
|
||||
class GitPlugin;
|
||||
class GitOutputWindow;
|
||||
class GitDiffEditorWidget;
|
||||
class CommitData;
|
||||
struct GitSubmitEditorPanelData;
|
||||
class Stash;
|
||||
@@ -133,8 +132,6 @@ public:
|
||||
QString findRepositoryForDirectory(const QString &dir);
|
||||
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 QStringList &unstagedFileNames, const QStringList &stagedFileNames= QStringList());
|
||||
@@ -326,7 +323,7 @@ private:
|
||||
QTextCodec *getSourceCodec(const QString &file) const;
|
||||
VcsBase::VcsBaseEditorWidget *findExistingVCSEditor(const char *registerDynamicProperty,
|
||||
const QString &dynamicPropertyValue) const;
|
||||
DiffEditor::DiffEditorWidget *findExistingDiffEditor(const char *registerDynamicProperty,
|
||||
DiffEditor::DiffEditorEditable *findExistingDiffEditor(const char *registerDynamicProperty,
|
||||
const QString &dynamicPropertyValue) const;
|
||||
|
||||
enum CodecType { CodecSource, CodecLogOutput, CodecNone };
|
||||
|
||||
Reference in New Issue
Block a user