Commit 2481e71d authored by hjk's avatar hjk
Browse files

Vcs: Move editor construction over to new scheme



Change-Id: I491b9f37bfe15ebc800fedd5c683bfaf24e63889
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 461a54bd
......@@ -248,7 +248,6 @@ const VcsBaseSubmitEditorParameters submitParameters = {
bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *errorMessage)
{
typedef VcsSubmitEditorFactory<SubversionSubmitEditor> SubversionSubmitEditorFactory;
typedef VcsEditorFactory<SubversionEditor> SubversionEditorFactory;
using namespace Constants;
using namespace Core::Constants;
......@@ -270,8 +269,9 @@ bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *e
static const char *describeSlot = SLOT(describe(QString,QString));
const int editorCount = sizeof(editorParameters) / sizeof(editorParameters[0]);
const auto widgetCreator = []() { return new SubversionEditor; };
for (int i = 0; i < editorCount; i++)
addAutoReleasedObject(new SubversionEditorFactory(editorParameters + i, this, describeSlot));
addAutoReleasedObject(new VcsEditorFactory(editorParameters + i, widgetCreator, this, describeSlot));
auto checkoutWizardFactory = new BaseCheckoutWizardFactory;
checkoutWizardFactory->setId(QLatin1String(VcsBase::Constants::VCS_ID_SUBVERSION));
......@@ -1282,7 +1282,8 @@ void SubversionPlugin::testDiffFileResolving_data()
void SubversionPlugin::testDiffFileResolving()
{
SubversionEditor editor(editorParameters + 2, 0);
SubversionEditor editor;
editor.setParameters(editorParameters + 2);
editor.testDiffFileResolving();
}
......@@ -1304,7 +1305,8 @@ void SubversionPlugin::testLogResolving()
" expectations, remove XFail.\n"
"\n"
);
SubversionEditor editor(editorParameters, 0);
SubversionEditor editor;
editor.setParameters(editorParameters);
editor.testLogResolving(data, "r1439551", "r1439540");
}
#endif
......
......@@ -37,6 +37,8 @@
#include <QCoreApplication>
#include <QStringList>
using namespace TextEditor;
/*!
\class VcsBase::BaseVCSEditorFactory
......@@ -52,44 +54,57 @@ namespace Internal {
class BaseVcsEditorFactoryPrivate
{
public:
const VcsBaseEditorParameters *m_type;
const VcsBaseEditorParameters *m_parameters;
QObject *m_describeReceiver;
const char *m_describeSlot;
BaseTextEditor::WidgetCreator m_widgetCreator;
};
} // namespace Internal
BaseVcsEditorFactory::BaseVcsEditorFactory(const VcsBaseEditorParameters *t,
VcsEditorFactory::VcsEditorFactory(const VcsBaseEditorParameters *parameters,
const BaseTextEditor::WidgetCreator &creator,
QObject *describeReceiver, const char *describeSlot)
: d(new Internal::BaseVcsEditorFactoryPrivate)
{
d->m_type = t;
d->m_parameters = parameters;
d->m_describeReceiver = describeReceiver;
d->m_describeSlot = describeSlot;
setId(t->id);
setDisplayName(QCoreApplication::translate("VCS", t->displayName));
if (QLatin1String(t->mimeType) != QLatin1String(DiffEditor::Constants::DIFF_EDITOR_MIMETYPE))
addMimeType(t->mimeType);
new TextEditor::TextEditorActionHandler(this, t->context);
d->m_widgetCreator = creator;
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);
}
BaseVcsEditorFactory::~BaseVcsEditorFactory()
VcsEditorFactory::~VcsEditorFactory()
{
delete d;
}
Core::IEditor *BaseVcsEditorFactory::createEditor()
Core::IEditor *VcsEditorFactory::createEditor()
{
VcsBaseEditorWidget *vcsEditor = createVcsBaseEditor(d->m_type);
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);
vcsEditor->init();
widget->init();
if (d->m_describeReceiver)
connect(vcsEditor, SIGNAL(describeRequested(QString,QString)), d->m_describeReceiver, d->m_describeSlot);
connect(widget, SIGNAL(describeRequested(QString,QString)), d->m_describeReceiver, d->m_describeSlot);
if (!mimeTypes().isEmpty())
vcsEditor->textDocument()->setMimeType(mimeTypes().front());
widget->textDocument()->setMimeType(mimeTypes().front());
return vcsEditor->editor();
return editor;
}
} // namespace VcsBase
......@@ -34,48 +34,28 @@
#include "vcsbaseeditor.h"
#include <coreplugin/editormanager/ieditorfactory.h>
#include <texteditor/basetexteditor.h>
namespace VcsBase {
namespace Internal { class BaseVcsEditorFactoryPrivate; }
class VCSBASE_EXPORT BaseVcsEditorFactory : public Core::IEditorFactory
class VCSBASE_EXPORT VcsEditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
explicit BaseVcsEditorFactory(const VcsBaseEditorParameters *type,
VcsEditorFactory(const VcsBaseEditorParameters *type,
const TextEditor::BaseTextEditor::WidgetCreator &creator,
QObject *describeReceiver,
const char *describeSlot);
~BaseVcsEditorFactory();
~VcsEditorFactory();
Core::IEditor *createEditor();
private:
// Implement to create and initialize (call init()) a VcsBaseEditor subclass.
virtual VcsBaseEditorWidget *createVcsBaseEditor(const VcsBaseEditorParameters *type) = 0;
Internal::BaseVcsEditorFactoryPrivate *const d;
};
// Utility template to create an editor.
template <class Editor>
class VcsEditorFactory : public BaseVcsEditorFactory
{
public:
explicit VcsEditorFactory(const VcsBaseEditorParameters *type,
QObject *describeReceiver = 0,
const char *describeSlot = 0)
: BaseVcsEditorFactory(type, describeReceiver, describeSlot)
{
}
private:
VcsBaseEditorWidget *createVcsBaseEditor(const VcsBaseEditorParameters *type)
{
return new Editor(type, 0);
}
};
} // namespace VcsBase
#endif // BASEVCSEDITORFACTORY_H
......
......@@ -150,18 +150,6 @@ namespace VcsBase {
manager passes the editor around.
*/
class VcsBaseEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
explicit VcsBaseEditor(const VcsBaseEditorParameters *type);
signals:
void describeRequested(const QString &source, const QString &change);
void annotateRevisionRequested(const QString &workingDirectory, const QString &file,
const QString &change, int line);
};
VcsBaseEditor::VcsBaseEditor(const VcsBaseEditorParameters *type)
{
setContext(Core::Context(type->context, TextEditor::Constants::C_TEXTEDITOR));
......@@ -547,13 +535,14 @@ void EmailTextCursorHandler::slotOpenUrl()
class VcsBaseEditorWidgetPrivate
{
public:
VcsBaseEditorWidgetPrivate(VcsBaseEditorWidget* editorWidget, const VcsBaseEditorParameters *type);
VcsBaseEditorWidgetPrivate(VcsBaseEditorWidget *editorWidget);
AbstractTextCursorHandler *findTextCursorHandler(const QTextCursor &cursor);
// creates a browse combo in the toolbar for quick access to entries.
// Can be used for diff and log. Combo created on first call.
QComboBox *entriesComboBox();
TextEditor::BaseTextEditorWidget *q;
const VcsBaseEditorParameters *m_parameters;
QString m_workingDirectory;
......@@ -566,7 +555,6 @@ public:
QString m_annotatePreviousRevisionTextFormat;
QString m_copyRevisionTextFormat;
bool m_fileLogAnnotateEnabled;
TextEditor::BaseTextEditor *m_editor;
VcsBaseEditorParameterWidget *m_configurationWidget;
bool m_mouseDragging;
QList<AbstractTextCursorHandler *> m_textCursorHandlers;
......@@ -576,14 +564,13 @@ private:
QComboBox *m_entriesComboBox;
};
VcsBaseEditorWidgetPrivate::VcsBaseEditorWidgetPrivate(VcsBaseEditorWidget *editorWidget,
const VcsBaseEditorParameters *type) :
m_parameters(type),
VcsBaseEditorWidgetPrivate::VcsBaseEditorWidgetPrivate(VcsBaseEditorWidget *editorWidget) :
q(editorWidget),
m_parameters(0),
m_cursorLine(-1),
m_annotateRevisionTextFormat(VcsBaseEditorWidget::tr("Annotate \"%1\"")),
m_copyRevisionTextFormat(VcsBaseEditorWidget::tr("Copy \"%1\"")),
m_fileLogAnnotateEnabled(false),
m_editor(0),
m_configurationWidget(0),
m_mouseDragging(false),
m_entriesComboBox(0)
......@@ -613,8 +600,7 @@ QComboBox *VcsBaseEditorWidgetPrivate::entriesComboBox()
policy.setHorizontalPolicy(QSizePolicy::Expanding);
m_entriesComboBox->setSizePolicy(policy);
m_editor->editorWidget()->insertExtraToolBarWidget
(TextEditor::BaseTextEditorWidget::Left, m_entriesComboBox);
q->insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, m_entriesComboBox);
return m_entriesComboBox;
}
......@@ -647,15 +633,20 @@ QComboBox *VcsBaseEditorWidgetPrivate::entriesComboBox()
\sa VcsBase::BaseVcsEditorFactory, VcsBase::VcsBaseEditorParameters, VcsBase::EditorContentType
*/
VcsBaseEditorWidget::VcsBaseEditorWidget(const VcsBaseEditorParameters *type, QWidget *parent)
: BaseTextEditorWidget(parent),
d(new Internal::VcsBaseEditorWidgetPrivate(this, type))
VcsBaseEditorWidget::VcsBaseEditorWidget()
: d(new Internal::VcsBaseEditorWidgetPrivate(this))
{
viewport()->setMouseTracking(true);
BaseTextDocumentPtr doc(new BaseTextDocument);
doc->setId(type->id);
doc->setMimeType(QLatin1String(d->m_parameters->mimeType));
setTextDocument(doc);
viewport()->setMouseTracking(true);
}
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)
......@@ -689,7 +680,6 @@ QString VcsBaseEditorWidget::fileNameForLine(int line) const
void VcsBaseEditorWidget::init()
{
d->m_editor = editor();
switch (d->m_parameters->type) {
case OtherContent:
break;
......@@ -817,14 +807,7 @@ bool VcsBaseEditorWidget::isModified() const
TextEditor::BaseTextEditor *VcsBaseEditorWidget::createEditor()
{
TextEditor::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)));
return editor;
QTC_ASSERT("should not happen anymore" && false, return 0);
}
void VcsBaseEditorWidget::slotPopulateDiffBrowser()
......@@ -1334,11 +1317,11 @@ QString VcsBaseEditorWidget::getTitleId(const QString &workingDirectory,
bool VcsBaseEditorWidget::setConfigurationWidget(VcsBaseEditorParameterWidget *w)
{
if (!d->m_editor || d->m_configurationWidget)
if (d->m_configurationWidget)
return false;
d->m_configurationWidget = w;
d->m_editor->editorWidget()->insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Right, w);
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Right, w);
return true;
}
......@@ -1569,8 +1552,21 @@ Core::IEditor* VcsBaseEditorWidget::locateEditorByTag(const QString &tag)
#ifdef WITH_TESTS
#include <QTest>
// Tests need a fully set-up editor/widget combo.
void VcsBase::VcsBaseEditorWidget::addDummyEditor()
{
TextEditor::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);
}
void VcsBase::VcsBaseEditorWidget::testDiffFileResolving()
{
addDummyEditor();
QFETCH(QByteArray, header);
QFETCH(QByteArray, fileName);
QTextDocument doc(QString::fromLatin1(header));
......@@ -1583,6 +1579,7 @@ void VcsBase::VcsBaseEditorWidget::testLogResolving(QByteArray &data,
const QByteArray &entry1,
const QByteArray &entry2)
{
addDummyEditor();
init();
textDocument()->setPlainText(QLatin1String(data));
QCOMPARE(d->entriesComboBox()->itemText(0), QString::fromLatin1(entry1));
......
......@@ -87,6 +87,18 @@ public:
QByteArray header;
};
class VcsBaseEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
explicit VcsBaseEditor(const VcsBaseEditorParameters *type);
signals:
void describeRequested(const QString &source, const QString &change);
void annotateRevisionRequested(const QString &workingDirectory, const QString &file,
const QString &change, int line);
};
class VCSBASE_EXPORT VcsBaseEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_PROPERTY(QString source READ source WRITE setSource)
......@@ -100,8 +112,7 @@ class VCSBASE_EXPORT VcsBaseEditorWidget : public TextEditor::BaseTextEditorWidg
protected:
// Initialization requires calling init() (which in turns calls
// virtual functions).
explicit VcsBaseEditorWidget(const VcsBaseEditorParameters *type,
QWidget *parent);
VcsBaseEditorWidget();
// Pattern for diff header. File name must be in the first capture group
void setDiffFilePattern(const QRegExp &pattern);
// Pattern for log entry. hash/revision number must be in the first capture group
......@@ -111,6 +122,8 @@ protected:
public:
virtual void init();
//
void setParameters(const VcsBaseEditorParameters *parameters);
~VcsBaseEditorWidget();
......@@ -281,6 +294,7 @@ private:
#ifdef WITH_TESTS
public:
void addDummyEditor();
void testDiffFileResolving();
void testLogResolving(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