forked from qt-creator/qt-creator
DiffEditorManager simplify
by using EditorManager::openEditorWithContents Change-Id: I2850648bff0f5b8f01254b9c7ce9539c1262f576 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -7,7 +7,6 @@ HEADERS += diffeditor_global.h \
|
||||
diffeditorcontroller.h \
|
||||
diffeditordocument.h \
|
||||
diffeditorfactory.h \
|
||||
diffeditormanager.h \
|
||||
diffeditorplugin.h \
|
||||
differ.h \
|
||||
diffutils.h \
|
||||
@@ -20,7 +19,6 @@ SOURCES += diffeditor.cpp \
|
||||
diffeditorcontroller.cpp \
|
||||
diffeditordocument.cpp \
|
||||
diffeditorfactory.cpp \
|
||||
diffeditormanager.cpp \
|
||||
diffeditorplugin.cpp \
|
||||
differ.cpp \
|
||||
diffutils.cpp \
|
||||
|
@@ -21,8 +21,6 @@ QtcPlugin {
|
||||
"diffeditordocument.h",
|
||||
"diffeditorfactory.cpp",
|
||||
"diffeditorfactory.h",
|
||||
"diffeditormanager.cpp",
|
||||
"diffeditormanager.h",
|
||||
"diffeditorplugin.cpp",
|
||||
"diffeditorplugin.h",
|
||||
"differ.cpp",
|
||||
|
@@ -32,6 +32,8 @@
|
||||
#include "diffeditorcontroller.h"
|
||||
#include "diffeditordocument.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -82,6 +84,21 @@ QString DiffEditorController::makePatch(bool revert, bool addPrefix) const
|
||||
return m_document->makePatch(m_diffFileIndex, m_chunkIndex, revert, addPrefix);
|
||||
}
|
||||
|
||||
Core::IDocument *DiffEditorController::findOrCreateDocument(const QString &vcsId,
|
||||
const QString &displayName)
|
||||
{
|
||||
QString preferredDisplayName = displayName;
|
||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(
|
||||
Constants::DIFF_EDITOR_ID, &preferredDisplayName, QByteArray(), vcsId);
|
||||
return editor ? editor->document() : 0;
|
||||
}
|
||||
|
||||
DiffEditorController *DiffEditorController::controller(Core::IDocument *document)
|
||||
{
|
||||
auto doc = qobject_cast<Internal::DiffEditorDocument *>(document);
|
||||
return doc ? doc->controller() : 0;
|
||||
}
|
||||
|
||||
void DiffEditorController::setDiffFiles(const QList<FileData> &diffFileList,
|
||||
const QString &workingDirectory)
|
||||
{
|
||||
|
@@ -61,6 +61,9 @@ public:
|
||||
|
||||
QString makePatch(bool revert, bool addPrefix = false) const;
|
||||
|
||||
static Core::IDocument *findOrCreateDocument(const QString &vcsId, const QString &displayName);
|
||||
static DiffEditorController *controller(Core::IDocument *document);
|
||||
|
||||
public slots:
|
||||
void informationForCommitReceived(const QString &output);
|
||||
|
||||
|
@@ -31,7 +31,6 @@
|
||||
#include "diffeditordocument.h"
|
||||
#include "diffeditorconstants.h"
|
||||
#include "diffeditorcontroller.h"
|
||||
#include "diffeditormanager.h"
|
||||
#include "diffutils.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
@@ -63,11 +62,6 @@ DiffEditorDocument::DiffEditorDocument() :
|
||||
setTemporary(true);
|
||||
}
|
||||
|
||||
DiffEditorDocument::~DiffEditorDocument()
|
||||
{
|
||||
DiffEditorManager::removeDocument(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a controller for a document
|
||||
* @param controller The controller to set.
|
||||
@@ -214,8 +208,6 @@ bool DiffEditorDocument::save(QString *errorString, const QString &fileName, boo
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
DiffEditorManager::removeDocument(this);
|
||||
|
||||
setController(0);
|
||||
setDescription(QString());
|
||||
|
||||
|
@@ -49,7 +49,6 @@ class DiffEditorDocument : public Core::BaseTextDocument
|
||||
Q_PROPERTY(QString plainText READ plainText STORED false) // For access by code pasters
|
||||
public:
|
||||
DiffEditorDocument();
|
||||
~DiffEditorDocument();
|
||||
|
||||
DiffEditorController *controller() const;
|
||||
|
||||
|
@@ -1,106 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing
|
||||
**
|
||||
** 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 The Qt Company. For licensing terms and
|
||||
** conditions see http://www.qt.io/terms-conditions. For further information
|
||||
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, The Qt Company gives you certain additional
|
||||
** rights. These rights are described in The Qt Company 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/editormanager/documentmodel.h>
|
||||
#include <coreplugin/id.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
static DiffEditorManager *m_instance = 0;
|
||||
|
||||
DiffEditorManager::DiffEditorManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
QTC_ASSERT(!m_instance, return);
|
||||
m_instance = this;
|
||||
}
|
||||
|
||||
DiffEditorManager::~DiffEditorManager()
|
||||
{
|
||||
m_instance = 0;
|
||||
}
|
||||
|
||||
Core::IDocument *DiffEditorManager::find(const QString &vcsId)
|
||||
{
|
||||
Core::IDocument *document = m_instance->m_idToDocument.value(vcsId);
|
||||
QTC_ASSERT(!document || document->isTemporary(), return 0);
|
||||
return document;
|
||||
}
|
||||
|
||||
Core::IDocument *DiffEditorManager::findOrCreate(const QString &vcsId, const QString &displayName)
|
||||
{
|
||||
auto document = static_cast<Internal::DiffEditorDocument *>(find(vcsId));
|
||||
if (document)
|
||||
return document;
|
||||
|
||||
DiffEditor *diffEditor = qobject_cast<DiffEditor *>(
|
||||
Core::EditorManager::openEditorWithContents(Constants::DIFF_EDITOR_ID, 0));
|
||||
QTC_ASSERT(diffEditor, return 0);
|
||||
|
||||
document = qobject_cast<Internal::DiffEditorDocument *>(diffEditor->document());
|
||||
QTC_ASSERT(document, return 0);
|
||||
|
||||
document->setPreferredDisplayName(displayName);
|
||||
|
||||
m_instance->m_idToDocument.insert(vcsId, document);
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
DiffEditorController *DiffEditorManager::controller(Core::IDocument *document)
|
||||
{
|
||||
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
|
@@ -1,71 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing
|
||||
**
|
||||
** 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 The Qt Company. For licensing terms and
|
||||
** conditions see http://www.qt.io/terms-conditions. For further information
|
||||
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, The Qt Company gives you certain additional
|
||||
** rights. These rights are described in The Qt Company 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 <QMap>
|
||||
#include <QObject>
|
||||
|
||||
namespace Core {
|
||||
class IDocument;
|
||||
class IEditor;
|
||||
}
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
class DiffEditorController;
|
||||
|
||||
namespace Internal { class DiffEditorDocument; }
|
||||
|
||||
class DIFFEDITOR_EXPORT DiffEditorManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DiffEditorManager(QObject *parent);
|
||||
virtual ~DiffEditorManager();
|
||||
|
||||
static Core::IDocument *findOrCreate(const QString &vcsId, const QString &displayName);
|
||||
static DiffEditorController *controller(Core::IDocument *document);
|
||||
|
||||
private:
|
||||
static Core::IDocument *find(const QString &vcsId);
|
||||
static void removeDocument(Core::IDocument *document);
|
||||
|
||||
QMap<QString, Internal::DiffEditorDocument *> m_idToDocument;
|
||||
|
||||
friend class Internal::DiffEditorDocument;
|
||||
};
|
||||
|
||||
} // namespace DiffEditor
|
||||
|
||||
#endif // DIFFEDITORMANAGER_H
|
@@ -34,7 +34,6 @@
|
||||
#include "diffeditorcontroller.h"
|
||||
#include "diffeditordocument.h"
|
||||
#include "diffeditorfactory.h"
|
||||
#include "diffeditormanager.h"
|
||||
#include "differ.h"
|
||||
|
||||
#include <QAction>
|
||||
@@ -148,8 +147,6 @@ bool DiffEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
|
||||
|
||||
addAutoReleasedObject(new DiffEditorFactory(this));
|
||||
|
||||
new DiffEditorManager(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -173,15 +170,14 @@ void DiffEditorPlugin::diff()
|
||||
|
||||
const QString documentId = QLatin1String("Diff ") + fileName1 + QLatin1String(", ") + fileName2;
|
||||
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
||||
auto const document
|
||||
= qobject_cast<DiffEditorDocument *>(DiffEditorManager::findOrCreate(documentId, title));
|
||||
auto const document = qobject_cast<DiffEditorDocument *>(
|
||||
DiffEditorController::findOrCreateDocument(documentId, title));
|
||||
if (!document)
|
||||
return;
|
||||
|
||||
DiffEditorController *controller = DiffEditorManager::controller(document);
|
||||
DiffEditorController *controller = DiffEditorController::controller(document);
|
||||
if (!controller)
|
||||
controller = new FileDiffController(document, fileName1, fileName2);
|
||||
QTC_ASSERT(controller, return);
|
||||
Core::EditorManager::activateEditorForDocument(document);
|
||||
document->reload();
|
||||
}
|
||||
|
@@ -64,7 +64,6 @@
|
||||
|
||||
#include <diffeditor/diffeditorconstants.h>
|
||||
#include <diffeditor/diffeditorcontroller.h>
|
||||
#include <diffeditor/diffeditormanager.h>
|
||||
#include <diffeditor/diffutils.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -743,7 +742,7 @@ void GitClient::requestReload(const QString &documentId, const QString &source,
|
||||
const QString &title,
|
||||
std::function<DiffEditorController *(IDocument *)> factory) const
|
||||
{
|
||||
IDocument *document = DiffEditorManager::findOrCreate(documentId, title);
|
||||
IDocument *document = DiffEditorController::findOrCreateDocument(documentId, title);
|
||||
QTC_ASSERT(document, return);
|
||||
DiffEditorController *controller = factory(document);
|
||||
QTC_ASSERT(controller, return);
|
||||
|
@@ -41,7 +41,6 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
#include <diffeditor/diffeditorcontroller.h>
|
||||
#include <diffeditor/diffeditormanager.h>
|
||||
#include <diffeditor/diffutils.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
@@ -279,8 +278,9 @@ DiffController *SubversionClient::findOrCreateDiffEditor(const QString &document
|
||||
const QString &title,
|
||||
const QString &workingDirectory) const
|
||||
{
|
||||
IDocument *document = DiffEditorManager::findOrCreate(documentId, title);
|
||||
DiffController *controller = qobject_cast<DiffController *>(DiffEditorManager::controller(document));
|
||||
IDocument *document = DiffEditorController::findOrCreateDocument(documentId, title);
|
||||
DiffController *controller = qobject_cast<DiffController *>(
|
||||
DiffEditorController::controller(document));
|
||||
if (!controller)
|
||||
controller = new DiffController(document, this, workingDirectory);
|
||||
VcsBasePlugin::setSource(document, source);
|
||||
|
Reference in New Issue
Block a user