forked from qt-creator/qt-creator
Add DiffEditorManager, refactoring.
GitDiffSwitcher operates now on IDocument. GitDiffHandler operates now on DiffEditorController. "source" property now attached to editor's document (VcsBasePlugin). Change-Id: Ie2570a597b8b992ac1dc33b9179eca459c8a751a Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com>
This commit is contained in:
@@ -118,7 +118,7 @@ void DescriptionEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
|||||||
|
|
||||||
DiffEditor::DiffEditor()
|
DiffEditor::DiffEditor()
|
||||||
: IEditor(0)
|
: IEditor(0)
|
||||||
, m_document(new Internal::DiffEditorDocument(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE)))
|
, m_document(new DiffEditorDocument(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE)))
|
||||||
, m_descriptionWidget(0)
|
, m_descriptionWidget(0)
|
||||||
, m_diffWidget(0)
|
, m_diffWidget(0)
|
||||||
, m_diffEditorController(0)
|
, m_diffEditorController(0)
|
||||||
@@ -163,9 +163,13 @@ void DiffEditor::ctor()
|
|||||||
m_descriptionWidget->setCodeStyle(TextEditorSettings::codeStyle());
|
m_descriptionWidget->setCodeStyle(TextEditorSettings::codeStyle());
|
||||||
m_descriptionWidget->baseTextDocument()->setFontSettings(TextEditorSettings::fontSettings());
|
m_descriptionWidget->baseTextDocument()->setFontSettings(TextEditorSettings::fontSettings());
|
||||||
|
|
||||||
m_diffEditorController = m_document->diffEditorController();
|
m_diffEditorController = m_document->controller();
|
||||||
m_diffWidget->setDiffEditorController(m_diffEditorController);
|
m_diffWidget->setDiffEditorController(m_diffEditorController);
|
||||||
|
|
||||||
|
connect(m_diffEditorController, SIGNAL(cleared(QString)),
|
||||||
|
this, SLOT(slotCleared(QString)));
|
||||||
|
connect(m_diffEditorController, SIGNAL(diffContentsChanged(QList<DiffEditorController::DiffFilesContents>,QString)),
|
||||||
|
this, SLOT(slotDiffContentsChanged(QList<DiffEditorController::DiffFilesContents>,QString)));
|
||||||
connect(m_diffEditorController, SIGNAL(currentDiffFileIndexChanged(int)),
|
connect(m_diffEditorController, SIGNAL(currentDiffFileIndexChanged(int)),
|
||||||
this, SLOT(activateEntry(int)));
|
this, SLOT(activateEntry(int)));
|
||||||
connect(m_diffEditorController, SIGNAL(descriptionChanged(QString)),
|
connect(m_diffEditorController, SIGNAL(descriptionChanged(QString)),
|
||||||
@@ -209,11 +213,6 @@ Core::Id DiffEditor::id() const
|
|||||||
return Constants::DIFF_EDITOR_ID;
|
return Constants::DIFF_EDITOR_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCodec *DiffEditor::codec() const
|
|
||||||
{
|
|
||||||
return m_diffWidget->codec();
|
|
||||||
}
|
|
||||||
|
|
||||||
static QToolBar *createToolBar(const QWidget *someWidget)
|
static QToolBar *createToolBar(const QWidget *someWidget)
|
||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
@@ -275,24 +274,50 @@ QWidget *DiffEditor::toolBar()
|
|||||||
m_toggleDescriptionAction = m_toolBar->addWidget(toggleDescription);
|
m_toggleDescriptionAction = m_toolBar->addWidget(toggleDescription);
|
||||||
slotDescriptionVisibilityChanged();
|
slotDescriptionVisibilityChanged();
|
||||||
|
|
||||||
if (m_diffEditorController) {
|
connect(whitespaceButton, SIGNAL(clicked(bool)),
|
||||||
connect(whitespaceButton, SIGNAL(clicked(bool)),
|
m_diffEditorController, SLOT(setIgnoreWhitespaces(bool)));
|
||||||
m_diffEditorController, SLOT(setIgnoreWhitespaces(bool)));
|
connect(contextSpinBox, SIGNAL(valueChanged(int)),
|
||||||
connect(contextSpinBox, SIGNAL(valueChanged(int)),
|
m_diffEditorController, SLOT(setContextLinesNumber(int)));
|
||||||
m_diffEditorController, SLOT(setContextLinesNumber(int)));
|
connect(toggleSync, SIGNAL(clicked(bool)),
|
||||||
connect(toggleSync, SIGNAL(clicked(bool)),
|
m_diffEditorController, SLOT(setHorizontalScrollBarSynchronization(bool)));
|
||||||
m_diffEditorController, SLOT(setHorizontalScrollBarSynchronization(bool)));
|
connect(toggleDescription, SIGNAL(clicked(bool)),
|
||||||
connect(toggleDescription, SIGNAL(clicked(bool)),
|
m_diffEditorController, SLOT(setDescriptionVisible(bool)));
|
||||||
m_diffEditorController, SLOT(setDescriptionVisible(bool)));
|
// TODO: synchronize in opposite direction too
|
||||||
// TODO: synchronize in opposite direction too
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_toolBar;
|
return m_toolBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::setDiff(const QList<DiffEditorController::DiffFilesContents> &diffFileList,
|
DiffEditorController * DiffEditor::controller() const
|
||||||
const QString &workingDirectory)
|
|
||||||
{
|
{
|
||||||
|
return m_diffEditorController;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditor::updateEntryToolTip()
|
||||||
|
{
|
||||||
|
const QString &toolTip = m_entriesComboBox->itemData(
|
||||||
|
m_entriesComboBox->currentIndex(), Qt::ToolTipRole).toString();
|
||||||
|
m_entriesComboBox->setToolTip(toolTip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditor::entryActivated(int index)
|
||||||
|
{
|
||||||
|
updateEntryToolTip();
|
||||||
|
m_diffEditorController->setCurrentDiffFileIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditor::slotCleared(const QString &message)
|
||||||
|
{
|
||||||
|
Q_UNUSED(message)
|
||||||
|
|
||||||
|
m_entriesComboBox->clear();
|
||||||
|
updateEntryToolTip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditor::slotDiffContentsChanged(const QList<DiffEditorController::DiffFilesContents> &diffFileList,
|
||||||
|
const QString &workingDirectory)
|
||||||
|
{
|
||||||
|
Q_UNUSED(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++) {
|
||||||
@@ -331,42 +356,6 @@ void DiffEditor::setDiff(const QList<DiffEditorController::DiffFilesContents> &d
|
|||||||
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1, itemToolTip, Qt::ToolTipRole);
|
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1, itemToolTip, Qt::ToolTipRole);
|
||||||
}
|
}
|
||||||
updateEntryToolTip();
|
updateEntryToolTip();
|
||||||
if (m_diffEditorController)
|
|
||||||
m_diffEditorController->setDiffContents(diffFileList, workingDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiffEditor::setDescription(const QString &description)
|
|
||||||
{
|
|
||||||
if (m_diffEditorController)
|
|
||||||
m_diffEditorController->setDescription(description);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiffEditor::setDescriptionEnabled(bool on)
|
|
||||||
{
|
|
||||||
if (m_diffEditorController)
|
|
||||||
m_diffEditorController->setDescriptionEnabled(on);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiffEditor::clear(const QString &message)
|
|
||||||
{
|
|
||||||
m_entriesComboBox->clear();
|
|
||||||
updateEntryToolTip();
|
|
||||||
if (m_diffEditorController)
|
|
||||||
m_diffEditorController->clear(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiffEditor::updateEntryToolTip()
|
|
||||||
{
|
|
||||||
const QString &toolTip = m_entriesComboBox->itemData(
|
|
||||||
m_entriesComboBox->currentIndex(), Qt::ToolTipRole).toString();
|
|
||||||
m_entriesComboBox->setToolTip(toolTip);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiffEditor::entryActivated(int index)
|
|
||||||
{
|
|
||||||
updateEntryToolTip();
|
|
||||||
if (m_diffEditorController)
|
|
||||||
m_diffEditorController->setCurrentDiffFileIndex(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::activateEntry(int index)
|
void DiffEditor::activateEntry(int index)
|
||||||
@@ -384,9 +373,6 @@ void DiffEditor::slotDescriptionChanged(const QString &description)
|
|||||||
|
|
||||||
void DiffEditor::slotDescriptionVisibilityChanged()
|
void DiffEditor::slotDescriptionVisibilityChanged()
|
||||||
{
|
{
|
||||||
if (!m_diffEditorController)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const bool visible = m_diffEditorController->isDescriptionVisible();
|
const bool visible = m_diffEditorController->isDescriptionVisible();
|
||||||
const bool enabled = m_diffEditorController->isDescriptionEnabled();
|
const bool enabled = m_diffEditorController->isDescriptionEnabled();
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ QT_END_NAMESPACE
|
|||||||
namespace TextEditor { class BaseTextEditorWidget; }
|
namespace TextEditor { class BaseTextEditorWidget; }
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
class SideBySideDiffEditorWidget;
|
|
||||||
|
|
||||||
namespace Internal { class DiffEditorDocument; }
|
class DiffEditorDocument;
|
||||||
|
class SideBySideDiffEditorWidget;
|
||||||
|
|
||||||
class DIFFEDITOR_EXPORT DiffEditor : public Core::IEditor
|
class DIFFEDITOR_EXPORT DiffEditor : public Core::IEditor
|
||||||
{
|
{
|
||||||
@@ -58,11 +58,7 @@ public:
|
|||||||
virtual ~DiffEditor();
|
virtual ~DiffEditor();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setDiff(const QList<DiffEditorController::DiffFilesContents> &diffFileList,
|
DiffEditorController *controller() const;
|
||||||
const QString &workingDirectory = QString());
|
|
||||||
void setDescription(const QString &description);
|
|
||||||
void setDescriptionEnabled(bool on);
|
|
||||||
void clear(const QString &message);
|
|
||||||
|
|
||||||
// Core::IEditor
|
// Core::IEditor
|
||||||
bool duplicateSupported() const { return false; }
|
bool duplicateSupported() const { return false; }
|
||||||
@@ -71,7 +67,6 @@ public:
|
|||||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||||
Core::IDocument *document();
|
Core::IDocument *document();
|
||||||
Core::Id id() const;
|
Core::Id id() const;
|
||||||
QTextCodec *codec() const;
|
|
||||||
|
|
||||||
QWidget *toolBar();
|
QWidget *toolBar();
|
||||||
|
|
||||||
@@ -79,6 +74,9 @@ public slots:
|
|||||||
void activateEntry(int index);
|
void activateEntry(int index);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void slotCleared(const QString &message);
|
||||||
|
void slotDiffContentsChanged(const QList<DiffEditorController::DiffFilesContents> &diffFileList,
|
||||||
|
const QString &workingDirectory);
|
||||||
void entryActivated(int index);
|
void entryActivated(int index);
|
||||||
void slotDescriptionChanged(const QString &description);
|
void slotDescriptionChanged(const QString &description);
|
||||||
void slotDescriptionVisibilityChanged();
|
void slotDescriptionVisibilityChanged();
|
||||||
@@ -87,7 +85,7 @@ private:
|
|||||||
void ctor();
|
void ctor();
|
||||||
void updateEntryToolTip();
|
void updateEntryToolTip();
|
||||||
|
|
||||||
QSharedPointer<Internal::DiffEditorDocument> m_document;
|
QSharedPointer<DiffEditorDocument> m_document;
|
||||||
TextEditor::BaseTextEditorWidget *m_descriptionWidget;
|
TextEditor::BaseTextEditorWidget *m_descriptionWidget;
|
||||||
SideBySideDiffEditorWidget *m_diffWidget;
|
SideBySideDiffEditorWidget *m_diffWidget;
|
||||||
DiffEditorController *m_diffEditorController;
|
DiffEditorController *m_diffEditorController;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ HEADERS += diffeditor_global.h \
|
|||||||
diffeditorcontroller.h \
|
diffeditorcontroller.h \
|
||||||
diffeditordocument.h \
|
diffeditordocument.h \
|
||||||
diffeditorfactory.h \
|
diffeditorfactory.h \
|
||||||
|
diffeditormanager.h \
|
||||||
diffeditorplugin.h \
|
diffeditorplugin.h \
|
||||||
differ.h \
|
differ.h \
|
||||||
sidebysidediffeditorwidget.h
|
sidebysidediffeditorwidget.h
|
||||||
@@ -15,6 +16,7 @@ SOURCES += diffeditor.cpp \
|
|||||||
diffeditorcontroller.cpp \
|
diffeditorcontroller.cpp \
|
||||||
diffeditordocument.cpp \
|
diffeditordocument.cpp \
|
||||||
diffeditorfactory.cpp \
|
diffeditorfactory.cpp \
|
||||||
|
diffeditormanager.cpp \
|
||||||
diffeditorplugin.cpp \
|
diffeditorplugin.cpp \
|
||||||
differ.cpp \
|
differ.cpp \
|
||||||
sidebysidediffeditorwidget.cpp
|
sidebysidediffeditorwidget.cpp
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ QtcPlugin {
|
|||||||
"diffeditordocument.h",
|
"diffeditordocument.h",
|
||||||
"diffeditorfactory.cpp",
|
"diffeditorfactory.cpp",
|
||||||
"diffeditorfactory.h",
|
"diffeditorfactory.h",
|
||||||
|
"diffeditormanager.cpp",
|
||||||
|
"diffeditormanager.h",
|
||||||
"diffeditorplugin.cpp",
|
"diffeditorplugin.cpp",
|
||||||
"diffeditorplugin.h",
|
"diffeditorplugin.h",
|
||||||
"differ.cpp",
|
"differ.cpp",
|
||||||
|
|||||||
@@ -110,7 +110,8 @@ void DiffEditorController::clear(const QString &message)
|
|||||||
emit cleared(message);
|
emit cleared(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorController::setDiffContents(const QList<DiffFilesContents> &diffFileList, const QString &workingDirectory)
|
void DiffEditorController::setDiffContents(const QList<DiffFilesContents> &diffFileList,
|
||||||
|
const QString &workingDirectory)
|
||||||
{
|
{
|
||||||
m_diffFileList = diffFileList;
|
m_diffFileList = diffFileList;
|
||||||
m_workingDirectory = workingDirectory;
|
m_workingDirectory = workingDirectory;
|
||||||
@@ -188,8 +189,3 @@ void DiffEditorController::setCurrentDiffFileIndex(int diffFileIndex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
|
||||||
//QTextCodec *DiffEditorWidget::codec() const
|
|
||||||
//{
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|||||||
@@ -60,8 +60,6 @@ public:
|
|||||||
DiffEditorController(QObject *parent = 0);
|
DiffEditorController(QObject *parent = 0);
|
||||||
~DiffEditorController();
|
~DiffEditorController();
|
||||||
|
|
||||||
// QTextCodec *codec() const;
|
|
||||||
|
|
||||||
QString clearMessage() const;
|
QString clearMessage() const;
|
||||||
|
|
||||||
QList<DiffFilesContents> diffContents() const;
|
QList<DiffFilesContents> diffContents() const;
|
||||||
@@ -78,7 +76,8 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void clear();
|
void clear();
|
||||||
void clear(const QString &message);
|
void clear(const QString &message);
|
||||||
void setDiffContents(const QList<DiffEditorController::DiffFilesContents> &diffFileList, const QString &workingDirectory = QString());
|
void setDiffContents(const QList<DiffEditorController::DiffFilesContents> &diffFileList,
|
||||||
|
const QString &workingDirectory = QString());
|
||||||
void setDescription(const QString &description);
|
void setDescription(const QString &description);
|
||||||
void setDescriptionEnabled(bool on);
|
void setDescriptionEnabled(bool on);
|
||||||
|
|
||||||
@@ -90,7 +89,7 @@ public slots:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
// This sets the current diff file index to -1
|
// This sets the current diff file index to -1
|
||||||
void cleared(const QString message);
|
void cleared(const QString &message);
|
||||||
// This sets the current diff file index to 0 (unless diffFileList is empty)
|
// This sets the current diff file index to 0 (unless diffFileList is empty)
|
||||||
void diffContentsChanged(const QList<DiffEditorController::DiffFilesContents> &diffFileList, const QString &workingDirectory);
|
void diffContentsChanged(const QList<DiffEditorController::DiffFilesContents> &diffFileList, const QString &workingDirectory);
|
||||||
void descriptionChanged(const QString &description);
|
void descriptionChanged(const QString &description);
|
||||||
|
|||||||
@@ -34,9 +34,6 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
///////////////////////////////// DiffFile //////////////////////////////////
|
|
||||||
|
|
||||||
DiffEditorDocument::DiffEditorDocument(const QString &mimeType) :
|
DiffEditorDocument::DiffEditorDocument(const QString &mimeType) :
|
||||||
Core::IDocument(),
|
Core::IDocument(),
|
||||||
@@ -51,7 +48,7 @@ DiffEditorDocument::~DiffEditorDocument()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditorController *DiffEditorDocument::diffEditorController() const
|
DiffEditorController *DiffEditorDocument::controller() const
|
||||||
{
|
{
|
||||||
return m_diffEditorController;
|
return m_diffEditorController;
|
||||||
}
|
}
|
||||||
@@ -90,5 +87,4 @@ bool DiffEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeTyp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
|||||||
@@ -38,16 +38,14 @@ namespace DiffEditor {
|
|||||||
|
|
||||||
class DiffEditorController;
|
class DiffEditorController;
|
||||||
|
|
||||||
namespace Internal {
|
class DIFFEDITOR_EXPORT DiffEditorDocument : public Core::IDocument
|
||||||
|
|
||||||
class DiffEditorDocument : public Core::IDocument
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DiffEditorDocument(const QString &mimeType);
|
explicit DiffEditorDocument(const QString &mimeType);
|
||||||
virtual ~DiffEditorDocument();
|
virtual ~DiffEditorDocument();
|
||||||
|
|
||||||
DiffEditorController *diffEditorController() const;
|
DiffEditorController *controller() const;
|
||||||
|
|
||||||
bool setContents(const QByteArray &contents);
|
bool setContents(const QByteArray &contents);
|
||||||
QString defaultPath() const { return QString(); }
|
QString defaultPath() const { return QString(); }
|
||||||
@@ -65,7 +63,6 @@ private:
|
|||||||
DiffEditorController *m_diffEditorController;
|
DiffEditorController *m_diffEditorController;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
|
||||||
#endif // DIFFEDITORDOCUMENT_H
|
#endif // DIFFEDITORDOCUMENT_H
|
||||||
|
|||||||
118
src/plugins/diffeditor/diffeditormanager.cpp
Normal file
118
src/plugins/diffeditor/diffeditormanager.cpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "diffeditormanager.h"
|
||||||
|
#include "diffeditor.h"
|
||||||
|
#include "diffeditorconstants.h"
|
||||||
|
#include "diffeditordocument.h"
|
||||||
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/id.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
namespace DiffEditor {
|
||||||
|
|
||||||
|
static DiffEditorManager *m_instance = 0;
|
||||||
|
|
||||||
|
DiffEditorManager::DiffEditorManager(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(!m_instance, return);
|
||||||
|
m_instance = this;
|
||||||
|
|
||||||
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
||||||
|
connect(editorManager, SIGNAL(editorsClosed(QList<Core::IEditor*>)),
|
||||||
|
this, SLOT(slotEditorsClosed(QList<Core::IEditor*>)));
|
||||||
|
}
|
||||||
|
|
||||||
|
DiffEditorManager::~DiffEditorManager()
|
||||||
|
{
|
||||||
|
m_instance = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DiffEditorManager *DiffEditorManager::instance()
|
||||||
|
{
|
||||||
|
return m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditorManager::slotEditorsClosed(const QList<Core::IEditor *> &editors)
|
||||||
|
{
|
||||||
|
QMap<Core::IDocument *, int> editorsForDocument;
|
||||||
|
for (int i = 0; i < editors.count(); i++) {
|
||||||
|
DiffEditor *diffEditor = qobject_cast<DiffEditor *>(editors.at(i));
|
||||||
|
if (diffEditor) {
|
||||||
|
Core::IDocument *document = diffEditor->document();
|
||||||
|
editorsForDocument[document]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Core::DocumentModel *documentModel = Core::EditorManager::documentModel();
|
||||||
|
QMapIterator<Core::IDocument *, int> it(editorsForDocument);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
if (documentModel->editorsForDocument(it.key()).count() == 0) { // no other editors use that document
|
||||||
|
DiffEditorDocument *document
|
||||||
|
= qobject_cast<DiffEditorDocument *>(it.key());
|
||||||
|
if (document) {
|
||||||
|
const QString documentId = documentToId.value(document);
|
||||||
|
documentToId.remove(document);
|
||||||
|
idToDocument.remove(documentId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DiffEditorDocument *DiffEditorManager::find(const QString &documentId)
|
||||||
|
{
|
||||||
|
return instance()->idToDocument.value(documentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
DiffEditorDocument *DiffEditorManager::findOrCreate(const QString &documentId, const QString &displayName)
|
||||||
|
{
|
||||||
|
DiffEditorDocument *document = find(documentId);
|
||||||
|
if (document)
|
||||||
|
return document;
|
||||||
|
|
||||||
|
const QString msgWait = tr("Waiting for data...");
|
||||||
|
DiffEditor *diffEditor = qobject_cast<DiffEditor *>(
|
||||||
|
Core::EditorManager::openEditorWithContents(Constants::DIFF_EDITOR_ID,
|
||||||
|
0, msgWait.toUtf8()));
|
||||||
|
QTC_ASSERT(diffEditor, return 0);
|
||||||
|
|
||||||
|
document = qobject_cast<DiffEditorDocument *>(diffEditor->document());
|
||||||
|
QTC_ASSERT(diffEditor, return 0);
|
||||||
|
|
||||||
|
document->setDisplayName(displayName);
|
||||||
|
|
||||||
|
instance()->idToDocument.insert(documentId, document);
|
||||||
|
instance()->documentToId.insert(document, documentId);
|
||||||
|
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace DiffEditor
|
||||||
66
src/plugins/diffeditor/diffeditormanager.h
Normal file
66
src/plugins/diffeditor/diffeditormanager.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 DIFFEDITORMANAGER_H
|
||||||
|
#define DIFFEDITORMANAGER_H
|
||||||
|
|
||||||
|
#include "diffeditor_global.h"
|
||||||
|
|
||||||
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
|
#include <coreplugin/idocument.h>
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
namespace DiffEditor {
|
||||||
|
|
||||||
|
class DiffEditorDocument;
|
||||||
|
|
||||||
|
class DIFFEDITOR_EXPORT DiffEditorManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DiffEditorManager(QObject *parent);
|
||||||
|
virtual ~DiffEditorManager();
|
||||||
|
|
||||||
|
static DiffEditorManager *instance();
|
||||||
|
|
||||||
|
static DiffEditorDocument *find(const QString &documentId);
|
||||||
|
static DiffEditorDocument *findOrCreate(const QString &documentId, const QString &displayName);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void slotEditorsClosed(const QList<Core::IEditor *> &editors);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMap<QString, DiffEditorDocument *> idToDocument;
|
||||||
|
QMap<DiffEditorDocument *, QString> documentToId;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace DiffEditor
|
||||||
|
|
||||||
|
#endif // DIFFEDITORMANAGER_H
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
#include "diffeditor.h"
|
#include "diffeditor.h"
|
||||||
#include "diffeditorconstants.h"
|
#include "diffeditorconstants.h"
|
||||||
#include "diffeditorfactory.h"
|
#include "diffeditorfactory.h"
|
||||||
#include "sidebysidediffeditorwidget.h"
|
#include "diffeditormanager.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
@@ -74,6 +74,8 @@ bool DiffEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
|
|||||||
|
|
||||||
addAutoReleasedObject(new DiffEditorFactory(this));
|
addAutoReleasedObject(new DiffEditorFactory(this));
|
||||||
|
|
||||||
|
new DiffEditorManager(this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,10 +109,8 @@ void DiffEditorPlugin::diff()
|
|||||||
|
|
||||||
Core::EditorManager::activateEditor(editor);
|
Core::EditorManager::activateEditor(editor);
|
||||||
|
|
||||||
QTextCodec *codec = editor->codec();
|
const QString text1 = getFileContents(fileName1);
|
||||||
|
const QString text2 = getFileContents(fileName2);
|
||||||
const QString text1 = getFileContents(fileName1, codec);
|
|
||||||
const QString text2 = getFileContents(fileName2, codec);
|
|
||||||
|
|
||||||
DiffEditorController::DiffFilesContents dfc;
|
DiffEditorController::DiffFilesContents dfc;
|
||||||
dfc.leftFileInfo = fileName1;
|
dfc.leftFileInfo = fileName1;
|
||||||
@@ -120,14 +120,14 @@ void DiffEditorPlugin::diff()
|
|||||||
QList<DiffEditorController::DiffFilesContents> list;
|
QList<DiffEditorController::DiffFilesContents> list;
|
||||||
list.append(dfc);
|
list.append(dfc);
|
||||||
|
|
||||||
editor->setDiff(list);
|
editor->controller()->setDiffContents(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DiffEditorPlugin::getFileContents(const QString &fileName, QTextCodec *codec) const
|
QString DiffEditorPlugin::getFileContents(const QString &fileName) const
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
return codec->toUnicode(file.readAll());
|
return Core::EditorManager::defaultTextCodec()->toUnicode(file.readAll());
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +136,8 @@ QString DiffEditorPlugin::getFileContents(const QString &fileName, QTextCodec *c
|
|||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
|
|
||||||
|
#include "sidebysidediffeditorwidget.h"
|
||||||
|
|
||||||
void DiffEditor::Internal::DiffEditorPlugin::testAssemblyRows()
|
void DiffEditor::Internal::DiffEditorPlugin::testAssemblyRows()
|
||||||
{
|
{
|
||||||
SideBySideDiffEditorWidget::testAssemblyRows();
|
SideBySideDiffEditorWidget::testAssemblyRows();
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ private slots:
|
|||||||
#endif // WITH_TESTS
|
#endif // WITH_TESTS
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString getFileContents(const QString &fileName, QTextCodec *codec) const;
|
QString getFileContents(const QString &fileName) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -405,11 +405,6 @@ public:
|
|||||||
|
|
||||||
SideDiffEditorWidget(QWidget *parent = 0);
|
SideDiffEditorWidget(QWidget *parent = 0);
|
||||||
|
|
||||||
// TODO: remove me, codec should be taken from somewhere else
|
|
||||||
QTextCodec *codec() const {
|
|
||||||
return const_cast<QTextCodec *>(baseTextDocument()->codec());
|
|
||||||
}
|
|
||||||
|
|
||||||
// block number, file info
|
// block number, file info
|
||||||
QMap<int, DiffEditorController::DiffFileInfo> fileInfo() const { return m_fileInfo; }
|
QMap<int, DiffEditorController::DiffFileInfo> fileInfo() const { return m_fileInfo; }
|
||||||
|
|
||||||
@@ -1175,11 +1170,6 @@ void SideBySideDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex)
|
|||||||
m_rightEditor->centerCursor();
|
m_rightEditor->centerCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCodec *SideBySideDiffEditorWidget::codec() const
|
|
||||||
{
|
|
||||||
return const_cast<QTextCodec *>(m_leftEditor->codec());
|
|
||||||
}
|
|
||||||
|
|
||||||
FileData SideBySideDiffEditorWidget::calculateContextData(const ChunkData &originalData) const
|
FileData SideBySideDiffEditorWidget::calculateContextData(const ChunkData &originalData) const
|
||||||
{
|
{
|
||||||
const int contextLinesNumber = m_controller ? m_controller->contextLinesNumber() : 3;
|
const int contextLinesNumber = m_controller ? m_controller->contextLinesNumber() : 3;
|
||||||
|
|||||||
@@ -36,15 +36,10 @@
|
|||||||
|
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor { class FontSettings; }
|
||||||
class BaseTextEditorWidget;
|
|
||||||
class FontSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QPlainTextEdit;
|
|
||||||
class QSplitter;
|
class QSplitter;
|
||||||
class QSyntaxHighlighter;
|
|
||||||
class QTextCharFormat;
|
class QTextCharFormat;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -53,7 +48,6 @@ QT_END_NAMESPACE
|
|||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
class SideDiffEditorWidget;
|
class SideDiffEditorWidget;
|
||||||
class TextLineData;
|
|
||||||
class ChunkData;
|
class ChunkData;
|
||||||
class FileData;
|
class FileData;
|
||||||
|
|
||||||
@@ -67,8 +61,6 @@ public:
|
|||||||
void setDiffEditorController(DiffEditorController *controller);
|
void setDiffEditorController(DiffEditorController *controller);
|
||||||
DiffEditorController *diffEditorController() const;
|
DiffEditorController *diffEditorController() const;
|
||||||
|
|
||||||
QTextCodec *codec() const;
|
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
static void testAssemblyRows();
|
static void testAssemblyRows();
|
||||||
#endif // WITH_TESTS
|
#endif // WITH_TESTS
|
||||||
|
|||||||
@@ -59,8 +59,10 @@
|
|||||||
#include <vcsbase/vcsbaseoutputwindow.h>
|
#include <vcsbase/vcsbaseoutputwindow.h>
|
||||||
#include <vcsbase/vcsbaseplugin.h>
|
#include <vcsbase/vcsbaseplugin.h>
|
||||||
|
|
||||||
#include <diffeditor/diffeditor.h>
|
|
||||||
#include <diffeditor/diffeditorconstants.h>
|
#include <diffeditor/diffeditorconstants.h>
|
||||||
|
#include <diffeditor/diffeditorcontroller.h>
|
||||||
|
#include <diffeditor/diffeditordocument.h>
|
||||||
|
#include <diffeditor/diffeditormanager.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -106,26 +108,7 @@ public:
|
|||||||
DiffShow
|
DiffShow
|
||||||
};
|
};
|
||||||
|
|
||||||
GitDiffSwitcher(Core::IEditor *parentEditor, GitClient *gitClient)
|
GitDiffSwitcher(Core::IDocument *parentDocument, GitClient *gitClient);
|
||||||
: QObject(parentEditor),
|
|
||||||
m_editor(parentEditor),
|
|
||||||
m_gitClient(gitClient)
|
|
||||||
{
|
|
||||||
m_usingDiffEditor = gitClient->settings()->boolValue(GitSettings::useDiffEditorKey);
|
|
||||||
QIcon actionIcon = m_usingDiffEditor
|
|
||||||
? QIcon(QLatin1String(Core::Constants::ICON_TEXT_DIFF))
|
|
||||||
: QIcon(QLatin1String(Core::Constants::ICON_SIDE_BY_SIDE_DIFF));
|
|
||||||
|
|
||||||
const QString actionToolTip = m_usingDiffEditor
|
|
||||||
? tr("Switch to Text Diff Editor")
|
|
||||||
: tr("Switch to Side By Side Diff Editor");
|
|
||||||
|
|
||||||
QAction *switchAction = new QAction(actionIcon, actionToolTip, parentEditor);
|
|
||||||
parentEditor->toolBar()->addAction(switchAction);
|
|
||||||
|
|
||||||
// must be queued connection because execute() removes the editor & tool bar that the action was added to
|
|
||||||
connect(switchAction, SIGNAL(triggered()), this, SLOT(execute()), Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setWorkingDirectory(const QString &workingDir) { m_workingDirectory = workingDir; }
|
void setWorkingDirectory(const QString &workingDir) { m_workingDirectory = workingDir; }
|
||||||
void setDiffType(DiffType type) { m_diffType = type; }
|
void setDiffType(DiffType type) { m_diffType = type; }
|
||||||
@@ -141,11 +124,16 @@ public:
|
|||||||
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
|
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
|
||||||
void setBaseArguments(const QStringList &args) { m_baseArguments = args; }
|
void setBaseArguments(const QStringList &args) { m_baseArguments = args; }
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
void execute();
|
void slotEditorOpened(Core::IEditor *editor);
|
||||||
|
void slotEditorClosed(Core::IEditor *editor);
|
||||||
|
void execute(QObject *editor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::IEditor *m_editor;
|
void attachAction(Core::IEditor *editor);
|
||||||
|
QString actionText();
|
||||||
|
|
||||||
|
Core::IDocument *m_document;
|
||||||
GitClient *m_gitClient;
|
GitClient *m_gitClient;
|
||||||
QString m_workingDirectory;
|
QString m_workingDirectory;
|
||||||
DiffType m_diffType;
|
DiffType m_diffType;
|
||||||
@@ -158,11 +146,80 @@ private:
|
|||||||
QString m_id;
|
QString m_id;
|
||||||
QString m_displayName;
|
QString m_displayName;
|
||||||
QStringList m_baseArguments;
|
QStringList m_baseArguments;
|
||||||
|
|
||||||
|
QSignalMapper *m_signalMapper;
|
||||||
|
QMap<QObject *, bool> m_editorToUsingSideBySideDiffEditor;
|
||||||
};
|
};
|
||||||
|
|
||||||
void GitDiffSwitcher::execute()
|
GitDiffSwitcher::GitDiffSwitcher(Core::IDocument *parentDocument, GitClient *gitClient)
|
||||||
|
: QObject(parentDocument),
|
||||||
|
m_document(parentDocument),
|
||||||
|
m_gitClient(gitClient),
|
||||||
|
m_signalMapper(new QSignalMapper(this))
|
||||||
{
|
{
|
||||||
m_gitClient->settings()->setValue(GitSettings::useDiffEditorKey, !m_usingDiffEditor);
|
Core::DocumentModel *documentModel = Core::EditorManager::documentModel();
|
||||||
|
QList<Core::IEditor *> editors = documentModel->editorsForDocument(m_document);
|
||||||
|
for (int i = 0; i < editors.count(); i++)
|
||||||
|
attachAction(editors.at(i));
|
||||||
|
|
||||||
|
// must be queued connection because execute() removes the editor & tool bar that the action was added to
|
||||||
|
connect(m_signalMapper, SIGNAL(mapped(QObject*)), this, SLOT(execute(QObject*)), Qt::QueuedConnection);
|
||||||
|
connect(Core::EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)),
|
||||||
|
this, SLOT(slotEditorOpened(Core::IEditor*)));
|
||||||
|
connect(Core::EditorManager::instance(), SIGNAL(editorAboutToClose(Core::IEditor*)),
|
||||||
|
this, SLOT(slotEditorClosed(Core::IEditor*)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitDiffSwitcher::attachAction(Core::IEditor *editor)
|
||||||
|
{
|
||||||
|
if (m_editorToUsingSideBySideDiffEditor.contains(editor))
|
||||||
|
return;
|
||||||
|
|
||||||
|
const bool usingSideBySideDiffEditor = m_gitClient->settings()->boolValue(GitSettings::useDiffEditorKey);
|
||||||
|
QIcon actionIcon = usingSideBySideDiffEditor
|
||||||
|
? QIcon(QLatin1String(Core::Constants::ICON_TEXT_DIFF))
|
||||||
|
: QIcon(QLatin1String(Core::Constants::ICON_SIDE_BY_SIDE_DIFF));
|
||||||
|
|
||||||
|
const QString actionToolTip = usingSideBySideDiffEditor
|
||||||
|
? tr("Switch to Text Diff Editor")
|
||||||
|
: tr("Switch to Side By Side Diff Editor");
|
||||||
|
|
||||||
|
QAction *switchAction = new QAction(actionIcon, actionToolTip, editor);
|
||||||
|
editor->toolBar()->addAction(switchAction);
|
||||||
|
connect(switchAction, SIGNAL(triggered()),
|
||||||
|
m_signalMapper, SLOT(map()));
|
||||||
|
m_signalMapper->setMapping(switchAction, editor);
|
||||||
|
|
||||||
|
m_editorToUsingSideBySideDiffEditor.insert(editor, usingSideBySideDiffEditor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitDiffSwitcher::slotEditorOpened(Core::IEditor *editor)
|
||||||
|
{
|
||||||
|
Core::IDocument *document = editor->document();
|
||||||
|
if (document != m_document)
|
||||||
|
return;
|
||||||
|
|
||||||
|
attachAction(editor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitDiffSwitcher::slotEditorClosed(Core::IEditor *editor)
|
||||||
|
{
|
||||||
|
Core::IDocument *document = editor->document();
|
||||||
|
if (document != m_document)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_editorToUsingSideBySideDiffEditor.remove(editor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitDiffSwitcher::execute(QObject *editor)
|
||||||
|
{
|
||||||
|
bool usingSideBySideEditor = !m_editorToUsingSideBySideDiffEditor.value(editor);
|
||||||
|
m_editorToUsingSideBySideDiffEditor[editor] = usingSideBySideEditor;
|
||||||
|
m_gitClient->settings()->setValue(GitSettings::useDiffEditorKey, usingSideBySideEditor);
|
||||||
|
|
||||||
|
Core::IEditor *ieditor = qobject_cast<Core::IEditor*>(editor);
|
||||||
|
Core::EditorManager::activateEditor(ieditor);
|
||||||
|
|
||||||
switch (m_diffType) {
|
switch (m_diffType) {
|
||||||
case DiffRepository:
|
case DiffRepository:
|
||||||
m_gitClient->diff(m_workingDirectory, QStringList(), QStringList());
|
m_gitClient->diff(m_workingDirectory, QStringList(), QStringList());
|
||||||
@@ -185,7 +242,8 @@ void GitDiffSwitcher::execute()
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Core::EditorManager::closeEditor(m_editor, false);
|
|
||||||
|
Core::EditorManager::closeEditor(ieditor, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
class GitDiffHandler : public QObject
|
class GitDiffHandler : public QObject
|
||||||
@@ -215,7 +273,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GitDiffHandler(DiffEditor::DiffEditor *editor,
|
GitDiffHandler(DiffEditor::DiffEditorController *editorController,
|
||||||
const QString &gitPath,
|
const QString &gitPath,
|
||||||
const QString &workingDirectory,
|
const QString &workingDirectory,
|
||||||
const QProcessEnvironment &environment,
|
const QProcessEnvironment &environment,
|
||||||
@@ -248,7 +306,7 @@ private:
|
|||||||
void feedEditor();
|
void feedEditor();
|
||||||
QString workingTreeContents(const QString &fileName) const;
|
QString workingTreeContents(const QString &fileName) const;
|
||||||
|
|
||||||
QPointer<DiffEditor::DiffEditor> m_editor;
|
QPointer<DiffEditor::DiffEditorController> m_editorController;
|
||||||
const QString m_gitPath;
|
const QString m_gitPath;
|
||||||
const QString m_workingDirectory;
|
const QString m_workingDirectory;
|
||||||
const QProcessEnvironment m_processEnvironment;
|
const QProcessEnvironment m_processEnvironment;
|
||||||
@@ -279,12 +337,12 @@ inline bool operator<(const GitDiffHandler::Revision &rev1, const GitDiffHandler
|
|||||||
return rev1.id < rev2.id;
|
return rev1.id < rev2.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
GitDiffHandler::GitDiffHandler(DiffEditor::DiffEditor *editor,
|
GitDiffHandler::GitDiffHandler(DiffEditor::DiffEditorController *editorController,
|
||||||
const QString &gitPath,
|
const QString &gitPath,
|
||||||
const QString &workingDirectory,
|
const QString &workingDirectory,
|
||||||
const QProcessEnvironment &environment,
|
const QProcessEnvironment &environment,
|
||||||
int timeout)
|
int timeout)
|
||||||
: m_editor(editor),
|
: m_editorController(editorController),
|
||||||
m_gitPath(gitPath),
|
m_gitPath(gitPath),
|
||||||
m_workingDirectory(workingDirectory),
|
m_workingDirectory(workingDirectory),
|
||||||
m_processEnvironment(environment),
|
m_processEnvironment(environment),
|
||||||
@@ -359,11 +417,14 @@ void GitDiffHandler::show(const QString &id)
|
|||||||
|
|
||||||
void GitDiffHandler::collectShowDescription(const QString &id)
|
void GitDiffHandler::collectShowDescription(const QString &id)
|
||||||
{
|
{
|
||||||
if (m_editor.isNull())
|
if (m_editorController.isNull()) {
|
||||||
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
m_editor->clear(m_waitMessage);
|
}
|
||||||
|
|
||||||
|
m_editorController->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);
|
||||||
command->setCodec(m_editor->codec());
|
command->setCodec(Core::EditorManager::defaultTextCodec());
|
||||||
connect(command, SIGNAL(output(QString)), this, SLOT(slotShowDescriptionReceived(QString)));
|
connect(command, SIGNAL(output(QString)), this, SLOT(slotShowDescriptionReceived(QString)));
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << QLatin1String("show") << QLatin1String("-s")
|
arguments << QLatin1String("show") << QLatin1String("-s")
|
||||||
@@ -374,11 +435,13 @@ void GitDiffHandler::collectShowDescription(const QString &id)
|
|||||||
|
|
||||||
void GitDiffHandler::slotShowDescriptionReceived(const QString &description)
|
void GitDiffHandler::slotShowDescriptionReceived(const QString &description)
|
||||||
{
|
{
|
||||||
if (m_editor.isNull())
|
if (m_editorController.isNull()) {
|
||||||
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_editor->setDescription(GitPlugin::instance()->gitClient()->
|
m_editorController->setDescription(GitPlugin::instance()->gitClient()->
|
||||||
extendedShowDescription(m_workingDirectory, description));
|
extendedShowDescription(m_workingDirectory, description));
|
||||||
|
|
||||||
collectFilesList(QStringList()
|
collectFilesList(QStringList()
|
||||||
<< m_requestedRevisionRange.begin.id
|
<< m_requestedRevisionRange.begin.id
|
||||||
@@ -387,11 +450,14 @@ void GitDiffHandler::slotShowDescriptionReceived(const QString &description)
|
|||||||
|
|
||||||
void GitDiffHandler::collectFilesList(const QStringList &additionalArguments)
|
void GitDiffHandler::collectFilesList(const QStringList &additionalArguments)
|
||||||
{
|
{
|
||||||
if (m_editor.isNull())
|
if (m_editorController.isNull()) {
|
||||||
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
m_editor->clear(m_waitMessage);
|
}
|
||||||
|
|
||||||
|
m_editorController->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);
|
||||||
command->setCodec(m_editor->codec());
|
command->setCodec(Core::EditorManager::defaultTextCodec());
|
||||||
connect(command, SIGNAL(output(QString)), this, SLOT(slotFileListReceived(QString)));
|
connect(command, SIGNAL(output(QString)), this, SLOT(slotFileListReceived(QString)));
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << QLatin1String("diff") << QLatin1String("--name-only") << additionalArguments;
|
arguments << QLatin1String("diff") << QLatin1String("--name-only") << additionalArguments;
|
||||||
@@ -402,8 +468,10 @@ void GitDiffHandler::collectFilesList(const QStringList &additionalArguments)
|
|||||||
|
|
||||||
void GitDiffHandler::slotFileListReceived(const QString &fileList)
|
void GitDiffHandler::slotFileListReceived(const QString &fileList)
|
||||||
{
|
{
|
||||||
if (m_editor.isNull())
|
if (m_editorController.isNull()) {
|
||||||
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList fileNames = fileList.split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
QStringList fileNames = fileList.split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
||||||
fileNames.removeDuplicates();
|
fileNames.removeDuplicates();
|
||||||
@@ -459,8 +527,7 @@ void GitDiffHandler::collectFilesContents()
|
|||||||
// prepare job here
|
// prepare job here
|
||||||
|
|
||||||
VcsBase::Command *command = new VcsBase::Command(m_gitPath, m_workingDirectory, m_processEnvironment);
|
VcsBase::Command *command = new VcsBase::Command(m_gitPath, m_workingDirectory, m_processEnvironment);
|
||||||
if (m_editor)
|
command->setCodec(Core::EditorManager::defaultTextCodec());
|
||||||
command->setCodec(m_editor->codec());
|
|
||||||
connect(command, SIGNAL(output(QString)), this, SLOT(slotFileContentsReceived(QString)));
|
connect(command, SIGNAL(output(QString)), this, SLOT(slotFileContentsReceived(QString)));
|
||||||
|
|
||||||
QString revisionArgument = (revision.type == Other)
|
QString revisionArgument = (revision.type == Other)
|
||||||
@@ -483,8 +550,10 @@ void GitDiffHandler::collectFilesContents()
|
|||||||
|
|
||||||
void GitDiffHandler::slotFileContentsReceived(const QString &contents)
|
void GitDiffHandler::slotFileContentsReceived(const QString &contents)
|
||||||
{
|
{
|
||||||
if (m_editor.isNull())
|
if (m_editorController.isNull()) {
|
||||||
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QMap<QString, QMap<Revision, bool> >::iterator itFile
|
QMap<QString, QMap<Revision, bool> >::iterator itFile
|
||||||
= m_pendingRevisions.begin();
|
= m_pendingRevisions.begin();
|
||||||
@@ -511,6 +580,11 @@ void GitDiffHandler::slotFileContentsReceived(const QString &contents)
|
|||||||
|
|
||||||
void GitDiffHandler::feedEditor()
|
void GitDiffHandler::feedEditor()
|
||||||
{
|
{
|
||||||
|
if (m_editorController.isNull()) {
|
||||||
|
deleteLater();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QList<DiffEditor::DiffEditorController::DiffFilesContents> list;
|
QList<DiffEditor::DiffEditorController::DiffFilesContents> list;
|
||||||
|
|
||||||
QMap<QString, QList<RevisionRange> >::const_iterator itFile
|
QMap<QString, QList<RevisionRange> >::const_iterator itFile
|
||||||
@@ -535,7 +609,7 @@ void GitDiffHandler::feedEditor()
|
|||||||
++itFile;
|
++itFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_editor->setDiff(list, m_workingDirectory);
|
m_editorController->setDiffContents(list, m_workingDirectory);
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,7 +620,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->codec()->toUnicode(file.readAll());
|
return Core::EditorManager::defaultTextCodec()->toUnicode(file.readAll());
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1021,33 +1095,14 @@ VcsBase::VcsBaseEditorWidget *GitClient::findExistingVCSEditor(const char *regis
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditor::DiffEditor *GitClient::findExistingDiffEditor(const char *registerDynamicProperty,
|
DiffEditor::DiffEditorDocument *GitClient::createDiffEditor(const QString documentId,
|
||||||
const QString &dynamicPropertyValue) const
|
|
||||||
{
|
|
||||||
DiffEditor::DiffEditor *diffEditor = qobject_cast<DiffEditor::DiffEditor *>(
|
|
||||||
locateEditor(registerDynamicProperty, dynamicPropertyValue));
|
|
||||||
if (diffEditor) {
|
|
||||||
diffEditor->document()->setContents(m_msgWait.toUtf8());
|
|
||||||
Core::EditorManager::activateEditor(diffEditor);
|
|
||||||
}
|
|
||||||
return diffEditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiffEditor::DiffEditor *GitClient::createDiffEditor(const char *registerDynamicProperty,
|
|
||||||
const QString &dynamicPropertyValue,
|
|
||||||
const QString &source,
|
const QString &source,
|
||||||
const QString &titlePattern,
|
const QString &title) const
|
||||||
const Core::Id editorId) const
|
|
||||||
{
|
{
|
||||||
QString title = titlePattern;
|
DiffEditor::DiffEditorDocument *diffEditorDocument = DiffEditor::DiffEditorManager::findOrCreate(documentId, title);
|
||||||
DiffEditor::DiffEditor *diffEditor = qobject_cast<DiffEditor::DiffEditor *>(
|
QTC_ASSERT(diffEditorDocument, return 0);
|
||||||
Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait.toUtf8()));
|
VcsBasePlugin::setSource(diffEditorDocument, source);
|
||||||
QTC_ASSERT(diffEditor, return 0);
|
return diffEditorDocument;
|
||||||
diffEditor->document()->setProperty(registerDynamicProperty, dynamicPropertyValue);
|
|
||||||
VcsBasePlugin::setSource(diffEditor, source);
|
|
||||||
|
|
||||||
Core::EditorManager::activateEditor(diffEditor);
|
|
||||||
return diffEditor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an editor associated to VCS output of a source file/directory
|
/* Create an editor associated to VCS output of a source file/directory
|
||||||
@@ -1099,19 +1154,16 @@ void GitClient::diff(const QString &workingDirectory,
|
|||||||
{
|
{
|
||||||
const QString title = tr("Git Diff");
|
const QString title = tr("Git Diff");
|
||||||
const int timeout = settings()->intValue(GitSettings::timeoutKey);
|
const int timeout = settings()->intValue(GitSettings::timeoutKey);
|
||||||
Core::IEditor *newEditor = 0;
|
Core::IDocument *newDocument = 0;
|
||||||
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
||||||
const char *propertyName = "sideBySideOriginalFileName";
|
const QString documentId = QLatin1String("sideBySideOriginalFileName") + workingDirectory;
|
||||||
DiffEditor::DiffEditor *diffEditor = findExistingDiffEditor(propertyName, workingDirectory);
|
DiffEditor::DiffEditorDocument *diffEditorDocument = DiffEditor::DiffEditorManager::find(documentId);
|
||||||
if (!diffEditor) {
|
if (!diffEditorDocument)
|
||||||
newEditor = diffEditor = createDiffEditor(propertyName,
|
newDocument = diffEditorDocument = createDiffEditor(documentId, workingDirectory, title);
|
||||||
workingDirectory,
|
|
||||||
workingDirectory,
|
|
||||||
title,
|
|
||||||
DiffEditor::Constants::DIFF_EDITOR_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
GitDiffHandler *handler = new GitDiffHandler(diffEditor,
|
Core::EditorManager::activateEditorForDocument(diffEditorDocument);
|
||||||
|
|
||||||
|
GitDiffHandler *handler = new GitDiffHandler(diffEditorDocument->controller(),
|
||||||
gitBinaryPath(),
|
gitBinaryPath(),
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
processEnvironment(),
|
processEnvironment(),
|
||||||
@@ -1144,7 +1196,7 @@ void GitClient::diff(const QString &workingDirectory,
|
|||||||
propertyName,
|
propertyName,
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
argWidget);
|
argWidget);
|
||||||
newEditor = vcsEditor->editor();
|
newDocument = vcsEditor->editor()->document();
|
||||||
connect(vcsEditor, SIGNAL(diffChunkApplied(VcsBase::DiffChunk)),
|
connect(vcsEditor, SIGNAL(diffChunkApplied(VcsBase::DiffChunk)),
|
||||||
argWidget, SLOT(executeCommand()));
|
argWidget, SLOT(executeCommand()));
|
||||||
connect(vcsEditor, SIGNAL(diffChunkReverted(VcsBase::DiffChunk)),
|
connect(vcsEditor, SIGNAL(diffChunkReverted(VcsBase::DiffChunk)),
|
||||||
@@ -1195,8 +1247,8 @@ void GitClient::diff(const QString &workingDirectory,
|
|||||||
command->addFlags(diffExecutionFlags());
|
command->addFlags(diffExecutionFlags());
|
||||||
command->execute();
|
command->execute();
|
||||||
}
|
}
|
||||||
if (newEditor) {
|
if (newDocument) {
|
||||||
GitDiffSwitcher *switcher = new GitDiffSwitcher(newEditor, this);
|
GitDiffSwitcher *switcher = new GitDiffSwitcher(newDocument, this);
|
||||||
switcher->setWorkingDirectory(workingDirectory);
|
switcher->setWorkingDirectory(workingDirectory);
|
||||||
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
||||||
// local repository diff
|
// local repository diff
|
||||||
@@ -1217,18 +1269,16 @@ void GitClient::diff(const QString &workingDirectory, const QString &fileName)
|
|||||||
{
|
{
|
||||||
const QString title = tr("Git Diff \"%1\"").arg(fileName);
|
const QString title = tr("Git Diff \"%1\"").arg(fileName);
|
||||||
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, fileName);
|
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, fileName);
|
||||||
Core::IEditor *newEditor = 0;
|
Core::IDocument *newDocument = 0;
|
||||||
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
||||||
const char *propertyName = "sideBySideOriginalFileName";
|
const QString documentId = QLatin1String("sideBySideOriginalFileName") + sourceFile;
|
||||||
DiffEditor::DiffEditor *diffEditor = findExistingDiffEditor(propertyName, sourceFile);
|
DiffEditor::DiffEditorDocument *diffEditorDocument = DiffEditor::DiffEditorManager::find(documentId);
|
||||||
if (!diffEditor) {
|
if (!diffEditorDocument)
|
||||||
newEditor = diffEditor = createDiffEditor(propertyName,
|
newDocument = diffEditorDocument = createDiffEditor(documentId, sourceFile, title);
|
||||||
sourceFile,
|
|
||||||
sourceFile,
|
Core::EditorManager::activateEditorForDocument(diffEditorDocument);
|
||||||
title,
|
|
||||||
DiffEditor::Constants::DIFF_EDITOR_ID);
|
GitDiffHandler *handler = new GitDiffHandler(diffEditorDocument->controller(),
|
||||||
}
|
|
||||||
GitDiffHandler *handler = new GitDiffHandler(diffEditor,
|
|
||||||
gitBinaryPath(),
|
gitBinaryPath(),
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
processEnvironment(),
|
processEnvironment(),
|
||||||
@@ -1248,7 +1298,7 @@ void GitClient::diff(const QString &workingDirectory, const QString &fileName)
|
|||||||
propertyName,
|
propertyName,
|
||||||
sourceFile,
|
sourceFile,
|
||||||
argWidget);
|
argWidget);
|
||||||
newEditor = vcsEditor->editor();
|
newDocument = vcsEditor->editor()->document();
|
||||||
connect(vcsEditor, SIGNAL(diffChunkApplied(VcsBase::DiffChunk)),
|
connect(vcsEditor, SIGNAL(diffChunkApplied(VcsBase::DiffChunk)),
|
||||||
argWidget, SLOT(executeCommand()));
|
argWidget, SLOT(executeCommand()));
|
||||||
connect(vcsEditor, SIGNAL(diffChunkReverted(VcsBase::DiffChunk)),
|
connect(vcsEditor, SIGNAL(diffChunkReverted(VcsBase::DiffChunk)),
|
||||||
@@ -1265,8 +1315,8 @@ void GitClient::diff(const QString &workingDirectory, const QString &fileName)
|
|||||||
cmdArgs << QLatin1String("--") << fileName;
|
cmdArgs << QLatin1String("--") << fileName;
|
||||||
executeGit(workingDirectory, cmdArgs, vcsEditor, false, diffExecutionFlags());
|
executeGit(workingDirectory, cmdArgs, vcsEditor, false, diffExecutionFlags());
|
||||||
}
|
}
|
||||||
if (newEditor) {
|
if (newDocument) {
|
||||||
GitDiffSwitcher *switcher = new GitDiffSwitcher(newEditor, this);
|
GitDiffSwitcher *switcher = new GitDiffSwitcher(newDocument, this);
|
||||||
switcher->setWorkingDirectory(workingDirectory);
|
switcher->setWorkingDirectory(workingDirectory);
|
||||||
switcher->setDiffType(GitDiffSwitcher::DiffFile);
|
switcher->setDiffType(GitDiffSwitcher::DiffFile);
|
||||||
switcher->setFileName(fileName);
|
switcher->setFileName(fileName);
|
||||||
@@ -1278,19 +1328,16 @@ void GitClient::diffBranch(const QString &workingDirectory,
|
|||||||
const QString &branchName)
|
const QString &branchName)
|
||||||
{
|
{
|
||||||
const QString title = tr("Git Diff Branch \"%1\"").arg(branchName);
|
const QString title = tr("Git Diff Branch \"%1\"").arg(branchName);
|
||||||
Core::IEditor *newEditor = 0;
|
Core::IDocument *newDocument = 0;
|
||||||
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
||||||
const char *propertyName = "sideBySideBranchName";
|
const QString documentId = QLatin1String("sideBySideBranchName") + branchName;
|
||||||
DiffEditor::DiffEditor *diffEditor = findExistingDiffEditor(propertyName, branchName);
|
DiffEditor::DiffEditorDocument *diffEditorDocument = DiffEditor::DiffEditorManager::find(documentId);
|
||||||
if (!diffEditor) {
|
if (!diffEditorDocument)
|
||||||
newEditor = diffEditor = createDiffEditor(propertyName,
|
newDocument = diffEditorDocument = createDiffEditor(documentId, workingDirectory, title);
|
||||||
branchName,
|
|
||||||
workingDirectory,
|
|
||||||
title,
|
|
||||||
DiffEditor::Constants::DIFF_EDITOR_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
GitDiffHandler *handler = new GitDiffHandler(diffEditor,
|
Core::EditorManager::activateEditorForDocument(diffEditorDocument);
|
||||||
|
|
||||||
|
GitDiffHandler *handler = new GitDiffHandler(diffEditorDocument->controller(),
|
||||||
gitBinaryPath(),
|
gitBinaryPath(),
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
processEnvironment(),
|
processEnvironment(),
|
||||||
@@ -1312,7 +1359,7 @@ void GitClient::diffBranch(const QString &workingDirectory,
|
|||||||
workingDirectory,
|
workingDirectory,
|
||||||
diffArgs,
|
diffArgs,
|
||||||
branchName));
|
branchName));
|
||||||
newEditor = vcsEditor->editor();
|
newDocument = vcsEditor->editor()->document();
|
||||||
}
|
}
|
||||||
vcsEditor->setWorkingDirectory(workingDirectory);
|
vcsEditor->setWorkingDirectory(workingDirectory);
|
||||||
|
|
||||||
@@ -1324,8 +1371,8 @@ void GitClient::diffBranch(const QString &workingDirectory,
|
|||||||
|
|
||||||
executeGit(workingDirectory, cmdArgs, vcsEditor, false, diffExecutionFlags());
|
executeGit(workingDirectory, cmdArgs, vcsEditor, false, diffExecutionFlags());
|
||||||
}
|
}
|
||||||
if (newEditor) {
|
if (newDocument) {
|
||||||
GitDiffSwitcher *switcher = new GitDiffSwitcher(newEditor, this);
|
GitDiffSwitcher *switcher = new GitDiffSwitcher(newDocument, this);
|
||||||
switcher->setWorkingDirectory(workingDirectory);
|
switcher->setWorkingDirectory(workingDirectory);
|
||||||
switcher->setDiffType(GitDiffSwitcher::DiffBranch);
|
switcher->setDiffType(GitDiffSwitcher::DiffBranch);
|
||||||
switcher->setBaseArguments(diffArgs);
|
switcher->setBaseArguments(diffArgs);
|
||||||
@@ -1436,20 +1483,18 @@ void GitClient::show(const QString &source, const QString &id,
|
|||||||
const QString title = tr("Git Show \"%1\"").arg(name.isEmpty() ? id : name);
|
const QString title = tr("Git Show \"%1\"").arg(name.isEmpty() ? id : name);
|
||||||
const QFileInfo sourceFi(source);
|
const QFileInfo sourceFi(source);
|
||||||
const QString workingDirectory = sourceFi.isDir() ? sourceFi.absoluteFilePath() : sourceFi.absolutePath();
|
const QString workingDirectory = sourceFi.isDir() ? sourceFi.absoluteFilePath() : sourceFi.absolutePath();
|
||||||
Core::IEditor *newEditor = 0;
|
Core::IDocument *newDocument = 0;
|
||||||
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
||||||
const char *propertyName = "sideBySideShow";
|
const QString documentId = QLatin1String("sideBySideShow") + id;
|
||||||
DiffEditor::DiffEditor *diffEditor = findExistingDiffEditor(propertyName, id);
|
DiffEditor::DiffEditorDocument *diffEditorDocument = DiffEditor::DiffEditorManager::find(documentId);
|
||||||
if (!diffEditor) {
|
if (!diffEditorDocument)
|
||||||
newEditor = diffEditor = createDiffEditor(propertyName,
|
newDocument = diffEditorDocument = createDiffEditor(documentId, source, title);
|
||||||
id,
|
|
||||||
source,
|
|
||||||
title,
|
|
||||||
DiffEditor::Constants::DIFF_EDITOR_ID);
|
|
||||||
diffEditor->setDescriptionEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
GitDiffHandler *handler = new GitDiffHandler(diffEditor,
|
diffEditorDocument->controller()->setDescriptionEnabled(true);
|
||||||
|
|
||||||
|
Core::EditorManager::activateEditorForDocument(diffEditorDocument);
|
||||||
|
|
||||||
|
GitDiffHandler *handler = new GitDiffHandler(diffEditorDocument->controller(),
|
||||||
gitBinaryPath(),
|
gitBinaryPath(),
|
||||||
findRepositoryForDirectory(workingDirectory),
|
findRepositoryForDirectory(workingDirectory),
|
||||||
processEnvironment(),
|
processEnvironment(),
|
||||||
@@ -1470,7 +1515,7 @@ void GitClient::show(const QString &source, const QString &id,
|
|||||||
source,
|
source,
|
||||||
args,
|
args,
|
||||||
id));
|
id));
|
||||||
newEditor = vcsEditor->editor();
|
newDocument = vcsEditor->editor()->document();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
@@ -1483,8 +1528,8 @@ void GitClient::show(const QString &source, const QString &id,
|
|||||||
vcsEditor->setWorkingDirectory(workingDirectory);
|
vcsEditor->setWorkingDirectory(workingDirectory);
|
||||||
executeGit(workingDirectory, arguments, vcsEditor);
|
executeGit(workingDirectory, arguments, vcsEditor);
|
||||||
}
|
}
|
||||||
if (newEditor) {
|
if (newDocument) {
|
||||||
GitDiffSwitcher *switcher = new GitDiffSwitcher(newEditor, this);
|
GitDiffSwitcher *switcher = new GitDiffSwitcher(newDocument, this);
|
||||||
switcher->setDiffType(GitDiffSwitcher::DiffShow);
|
switcher->setDiffType(GitDiffSwitcher::DiffShow);
|
||||||
switcher->setFileName(source);
|
switcher->setFileName(source);
|
||||||
switcher->setBaseArguments(args);
|
switcher->setBaseArguments(args);
|
||||||
|
|||||||
@@ -56,11 +56,9 @@ namespace VcsBase {
|
|||||||
class VcsBaseEditorParameterWidget;
|
class VcsBaseEditorParameterWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils { struct SynchronousProcessResponse; }
|
||||||
struct SynchronousProcessResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace DiffEditor { class DiffEditor; }
|
namespace DiffEditor { class DiffEditorDocument; }
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -351,8 +349,6 @@ 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::DiffEditor *findExistingDiffEditor(const char *registerDynamicProperty,
|
|
||||||
const QString &dynamicPropertyValue) const;
|
|
||||||
|
|
||||||
enum CodecType { CodecSource, CodecLogOutput, CodecNone };
|
enum CodecType { CodecSource, CodecLogOutput, CodecNone };
|
||||||
VcsBase::VcsBaseEditorWidget *createVcsEditor(const Core::Id &kind,
|
VcsBase::VcsBaseEditorWidget *createVcsEditor(const Core::Id &kind,
|
||||||
@@ -362,11 +358,9 @@ private:
|
|||||||
const char *registerDynamicProperty,
|
const char *registerDynamicProperty,
|
||||||
const QString &dynamicPropertyValue,
|
const QString &dynamicPropertyValue,
|
||||||
VcsBase::VcsBaseEditorParameterWidget *configWidget) const;
|
VcsBase::VcsBaseEditorParameterWidget *configWidget) const;
|
||||||
DiffEditor::DiffEditor *createDiffEditor(const char *registerDynamicProperty,
|
DiffEditor::DiffEditorDocument *createDiffEditor(const QString documentId,
|
||||||
const QString &dynamicPropertyValue,
|
|
||||||
const QString &source,
|
const QString &source,
|
||||||
const QString &titlePattern,
|
const QString &title) const;
|
||||||
const Core::Id editorId) const;
|
|
||||||
|
|
||||||
VcsBase::Command *createCommand(const QString &workingDirectory,
|
VcsBase::Command *createCommand(const QString &workingDirectory,
|
||||||
VcsBase::VcsBaseEditorWidget* editor = 0,
|
VcsBase::VcsBaseEditorWidget* editor = 0,
|
||||||
|
|||||||
@@ -737,12 +737,12 @@ void VcsBaseEditorWidget::setForceReadOnly(bool b)
|
|||||||
|
|
||||||
QString VcsBaseEditorWidget::source() const
|
QString VcsBaseEditorWidget::source() const
|
||||||
{
|
{
|
||||||
return VcsBasePlugin::source(editor());
|
return VcsBasePlugin::source(baseTextDocument());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsBaseEditorWidget::setSource(const QString &source)
|
void VcsBaseEditorWidget::setSource(const QString &source)
|
||||||
{
|
{
|
||||||
VcsBasePlugin::setSource(editor(), source);
|
VcsBasePlugin::setSource(baseTextDocument(), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VcsBaseEditorWidget::annotateRevisionTextFormat() const
|
QString VcsBaseEditorWidget::annotateRevisionTextFormat() const
|
||||||
|
|||||||
@@ -238,11 +238,7 @@ void StateListener::slotStateChanged()
|
|||||||
} else {
|
} else {
|
||||||
state.currentFile = currentDocument->filePath();
|
state.currentFile = currentDocument->filePath();
|
||||||
if (state.currentFile.isEmpty()) {
|
if (state.currentFile.isEmpty()) {
|
||||||
const QList<Core::IEditor *> editors =
|
state.currentFile = VcsBasePlugin::source(currentDocument);
|
||||||
Core::EditorManager::documentModel()->editorsForDocument(currentDocument);
|
|
||||||
if (!editors.isEmpty()) {
|
|
||||||
state.currentFile = VcsBasePlugin::source(editors.first());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QScopedPointer<QFileInfo> currentFileInfo; // Instantiate QFileInfo only once if required.
|
QScopedPointer<QFileInfo> currentFileInfo; // Instantiate QFileInfo only once if required.
|
||||||
@@ -750,12 +746,12 @@ bool VcsBasePlugin::isSshPromptConfigured()
|
|||||||
|
|
||||||
static const char SOURCE_PROPERTY[] = "qtcreator_source";
|
static const char SOURCE_PROPERTY[] = "qtcreator_source";
|
||||||
|
|
||||||
void VcsBasePlugin::setSource(Core::IEditor *editor, const QString &source)
|
void VcsBasePlugin::setSource(Core::IDocument *editor, const QString &source)
|
||||||
{
|
{
|
||||||
editor->setProperty(SOURCE_PROPERTY, source);
|
editor->setProperty(SOURCE_PROPERTY, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VcsBasePlugin::source(Core::IEditor *editor)
|
QString VcsBasePlugin::source(Core::IDocument *editor)
|
||||||
{
|
{
|
||||||
return editor->property(SOURCE_PROPERTY).toString();
|
return editor->property(SOURCE_PROPERTY).toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace Utils { struct SynchronousProcessResponse; }
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
class IVersionControl;
|
class IVersionControl;
|
||||||
class Id;
|
class Id;
|
||||||
class IEditor;
|
class IDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace VcsBase {
|
namespace VcsBase {
|
||||||
@@ -157,9 +157,9 @@ public:
|
|||||||
static bool isSshPromptConfigured();
|
static bool isSshPromptConfigured();
|
||||||
|
|
||||||
// Sets the source of editor contents, can be directory or file.
|
// Sets the source of editor contents, can be directory or file.
|
||||||
static void setSource(Core::IEditor *editor, const QString &source);
|
static void setSource(Core::IDocument *document, const QString &source);
|
||||||
// Returns the source of editor contents.
|
// Returns the source of editor contents.
|
||||||
static QString source(Core::IEditor *editor);
|
static QString source(Core::IDocument *document);
|
||||||
|
|
||||||
// Convenience to synchronously run VCS commands
|
// Convenience to synchronously run VCS commands
|
||||||
enum RunVcsFlags {
|
enum RunVcsFlags {
|
||||||
|
|||||||
Reference in New Issue
Block a user