forked from qt-creator/qt-creator
DiffEditor: Make DiffEditorDocument internal
Only expose Core::IDocument and keep DiffEditorDocument internal to the DiffEditor plugin. Change-Id: If39b82e2f20d40a65284503b4d4fd8dad919ad3a Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -201,6 +201,8 @@ void DescriptionEditorWidget::handleCurrentContents()
|
|||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
|
using namespace Internal;
|
||||||
|
|
||||||
///////////////////////////////// DiffEditor //////////////////////////////////
|
///////////////////////////////// DiffEditor //////////////////////////////////
|
||||||
|
|
||||||
DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
|
DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
|
||||||
@@ -221,7 +223,7 @@ DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
|
|||||||
|
|
||||||
QSplitter *splitter = new Core::MiniSplitter(Qt::Vertical);
|
QSplitter *splitter = new Core::MiniSplitter(Qt::Vertical);
|
||||||
|
|
||||||
m_descriptionWidget = new Internal::DescriptionEditorWidget(splitter);
|
m_descriptionWidget = new DescriptionEditorWidget(splitter);
|
||||||
m_descriptionWidget->setReadOnly(true);
|
m_descriptionWidget->setReadOnly(true);
|
||||||
splitter->addWidget(m_descriptionWidget);
|
splitter->addWidget(m_descriptionWidget);
|
||||||
|
|
||||||
@@ -240,7 +242,7 @@ DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
|
|||||||
DiffEditorController *control = controller();
|
DiffEditorController *control = controller();
|
||||||
m_guiController = new DiffEditorGuiController(control, this);
|
m_guiController = new DiffEditorGuiController(control, this);
|
||||||
|
|
||||||
connect(m_descriptionWidget, &Internal::DescriptionEditorWidget::requestBranchList,
|
connect(m_descriptionWidget, &DescriptionEditorWidget::requestBranchList,
|
||||||
control, &DiffEditorController::expandBranchesRequested);
|
control, &DiffEditorController::expandBranchesRequested);
|
||||||
connect(control, &DiffEditorController::cleared, this, &DiffEditor::slotCleared);
|
connect(control, &DiffEditorController::cleared, this, &DiffEditor::slotCleared);
|
||||||
connect(control, &DiffEditorController::diffFilesChanged,
|
connect(control, &DiffEditorController::diffFilesChanged,
|
||||||
|
@@ -48,9 +48,11 @@ namespace TextEditor { class TextEditorWidget; }
|
|||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
namespace Internal { class DescriptionEditorWidget; }
|
namespace Internal {
|
||||||
|
class DescriptionEditorWidget;
|
||||||
class DiffEditorDocument;
|
class DiffEditorDocument;
|
||||||
|
} // namespace Internal
|
||||||
|
|
||||||
class DiffEditorGuiController;
|
class DiffEditorGuiController;
|
||||||
class SideBySideDiffEditorWidget;
|
class SideBySideDiffEditorWidget;
|
||||||
class UnifiedDiffEditorWidget;
|
class UnifiedDiffEditorWidget;
|
||||||
@@ -60,7 +62,7 @@ class DIFFEDITOR_EXPORT DiffEditor : public Core::IEditor
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DiffEditor(const QSharedPointer<DiffEditorDocument> &doc);
|
DiffEditor(const QSharedPointer<Internal::DiffEditorDocument> &doc);
|
||||||
~DiffEditor();
|
~DiffEditor();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -96,7 +98,7 @@ private:
|
|||||||
QWidget *readCurrentDiffEditorSetting();
|
QWidget *readCurrentDiffEditorSetting();
|
||||||
void writeCurrentDiffEditorSetting(QWidget *currentEditor);
|
void writeCurrentDiffEditorSetting(QWidget *currentEditor);
|
||||||
|
|
||||||
QSharedPointer<DiffEditorDocument> m_document;
|
QSharedPointer<Internal::DiffEditorDocument> m_document;
|
||||||
Internal::DescriptionEditorWidget *m_descriptionWidget;
|
Internal::DescriptionEditorWidget *m_descriptionWidget;
|
||||||
QStackedWidget *m_stackedWidget;
|
QStackedWidget *m_stackedWidget;
|
||||||
SideBySideDiffEditorWidget *m_sideBySideEditor;
|
SideBySideDiffEditorWidget *m_sideBySideEditor;
|
||||||
|
@@ -43,6 +43,7 @@
|
|||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
DiffEditorDocument::DiffEditorDocument() :
|
DiffEditorDocument::DiffEditorDocument() :
|
||||||
Core::BaseTextDocument(),
|
Core::BaseTextDocument(),
|
||||||
@@ -156,4 +157,5 @@ QString DiffEditorDocument::plainText() const
|
|||||||
return m_controller->contents();
|
return m_controller->contents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
@@ -31,15 +31,15 @@
|
|||||||
#ifndef DIFFEDITORDOCUMENT_H
|
#ifndef DIFFEDITORDOCUMENT_H
|
||||||
#define DIFFEDITORDOCUMENT_H
|
#define DIFFEDITORDOCUMENT_H
|
||||||
|
|
||||||
#include "diffeditor_global.h"
|
|
||||||
|
|
||||||
#include <coreplugin/textdocument.h>
|
#include <coreplugin/textdocument.h>
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
class DiffEditorController;
|
class DiffEditorController;
|
||||||
|
|
||||||
class DIFFEDITOR_EXPORT DiffEditorDocument : public Core::BaseTextDocument
|
namespace Internal {
|
||||||
|
|
||||||
|
class DiffEditorDocument : public Core::BaseTextDocument
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString plainText READ plainText STORED false) // For access by code pasters
|
Q_PROPERTY(QString plainText READ plainText STORED false) // For access by code pasters
|
||||||
@@ -64,6 +64,7 @@ private:
|
|||||||
DiffEditorController *const m_controller;
|
DiffEditorController *const m_controller;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
|
||||||
#endif // DIFFEDITORDOCUMENT_H
|
#endif // DIFFEDITORDOCUMENT_H
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "diffeditormanager.h"
|
#include "diffeditormanager.h"
|
||||||
#include "diffeditor.h"
|
#include "diffeditor.h"
|
||||||
|
#include "diffeditordocument.h"
|
||||||
#include "diffeditorconstants.h"
|
#include "diffeditorconstants.h"
|
||||||
#include "diffeditordocument.h"
|
#include "diffeditordocument.h"
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -39,6 +40,8 @@
|
|||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
|
using namespace Internal;
|
||||||
|
|
||||||
static DiffEditorManager *m_instance = 0;
|
static DiffEditorManager *m_instance = 0;
|
||||||
|
|
||||||
DiffEditorManager::DiffEditorManager(QObject *parent)
|
DiffEditorManager::DiffEditorManager(QObject *parent)
|
||||||
@@ -70,26 +73,19 @@ void DiffEditorManager::slotEditorsClosed(const QList<Core::IEditor *> &editors)
|
|||||||
QMapIterator<Core::IDocument *, int> it(editorsForDocument);
|
QMapIterator<Core::IDocument *, int> it(editorsForDocument);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
if (Core::DocumentModel::editorsForDocument(it.key()).count() == 0) { // no other editors use that document
|
if (Core::DocumentModel::editorsForDocument(it.key()).count() == 0) // no other editors use that document
|
||||||
DiffEditorDocument *document
|
removeDocument(it.key());
|
||||||
= 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)
|
Core::IDocument *DiffEditorManager::find(const QString &vcsId)
|
||||||
{
|
{
|
||||||
return m_instance->idToDocument.value(documentId);
|
return m_instance->m_idToDocument.value(vcsId);
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditorDocument *DiffEditorManager::findOrCreate(const QString &documentId, const QString &displayName)
|
Core::IDocument *DiffEditorManager::findOrCreate(const QString &vcsId, const QString &displayName)
|
||||||
{
|
{
|
||||||
DiffEditorDocument *document = find(documentId);
|
auto document = static_cast<Internal::DiffEditorDocument *>(find(vcsId));
|
||||||
if (document)
|
if (document)
|
||||||
return document;
|
return document;
|
||||||
|
|
||||||
@@ -99,25 +95,32 @@ DiffEditorDocument *DiffEditorManager::findOrCreate(const QString &documentId, c
|
|||||||
0, msgWait.toUtf8()));
|
0, msgWait.toUtf8()));
|
||||||
QTC_ASSERT(diffEditor, return 0);
|
QTC_ASSERT(diffEditor, return 0);
|
||||||
|
|
||||||
document = qobject_cast<DiffEditorDocument *>(diffEditor->document());
|
document = qobject_cast<Internal::DiffEditorDocument *>(diffEditor->document());
|
||||||
QTC_ASSERT(diffEditor, return 0);
|
QTC_ASSERT(diffEditor, return 0);
|
||||||
|
|
||||||
document->setDisplayName(displayName);
|
document->setDisplayName(displayName);
|
||||||
|
|
||||||
m_instance->idToDocument.insert(documentId, document);
|
m_instance->m_idToDocument.insert(vcsId, document);
|
||||||
m_instance->documentToId.insert(document, documentId);
|
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorManager::removeDocument(DiffEditorDocument *document)
|
DiffEditorController *DiffEditorManager::controller(Core::IDocument *document)
|
||||||
{
|
{
|
||||||
if (!m_instance->documentToId.contains(document))
|
auto doc = qobject_cast<DiffEditorDocument *>(document);
|
||||||
return;
|
return doc ? doc->controller() : 0;
|
||||||
const QString documentId = m_instance->documentToId.value(document);
|
|
||||||
m_instance->documentToId.remove(document);
|
|
||||||
m_instance->idToDocument.remove(documentId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiffEditorManager::removeDocument(Core::IDocument *document)
|
||||||
|
{
|
||||||
|
DiffEditorDocument *doc = qobject_cast<DiffEditorDocument *>(document);
|
||||||
|
QTC_ASSERT(doc, return);
|
||||||
|
for (auto it = m_instance->m_idToDocument.constBegin(); it != m_instance->m_idToDocument.constEnd(); ++it) {
|
||||||
|
if (it.value() == doc) {
|
||||||
|
m_instance->m_idToDocument.remove(it.key());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
@@ -38,9 +38,13 @@
|
|||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
|
namespace Core { class IDocument; }
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
class DiffEditorDocument;
|
class DiffEditorController;
|
||||||
|
|
||||||
|
namespace Internal { class DiffEditorDocument; }
|
||||||
|
|
||||||
class DIFFEDITOR_EXPORT DiffEditorManager : public QObject
|
class DIFFEDITOR_EXPORT DiffEditorManager : public QObject
|
||||||
{
|
{
|
||||||
@@ -49,16 +53,17 @@ public:
|
|||||||
explicit DiffEditorManager(QObject *parent);
|
explicit DiffEditorManager(QObject *parent);
|
||||||
virtual ~DiffEditorManager();
|
virtual ~DiffEditorManager();
|
||||||
|
|
||||||
static DiffEditorDocument *find(const QString &documentId);
|
static Core::IDocument *find(const QString &vcsId);
|
||||||
static DiffEditorDocument *findOrCreate(const QString &documentId, const QString &displayName);
|
static Core::IDocument *findOrCreate(const QString &vcsId, const QString &displayName);
|
||||||
static void removeDocument(DiffEditorDocument *document);
|
static DiffEditorController *controller(Core::IDocument *document);
|
||||||
|
|
||||||
|
static void removeDocument(Core::IDocument *document);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotEditorsClosed(const QList<Core::IEditor *> &editors);
|
void slotEditorsClosed(const QList<Core::IEditor *> &editors);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString, DiffEditorDocument *> idToDocument;
|
QMap<QString, Internal::DiffEditorDocument *> m_idToDocument;
|
||||||
QMap<DiffEditorDocument *, QString> documentToId;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
@@ -47,6 +47,8 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -195,11 +197,12 @@ void DiffEditorPlugin::diff()
|
|||||||
const QString documentId = QLatin1String("Diff ") + fileName1
|
const QString documentId = QLatin1String("Diff ") + fileName1
|
||||||
+ QLatin1String(", ") + fileName2;
|
+ QLatin1String(", ") + fileName2;
|
||||||
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
||||||
DiffEditorDocument * const document = DiffEditorManager::findOrCreate(documentId, title);
|
Core::IDocument *const document = DiffEditorManager::findOrCreate(documentId, title);
|
||||||
if (!document)
|
if (!document)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DiffEditorController *controller = document->controller();
|
DiffEditorController *controller = DiffEditorManager::controller(document);
|
||||||
|
QTC_ASSERT(controller, return);
|
||||||
if (!controller->reloader()) {
|
if (!controller->reloader()) {
|
||||||
SimpleDiffEditorReloader *reloader =
|
SimpleDiffEditorReloader *reloader =
|
||||||
new SimpleDiffEditorReloader(fileName1, fileName2);
|
new SimpleDiffEditorReloader(fileName1, fileName2);
|
||||||
@@ -208,7 +211,7 @@ void DiffEditorPlugin::diff()
|
|||||||
|
|
||||||
Core::EditorManager::activateEditorForDocument(document);
|
Core::EditorManager::activateEditorForDocument(document);
|
||||||
|
|
||||||
document->controller()->requestReload();
|
controller->requestReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -63,7 +63,6 @@
|
|||||||
|
|
||||||
#include <diffeditor/diffeditorconstants.h>
|
#include <diffeditor/diffeditorconstants.h>
|
||||||
#include <diffeditor/diffeditorcontroller.h>
|
#include <diffeditor/diffeditorcontroller.h>
|
||||||
#include <diffeditor/diffeditordocument.h>
|
|
||||||
#include <diffeditor/diffeditormanager.h>
|
#include <diffeditor/diffeditormanager.h>
|
||||||
#include <diffeditor/diffeditorreloader.h>
|
#include <diffeditor/diffeditorreloader.h>
|
||||||
#include <diffeditor/diffutils.h>
|
#include <diffeditor/diffutils.h>
|
||||||
@@ -745,14 +744,14 @@ GitDiffEditorReloader *GitClient::findOrCreateDiffEditor(const QString &document
|
|||||||
{
|
{
|
||||||
DiffEditorController *controller = 0;
|
DiffEditorController *controller = 0;
|
||||||
GitDiffEditorReloader *reloader = 0;
|
GitDiffEditorReloader *reloader = 0;
|
||||||
DiffEditorDocument *diffEditorDocument = DiffEditorManager::find(documentId);
|
Core::IDocument *document = DiffEditorManager::find(documentId);
|
||||||
if (diffEditorDocument) {
|
if (document) {
|
||||||
controller = diffEditorDocument->controller();
|
controller = DiffEditorManager::controller(document);
|
||||||
reloader = static_cast<GitDiffEditorReloader *>(controller->reloader());
|
reloader = static_cast<GitDiffEditorReloader *>(controller->reloader());
|
||||||
} else {
|
} else {
|
||||||
diffEditorDocument = DiffEditorManager::findOrCreate(documentId, title);
|
document = DiffEditorManager::findOrCreate(documentId, title);
|
||||||
QTC_ASSERT(diffEditorDocument, return 0);
|
QTC_ASSERT(document, return 0);
|
||||||
controller = diffEditorDocument->controller();
|
controller = DiffEditorManager::controller(document);
|
||||||
|
|
||||||
connect(controller, &DiffEditorController::chunkActionsRequested,
|
connect(controller, &DiffEditorController::chunkActionsRequested,
|
||||||
this, &GitClient::slotChunkActionsRequested, Qt::DirectConnection);
|
this, &GitClient::slotChunkActionsRequested, Qt::DirectConnection);
|
||||||
@@ -766,8 +765,8 @@ GitDiffEditorReloader *GitClient::findOrCreateDiffEditor(const QString &document
|
|||||||
}
|
}
|
||||||
QTC_ASSERT(reloader, return 0);
|
QTC_ASSERT(reloader, return 0);
|
||||||
|
|
||||||
VcsBasePlugin::setSource(diffEditorDocument, source);
|
VcsBasePlugin::setSource(document, source);
|
||||||
EditorManager::activateEditorForDocument(diffEditorDocument);
|
EditorManager::activateEditorForDocument(document);
|
||||||
return reloader;
|
return reloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,7 +41,6 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/synchronousprocess.h>
|
#include <utils/synchronousprocess.h>
|
||||||
#include <diffeditor/diffeditorcontroller.h>
|
#include <diffeditor/diffeditorcontroller.h>
|
||||||
#include <diffeditor/diffeditordocument.h>
|
|
||||||
#include <diffeditor/diffeditormanager.h>
|
#include <diffeditor/diffeditormanager.h>
|
||||||
#include <diffeditor/diffeditorreloader.h>
|
#include <diffeditor/diffeditorreloader.h>
|
||||||
#include <diffeditor/diffutils.h>
|
#include <diffeditor/diffutils.h>
|
||||||
@@ -321,14 +320,15 @@ SubversionDiffEditorReloader *SubversionClient::findOrCreateDiffEditor(const QSt
|
|||||||
{
|
{
|
||||||
DiffEditor::DiffEditorController *controller = 0;
|
DiffEditor::DiffEditorController *controller = 0;
|
||||||
SubversionDiffEditorReloader *reloader = 0;
|
SubversionDiffEditorReloader *reloader = 0;
|
||||||
DiffEditor::DiffEditorDocument *diffEditorDocument = DiffEditor::DiffEditorManager::find(documentId);
|
Core::IDocument *document = DiffEditor::DiffEditorManager::find(documentId);
|
||||||
if (diffEditorDocument) {
|
if (document) {
|
||||||
controller = diffEditorDocument->controller();
|
controller = DiffEditor::DiffEditorManager::controller(document);
|
||||||
reloader = static_cast<SubversionDiffEditorReloader *>(controller->reloader());
|
reloader = static_cast<SubversionDiffEditorReloader *>(controller->reloader());
|
||||||
} else {
|
} else {
|
||||||
diffEditorDocument = DiffEditor::DiffEditorManager::findOrCreate(documentId, title);
|
document = DiffEditor::DiffEditorManager::findOrCreate(documentId, title);
|
||||||
QTC_ASSERT(diffEditorDocument, return 0);
|
QTC_ASSERT(document, return 0);
|
||||||
controller = diffEditorDocument->controller();
|
controller = DiffEditor::DiffEditorManager::controller(document);
|
||||||
|
QTC_ASSERT(controller, return 0);
|
||||||
|
|
||||||
reloader = new SubversionDiffEditorReloader(this);
|
reloader = new SubversionDiffEditorReloader(this);
|
||||||
controller->setReloader(reloader);
|
controller->setReloader(reloader);
|
||||||
@@ -337,7 +337,7 @@ SubversionDiffEditorReloader *SubversionClient::findOrCreateDiffEditor(const QSt
|
|||||||
QTC_ASSERT(reloader, return 0);
|
QTC_ASSERT(reloader, return 0);
|
||||||
|
|
||||||
reloader->setWorkingDirectory(workingDirectory);
|
reloader->setWorkingDirectory(workingDirectory);
|
||||||
VcsBasePlugin::setSource(diffEditorDocument, source);
|
VcsBasePlugin::setSource(document, source);
|
||||||
|
|
||||||
return reloader;
|
return reloader;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user