Commit 59259df5 authored by hjk's avatar hjk

Vcs: Convert to new editor construction scheme

Change-Id: I4b4516c8cdf1a934a7865ac6dce904a244995b5b
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 5f7e89d9
......@@ -655,9 +655,7 @@ void BazaarPlugin::testDiffFileResolving_data()
void BazaarPlugin::testDiffFileResolving()
{
BazaarEditorWidget editor;
editor.setParameters(editorParameters + 2);
editor.testDiffFileResolving();
VcsBaseEditorWidget::testDiffFileResolving(editorParameters[2].id);
}
void BazaarPlugin::testLogResolving()
......@@ -680,9 +678,7 @@ void BazaarPlugin::testLogResolving()
" (gz) Set approved revision and vote \"Approve\" when using lp-propose\n"
" --approve (Jonathan Lange)\n"
);
BazaarEditorWidget editor;
editor.setParameters(editorParameters);
editor.testLogResolving(data, "6572", "6571");
VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, "6572", "6571");
}
#endif
......
......@@ -70,7 +70,6 @@
#include <vcsbase/vcsoutputwindow.h>
#include <vcsbase/vcsbasesubmiteditor.h>
#include <QAction>
#include <QDebug>
#include <QDialog>
......@@ -105,7 +104,7 @@
using namespace Core;
using namespace ProjectExplorer;
using VcsBase::VcsOutputWindow;
using namespace VcsBase;
namespace ClearCase {
namespace Internal {
......@@ -2227,9 +2226,7 @@ void ClearCasePlugin::testDiffFileResolving_data()
void ClearCasePlugin::testDiffFileResolving()
{
ClearCaseEditorWidget editor;
editor.setParameters(editorParameters + 2);
editor.testDiffFileResolving();
VcsBaseEditorWidget::testDiffFileResolving(editorParameters[2].id);
}
void ClearCasePlugin::testLogResolving()
......@@ -2238,9 +2235,7 @@ void ClearCasePlugin::testLogResolving()
"13-Sep.17:41 user1 create version \"src/plugins/clearcase/clearcaseeditor.h@@/main/branch1/branch2/9\" (baseline1, baseline2, ...)\n"
"22-Aug.14:13 user2 create version \"src/plugins/clearcase/clearcaseeditor.h@@/main/branch1/branch2/8\" (baseline3, baseline4, ...)\n"
);
ClearCaseEditorWidget editor;
editor.setParameters(editorParameters);
editor.testLogResolving(data,
VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data,
"src/plugins/clearcase/clearcaseeditor.h@@/main/branch1/branch2/9",
"src/plugins/clearcase/clearcaseeditor.h@@/main/branch1/branch2/8");
}
......
......@@ -1319,9 +1319,7 @@ void CvsPlugin::testDiffFileResolving_data()
void CvsPlugin::testDiffFileResolving()
{
CvsEditorWidget editor;
editor.setParameters(editorParameters + 3);
editor.testDiffFileResolving();
VcsBaseEditorWidget::testDiffFileResolving(editorParameters[3].id);
}
void CvsPlugin::testLogResolving()
......@@ -1347,9 +1345,7 @@ void CvsPlugin::testLogResolving()
"added latest commentary\n"
"----------------------------\n"
);
CvsEditorWidget editor;
editor.setParameters(editorParameters + 1);
editor.testLogResolving(data, "1.3", "1.2");
VcsBaseEditorWidget::testLogResolving(editorParameters[1].id, data, "1.3", "1.2");
}
#endif
......
......@@ -58,6 +58,7 @@
#include <coreplugin/infobar.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/locator/commandlocator.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/coreconstants.h>
......@@ -72,7 +73,6 @@
#include <vcsbase/basevcssubmiteditorfactory.h>
#include <vcsbase/vcsoutputwindow.h>
#include <vcsbase/cleandialog.h>
#include <coreplugin/locator/commandlocator.h>
#include <QDebug>
#include <QDir>
......@@ -1523,9 +1523,7 @@ void GitPlugin::testDiffFileResolving_data()
void GitPlugin::testDiffFileResolving()
{
GitEditorWidget editor;
editor.setParameters(editorParameters + 3);
editor.testDiffFileResolving();
VcsBaseEditorWidget::testDiffFileResolving(editorParameters[3].id);
}
void GitPlugin::testLogResolving()
......@@ -1550,9 +1548,8 @@ void GitPlugin::testLogResolving()
" \n"
" Signed-off-by: Junio C Hamano <gitster@pobox.com>\n"
);
GitEditorWidget editor;
editor.setParameters(editorParameters + 1);
editor.testLogResolving(data,
VcsBaseEditorWidget::testLogResolving(editorParameters[1].id, data,
"50a6b54c - Merge branch 'for-junio' of git://bogomips.org/git-svn",
"3587b513 - Update draft release notes to 1.8.2");
}
......
......@@ -722,9 +722,7 @@ void MercurialPlugin::testDiffFileResolving_data()
void MercurialPlugin::testDiffFileResolving()
{
MercurialEditorWidget editor;
editor.setParameters(editorParameters + 2);
editor.testDiffFileResolving();
VcsBaseEditorWidget::testDiffFileResolving(editorParameters[2].id);
}
void MercurialPlugin::testLogResolving()
......@@ -744,9 +742,7 @@ void MercurialPlugin::testLogResolving()
"date: Sat Jan 19 04:08:16 2013 +0100\n"
"summary: test-rebase: add another test for rebase with multiple roots\n"
);
MercurialEditorWidget editor;
editor.setParameters(editorParameters);
editor.testLogResolving(data, "18473:692cbda1eb50", "18472:37100f30590f");
VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, "18473:692cbda1eb50", "18472:37100f30590f");
}
#endif
......
......@@ -1555,9 +1555,7 @@ void PerforcePlugin::testLogResolving()
"\n"
" Comment\n"
);
PerforceEditorWidget editor;
editor.setParameters(editorParameters);
editor.testLogResolving(data, "12345", "12344");
VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, "12345", "12344");
}
#endif
......
......@@ -1282,9 +1282,7 @@ void SubversionPlugin::testDiffFileResolving_data()
void SubversionPlugin::testDiffFileResolving()
{
SubversionEditorWidget editor;
editor.setParameters(editorParameters + 2);
editor.testDiffFileResolving();
VcsBaseEditorWidget::testDiffFileResolving(editorParameters[2].id);
}
void SubversionPlugin::testLogResolving()
......@@ -1305,9 +1303,7 @@ void SubversionPlugin::testLogResolving()
" expectations, remove XFail.\n"
"\n"
);
SubversionEditorWidget editor;
editor.setParameters(editorParameters);
editor.testLogResolving(data, "r1439551", "r1439540");
VcsBaseEditorWidget::testLogResolving(editorParameters[0].id, data, "r1439551", "r1439540");
}
#endif
......
......@@ -647,11 +647,12 @@ public:
void setEditorActionHandlers(Core::Id contextId, uint optionalActions);
void setEditorActionHandlers(uint optionalActions);
Core::IEditor *createEditor();
private:
friend class BaseTextEditor;
friend class PlainTextEditorFactory;
Core::IEditor *createEditor();
BaseTextEditor *createEditorHelper(const BaseTextDocumentPtr &doc);
BaseTextEditor *duplicateTextEditor(BaseTextEditor *);
......
......@@ -279,7 +279,8 @@ SyntaxHighlighter::SyntaxHighlighter(QTextDocument *parent)
: QObject(parent), d_ptr(new SyntaxHighlighterPrivate)
{
d_ptr->q_ptr = this;
setDocument(parent);
if (parent)
setDocument(parent);
}
/*!
......@@ -291,7 +292,8 @@ SyntaxHighlighter::SyntaxHighlighter(QTextEdit *parent)
: QObject(parent), d_ptr(new SyntaxHighlighterPrivate)
{
d_ptr->q_ptr = this;
setDocument(parent->document());
if (parent)
setDocument(parent->document());
}
/*!
......
......@@ -33,6 +33,8 @@
#include <texteditor/texteditoractionhandler.h>
#include <diffeditor/diffeditorconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
#include <QStringList>
......@@ -49,62 +51,44 @@ using namespace TextEditor;
*/
namespace VcsBase {
namespace Internal {
class BaseVcsEditorFactoryPrivate
{
public:
const VcsBaseEditorParameters *m_parameters;
QObject *m_describeReceiver;
const char *m_describeSlot;
BaseTextEditorFactory::EditorWidgetCreator m_widgetCreator;
};
} // namespace Internal
VcsEditorFactory::VcsEditorFactory(const VcsBaseEditorParameters *parameters,
const BaseTextEditorFactory::EditorWidgetCreator &creator,
const EditorWidgetCreator &editorWidgetCreator,
QObject *describeReceiver, const char *describeSlot)
: d(new Internal::BaseVcsEditorFactoryPrivate)
{
d->m_parameters = parameters;
d->m_describeReceiver = describeReceiver;
d->m_describeSlot = describeSlot;
d->m_widgetCreator = creator;
setProperty("VcsEditorFactoryName", QByteArray(parameters->id));
setId(parameters->id);
setDisplayName(QCoreApplication::translate("VCS", parameters->displayName));
if (QLatin1String(parameters->mimeType) != QLatin1String(DiffEditor::Constants::DIFF_EDITOR_MIMETYPE))
addMimeType(parameters->mimeType);
new TextEditor::TextEditorActionHandler(this, parameters->context);
}
VcsEditorFactory::~VcsEditorFactory()
{
delete d;
setEditorActionHandlers(parameters->context, TextEditorActionHandler::None);
setDocumentCreator([=]() {
auto document = new BaseTextDocument(parameters->id);
// if (QLatin1String(parameters->mimeType) != QLatin1String(DiffEditor::Constants::DIFF_EDITOR_MIMETYPE))
document->setMimeType(QLatin1String(parameters->mimeType));
return document;
});
setEditorWidgetCreator([=]() {
auto widget = qobject_cast<VcsBaseEditorWidget *>(editorWidgetCreator());
widget->setDescribeSlot(describeReceiver, describeSlot);
widget->setParameters(parameters);
return widget;
});
setEditorCreator([=]() {
return new VcsBaseEditor(parameters);
});
}
Core::IEditor *VcsEditorFactory::createEditor()
VcsBaseEditor *VcsEditorFactory::createEditorById(const char *id)
{
TextEditor::BaseTextEditor *editor = new VcsBaseEditor(d->m_parameters);
VcsBaseEditorWidget *widget = qobject_cast<VcsBaseEditorWidget *>(d->m_widgetCreator());
widget->setParameters(d->m_parameters);
// Pass on signals.
connect(widget, SIGNAL(describeRequested(QString,QString)),
editor, SIGNAL(describeRequested(QString,QString)));
connect(widget, SIGNAL(annotateRevisionRequested(QString,QString,QString,int)),
editor, SIGNAL(annotateRevisionRequested(QString,QString,QString,int)));
editor->setEditorWidget(widget);
widget->init();
if (d->m_describeReceiver)
connect(widget, SIGNAL(describeRequested(QString,QString)), d->m_describeReceiver, d->m_describeSlot);
if (!mimeTypes().isEmpty())
widget->textDocument()->setMimeType(mimeTypes().front());
return editor;
auto factory = ExtensionSystem::PluginManager::getObject<VcsEditorFactory>(
[id](QObject *ob) { return ob->property("VcsEditorFactoryName").toByteArray() == id; });
QTC_ASSERT(factory, return 0);
return qobject_cast<VcsBaseEditor *>(factory->createEditor());
}
} // namespace VcsBase
......@@ -33,27 +33,22 @@
#include "vcsbase_global.h"
#include "vcsbaseeditor.h"
#include <coreplugin/editormanager/ieditorfactory.h>
#include <texteditor/basetexteditor.h>
#include <QSharedPointer>
namespace VcsBase {
namespace Internal { class BaseVcsEditorFactoryPrivate; }
class VCSBASE_EXPORT VcsEditorFactory : public Core::IEditorFactory
class VCSBASE_EXPORT VcsEditorFactory : public TextEditor::BaseTextEditorFactory
{
Q_OBJECT
public:
VcsEditorFactory(const VcsBaseEditorParameters *type,
const TextEditor::BaseTextEditorFactory::EditorWidgetCreator &creator,
VcsEditorFactory(const VcsBaseEditorParameters *parameters,
const EditorWidgetCreator &editorWidgetCreator,
QObject *describeReceiver,
const char *describeSlot);
~VcsEditorFactory();
Core::IEditor *createEditor();
private:
Internal::BaseVcsEditorFactoryPrivate *const d;
static VcsBaseEditor *createEditorById(const char *id);
};
} // namespace VcsBase
......
......@@ -30,6 +30,7 @@
#include "vcsbaseeditor.h"
#include "diffhighlighter.h"
#include "baseannotationhighlighter.h"
#include "basevcseditorfactory.h"
#include "vcsbaseplugin.h"
#include "vcsbaseeditorparameterwidget.h"
#include "vcscommand.h"
......@@ -559,6 +560,10 @@ public:
bool m_mouseDragging;
QList<AbstractTextCursorHandler *> m_textCursorHandlers;
QPointer<VcsCommand> m_command;
QObject *m_describeReceiver;
const char *m_describeSlot;
private:
QComboBox *m_entriesComboBox;
};
......@@ -571,6 +576,8 @@ VcsBaseEditorWidgetPrivate::VcsBaseEditorWidgetPrivate(VcsBaseEditorWidget *edit
m_fileLogAnnotateEnabled(false),
m_configurationWidget(0),
m_mouseDragging(false),
m_describeReceiver(0),
m_describeSlot(0),
m_entriesComboBox(0)
{
m_textCursorHandlers.append(new ChangeTextCursorHandler(editorWidget));
......@@ -635,16 +642,12 @@ VcsBaseEditorWidget::VcsBaseEditorWidget()
: d(new Internal::VcsBaseEditorWidgetPrivate(this))
{
viewport()->setMouseTracking(true);
BaseTextDocumentPtr doc(new BaseTextDocument);
setTextDocument(doc);
}
void VcsBaseEditorWidget::setParameters(const VcsBaseEditorParameters *parameters)
{
QTC_CHECK(d->m_parameters == 0);
d->m_parameters = parameters;
textDocument()->setId(d->m_parameters->id);
textDocument()->setMimeType(QLatin1String(d->m_parameters->mimeType));
}
void VcsBaseEditorWidget::setDiffFilePattern(const QRegExp &pattern)
......@@ -676,6 +679,27 @@ QString VcsBaseEditorWidget::fileNameForLine(int line) const
return source();
}
void VcsBaseEditorWidget::setDescribeSlot(QObject *describeReceiver, const char *describeSlot)
{
d->m_describeReceiver = describeReceiver;
d->m_describeSlot = describeSlot;
}
void VcsBaseEditorWidget::finalizeInitialization()
{
BaseTextEditor *editor = this->editor();
// Pass on signals.
connect(this, SIGNAL(describeRequested(QString,QString)),
editor, SIGNAL(describeRequested(QString,QString)));
connect(this, SIGNAL(annotateRevisionRequested(QString,QString,QString,int)),
editor, SIGNAL(annotateRevisionRequested(QString,QString,QString,int)));
if (d->m_describeReceiver)
connect(this, SIGNAL(describeRequested(QString,QString)), d->m_describeReceiver, d->m_describeSlot);
init();
}
void VcsBaseEditorWidget::init()
{
switch (d->m_parameters->type) {
......@@ -1550,38 +1574,32 @@ Core::IEditor *VcsBaseEditor::locateEditorByTag(const QString &tag)
#ifdef WITH_TESTS
#include <QTest>
// Tests need a fully set-up editor/widget combo.
void VcsBase::VcsBaseEditorWidget::addDummyEditor()
void VcsBase::VcsBaseEditorWidget::testDiffFileResolving(const char *id)
{
BaseTextEditor *editor = new VcsBaseEditor(d->m_parameters);
// Pass on signals.
connect(this, SIGNAL(describeRequested(QString,QString)),
editor, SIGNAL(describeRequested(QString,QString)));
connect(this, SIGNAL(annotateRevisionRequested(QString,QString,QString,int)),
editor, SIGNAL(annotateRevisionRequested(QString,QString,QString,int)));
editor->setEditorWidget(this);
}
VcsBaseEditor *editor = VcsBase::VcsEditorFactory::createEditorById(id);
VcsBaseEditorWidget *widget = qobject_cast<VcsBaseEditorWidget *>(editor->editorWidget());
void VcsBase::VcsBaseEditorWidget::testDiffFileResolving()
{
addDummyEditor();
QFETCH(QByteArray, header);
QFETCH(QByteArray, fileName);
QTextDocument doc(QString::fromLatin1(header));
init();
QTextBlock block = doc.lastBlock();
QVERIFY(fileNameFromDiffSpecification(block).endsWith(QString::fromLatin1(fileName)));
QVERIFY(widget->fileNameFromDiffSpecification(block).endsWith(QString::fromLatin1(fileName)));
delete editor;
}
void VcsBase::VcsBaseEditorWidget::testLogResolving(QByteArray &data,
void VcsBase::VcsBaseEditorWidget::testLogResolving(const char *id, QByteArray &data,
const QByteArray &entry1,
const QByteArray &entry2)
{
addDummyEditor();
init();
textDocument()->setPlainText(QLatin1String(data));
QCOMPARE(d->entriesComboBox()->itemText(0), QString::fromLatin1(entry1));
QCOMPARE(d->entriesComboBox()->itemText(1), QString::fromLatin1(entry2));
VcsBaseEditor *editor = VcsBase::VcsEditorFactory::createEditorById(id);
VcsBaseEditorWidget *widget = qobject_cast<VcsBaseEditorWidget *>(editor->editorWidget());
widget->textDocument()->setPlainText(QLatin1String(data));
QCOMPARE(widget->d->entriesComboBox()->itemText(0), QString::fromLatin1(entry1));
QCOMPARE(widget->d->entriesComboBox()->itemText(1), QString::fromLatin1(entry2));
delete editor;
}
#endif
......
......@@ -160,6 +160,10 @@ protected:
virtual QString fileNameForLine(int line) const;
public:
void finalizeInitialization();
// FIXME: Consolidate these into finalizeInitialization
void setDescribeSlot(QObject *describeReceiver, const char *describeSlot);
// void
virtual void init();
//
void setParameters(const VcsBaseEditorParameters *parameters);
......@@ -291,9 +295,8 @@ private:
#ifdef WITH_TESTS
public:
void addDummyEditor();
void testDiffFileResolving();
void testLogResolving(QByteArray &data, const QByteArray &entry1, const QByteArray &entry2);
static void testDiffFileResolving(const char *id);
static void testLogResolving(const char *id, QByteArray &data, const QByteArray &entry1, const QByteArray &entry2);
#endif
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment