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