forked from qt-creator/qt-creator
Core: Make IEditorFactory::createEditor use a function object
Also, replace or remove unneeded Q_OBJECTs, and make base setters and adders protected. Change-Id: I212257ef53984d8852dc8c478537199fc9483486 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -38,17 +38,15 @@ using namespace Android::Internal;
|
|||||||
AndroidManifestEditorFactory::AndroidManifestEditorFactory()
|
AndroidManifestEditorFactory::AndroidManifestEditorFactory()
|
||||||
{
|
{
|
||||||
setId(Constants::ANDROID_MANIFEST_EDITOR_ID);
|
setId(Constants::ANDROID_MANIFEST_EDITOR_ID);
|
||||||
setDisplayName(tr("Android Manifest editor"));
|
setDisplayName(AndroidManifestEditorWidget::tr("Android Manifest editor"));
|
||||||
addMimeType(Constants::ANDROID_MANIFEST_MIME_TYPE);
|
addMimeType(Constants::ANDROID_MANIFEST_MIME_TYPE);
|
||||||
auto actionHandler = new TextEditor::TextEditorActionHandler(
|
auto actionHandler = new TextEditor::TextEditorActionHandler(
|
||||||
this, id(), Constants::ANDROID_MANIFEST_EDITOR_CONTEXT);
|
this, id(), Constants::ANDROID_MANIFEST_EDITOR_CONTEXT);
|
||||||
actionHandler->setTextEditorWidgetResolver([](Core::IEditor *editor) {
|
actionHandler->setTextEditorWidgetResolver([](Core::IEditor *editor) {
|
||||||
return static_cast<AndroidManifestEditor *>(editor)->textEditor();
|
return static_cast<AndroidManifestEditor *>(editor)->textEditor();
|
||||||
});
|
});
|
||||||
}
|
setEditorCreator([] {
|
||||||
|
auto androidManifestEditorWidget = new AndroidManifestEditorWidget;
|
||||||
Core::IEditor *AndroidManifestEditorFactory::createEditor()
|
return androidManifestEditorWidget->editor();
|
||||||
{
|
});
|
||||||
auto androidManifestEditorWidget = new AndroidManifestEditorWidget();
|
|
||||||
return androidManifestEditorWidget->editor();
|
|
||||||
}
|
}
|
||||||
|
@@ -30,14 +30,10 @@
|
|||||||
namespace Android {
|
namespace Android {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class AndroidManifestEditorFactory : public Core::IEditorFactory
|
class AndroidManifestEditorFactory final : public Core::IEditorFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AndroidManifestEditorFactory();
|
AndroidManifestEditorFactory();
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -471,33 +471,32 @@ BinEditorFactory::BinEditorFactory()
|
|||||||
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
|
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
|
||||||
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::C_BINEDITOR_DISPLAY_NAME));
|
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::C_BINEDITOR_DISPLAY_NAME));
|
||||||
addMimeType(Constants::C_BINEDITOR_MIMETYPE);
|
addMimeType(Constants::C_BINEDITOR_MIMETYPE);
|
||||||
}
|
|
||||||
|
|
||||||
IEditor *BinEditorFactory::createEditor()
|
setEditorCreator([] {
|
||||||
{
|
auto widget = new BinEditorWidget();
|
||||||
auto widget = new BinEditorWidget();
|
auto editor = new BinEditor(widget);
|
||||||
auto editor = new BinEditor(widget);
|
|
||||||
|
|
||||||
connect(dd->m_undoAction, &QAction::triggered, widget, &BinEditorWidget::undo);
|
connect(dd->m_undoAction, &QAction::triggered, widget, &BinEditorWidget::undo);
|
||||||
connect(dd->m_redoAction, &QAction::triggered, widget, &BinEditorWidget::redo);
|
connect(dd->m_redoAction, &QAction::triggered, widget, &BinEditorWidget::redo);
|
||||||
connect(dd->m_copyAction, &QAction::triggered, widget, &BinEditorWidget::copy);
|
connect(dd->m_copyAction, &QAction::triggered, widget, &BinEditorWidget::copy);
|
||||||
connect(dd->m_selectAllAction, &QAction::triggered, widget, &BinEditorWidget::selectAll);
|
connect(dd->m_selectAllAction, &QAction::triggered, widget, &BinEditorWidget::selectAll);
|
||||||
|
|
||||||
auto updateActions = [widget] {
|
auto updateActions = [widget] {
|
||||||
dd->m_selectAllAction->setEnabled(true);
|
dd->m_selectAllAction->setEnabled(true);
|
||||||
dd->m_undoAction->setEnabled(widget->isUndoAvailable());
|
dd->m_undoAction->setEnabled(widget->isUndoAvailable());
|
||||||
dd->m_redoAction->setEnabled(widget->isRedoAvailable());
|
dd->m_redoAction->setEnabled(widget->isRedoAvailable());
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(widget, &BinEditorWidget::undoAvailable, widget, updateActions);
|
connect(widget, &BinEditorWidget::undoAvailable, widget, updateActions);
|
||||||
connect(widget, &BinEditorWidget::redoAvailable, widget, updateActions);
|
connect(widget, &BinEditorWidget::redoAvailable, widget, updateActions);
|
||||||
|
|
||||||
auto aggregate = new Aggregation::Aggregate;
|
auto aggregate = new Aggregation::Aggregate;
|
||||||
auto binEditorFind = new BinEditorFind(widget);
|
auto binEditorFind = new BinEditorFind(widget);
|
||||||
aggregate->add(binEditorFind);
|
aggregate->add(binEditorFind);
|
||||||
aggregate->add(widget);
|
aggregate->add(widget);
|
||||||
|
|
||||||
return editor;
|
return editor;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////// BinEditor Services //////////////////////////////////
|
///////////////////////////////// BinEditor Services //////////////////////////////////
|
||||||
|
@@ -44,14 +44,10 @@ class BinEditorPlugin : public ExtensionSystem::IPlugin
|
|||||||
void extensionsInitialized() final {}
|
void extensionsInitialized() final {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class BinEditorFactory : public Core::IEditorFactory
|
class BinEditorFactory final : public Core::IEditorFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BinEditorFactory();
|
BinEditorFactory();
|
||||||
|
|
||||||
Core::IEditor *createEditor() final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FactoryServiceImpl : public QObject, public FactoryService
|
class FactoryServiceImpl : public QObject, public FactoryService
|
||||||
|
@@ -96,6 +96,17 @@ const EditorFactoryList IEditorFactory::preferredEditorFactories(const QString &
|
|||||||
return factories;
|
return factories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEditor *IEditorFactory::createEditor() const
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_creator, return nullptr);
|
||||||
|
return m_creator();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IEditorFactory::setEditorCreator(const std::function<IEditor *()> &creator)
|
||||||
|
{
|
||||||
|
m_creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
QHash<Utils::MimeType, Core::IEditorFactory *> Core::Internal::userPreferredEditorFactories()
|
QHash<Utils::MimeType, Core::IEditorFactory *> Core::Internal::userPreferredEditorFactories()
|
||||||
{
|
{
|
||||||
return g_userPreferredEditorFactories;
|
return g_userPreferredEditorFactories;
|
||||||
|
@@ -52,22 +52,25 @@ public:
|
|||||||
static const EditorFactoryList defaultEditorFactories(const Utils::MimeType &mimeType);
|
static const EditorFactoryList defaultEditorFactories(const Utils::MimeType &mimeType);
|
||||||
static const EditorFactoryList preferredEditorFactories(const QString &fileName);
|
static const EditorFactoryList preferredEditorFactories(const QString &fileName);
|
||||||
|
|
||||||
QString displayName() const { return m_displayName; }
|
|
||||||
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
|
|
||||||
|
|
||||||
Id id() const { return m_id; }
|
Id id() const { return m_id; }
|
||||||
void setId(Id id) { m_id = id; }
|
QString displayName() const { return m_displayName; }
|
||||||
|
|
||||||
virtual IEditor *createEditor() = 0;
|
|
||||||
|
|
||||||
QStringList mimeTypes() const { return m_mimeTypes; }
|
QStringList mimeTypes() const { return m_mimeTypes; }
|
||||||
|
|
||||||
|
IEditor *createEditor() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setId(Id id) { m_id = id; }
|
||||||
|
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
|
||||||
void setMimeTypes(const QStringList &mimeTypes) { m_mimeTypes = mimeTypes; }
|
void setMimeTypes(const QStringList &mimeTypes) { m_mimeTypes = mimeTypes; }
|
||||||
void addMimeType(const char *mimeType) { m_mimeTypes.append(QLatin1String(mimeType)); }
|
void addMimeType(const char *mimeType) { m_mimeTypes.append(QLatin1String(mimeType)); }
|
||||||
void addMimeType(const QString &mimeType) { m_mimeTypes.append(mimeType); }
|
void addMimeType(const QString &mimeType) { m_mimeTypes.append(mimeType); }
|
||||||
|
void setEditorCreator(const std::function<IEditor *()> &creator);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Id m_id;
|
Id m_id;
|
||||||
QString m_displayName;
|
QString m_displayName;
|
||||||
QStringList m_mimeTypes;
|
QStringList m_mimeTypes;
|
||||||
|
std::function<IEditor *()> m_creator;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@@ -45,14 +45,10 @@ FormEditorFactory::FormEditorFactory()
|
|||||||
setId(K_DESIGNER_XML_EDITOR_ID);
|
setId(K_DESIGNER_XML_EDITOR_ID);
|
||||||
setDisplayName(QCoreApplication::translate("Designer", C_DESIGNER_XML_DISPLAY_NAME));
|
setDisplayName(QCoreApplication::translate("Designer", C_DESIGNER_XML_DISPLAY_NAME));
|
||||||
addMimeType(FORM_MIMETYPE);
|
addMimeType(FORM_MIMETYPE);
|
||||||
|
setEditorCreator([] { return FormEditorW::createEditor(); });
|
||||||
|
|
||||||
FileIconProvider::registerIconOverlayForSuffix(ProjectExplorer::Constants::FILEOVERLAY_UI, "ui");
|
FileIconProvider::registerIconOverlayForSuffix(ProjectExplorer::Constants::FILEOVERLAY_UI, "ui");
|
||||||
}
|
}
|
||||||
|
|
||||||
IEditor *FormEditorFactory::createEditor()
|
|
||||||
{
|
|
||||||
return FormEditorW::createEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Designer
|
} // namespace Designer
|
||||||
|
@@ -30,14 +30,10 @@
|
|||||||
namespace Designer {
|
namespace Designer {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class FormEditorFactory : public Core::IEditorFactory
|
class FormEditorFactory final : public Core::IEditorFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FormEditorFactory();
|
FormEditorFactory();
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -62,11 +62,8 @@ DiffEditorFactory::DiffEditorFactory(QObject *parent)
|
|||||||
rightHandler->setTextEditorWidgetResolver([](Core::IEditor *e) {
|
rightHandler->setTextEditorWidgetResolver([](Core::IEditor *e) {
|
||||||
return static_cast<DiffEditor *>(e)->rightEditorWidget();
|
return static_cast<DiffEditor *>(e)->rightEditorWidget();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Core::IEditor *DiffEditorFactory::createEditor()
|
setEditorCreator([] { return new DiffEditor(new DiffEditorDocument); });
|
||||||
{
|
|
||||||
return new DiffEditor(new DiffEditorDocument);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -25,22 +25,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "diffeditor_global.h"
|
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class DiffEditorFactory : public Core::IEditorFactory
|
class DiffEditorFactory : public Core::IEditorFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DiffEditorFactory(QObject *parent);
|
explicit DiffEditorFactory(QObject *parent);
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -38,16 +38,12 @@ ImageViewerFactory::ImageViewerFactory()
|
|||||||
{
|
{
|
||||||
setId(Constants::IMAGEVIEWER_ID);
|
setId(Constants::IMAGEVIEWER_ID);
|
||||||
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::IMAGEVIEWER_DISPLAY_NAME));
|
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::IMAGEVIEWER_DISPLAY_NAME));
|
||||||
|
setEditorCreator([] { return new ImageViewer; });
|
||||||
|
|
||||||
const QList<QByteArray> supportedMimeTypes = QImageReader::supportedMimeTypes();
|
const QList<QByteArray> supportedMimeTypes = QImageReader::supportedMimeTypes();
|
||||||
foreach (const QByteArray &format, supportedMimeTypes)
|
for (const QByteArray &format : supportedMimeTypes)
|
||||||
addMimeType(format.constData());
|
addMimeType(format.constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IEditor *ImageViewerFactory::createEditor()
|
|
||||||
{
|
|
||||||
return new ImageViewer();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ImageViewer
|
} // namespace ImageViewer
|
||||||
|
@@ -27,19 +27,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
|
||||||
#include <coreplugin/idocument.h>
|
|
||||||
|
|
||||||
namespace ImageViewer {
|
namespace ImageViewer {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class ImageViewerFactory : public Core::IEditorFactory
|
class ImageViewerFactory final : public Core::IEditorFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
ImageViewerFactory();
|
ImageViewerFactory();
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -34,37 +34,24 @@
|
|||||||
namespace ModelEditor {
|
namespace ModelEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class ModelEditorFactory::ModelEditorFactoryPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
UiController *uiController = nullptr;
|
|
||||||
ActionHandler *actionHandler = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
ModelEditorFactory::ModelEditorFactory(UiController *uiController)
|
ModelEditorFactory::ModelEditorFactory(UiController *uiController)
|
||||||
: d(new ModelEditorFactoryPrivate())
|
|
||||||
{
|
{
|
||||||
setId(Constants::MODEL_EDITOR_ID);
|
setId(Constants::MODEL_EDITOR_ID);
|
||||||
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::MODEL_EDITOR_DISPLAY_NAME));
|
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::MODEL_EDITOR_DISPLAY_NAME));
|
||||||
addMimeType(Constants::MIME_TYPE_MODEL);
|
addMimeType(Constants::MIME_TYPE_MODEL);
|
||||||
d->uiController = uiController;
|
m_uiController = uiController;
|
||||||
d->actionHandler = new ActionHandler(Core::Context(Constants::MODEL_EDITOR_ID), this);
|
m_actionHandler = new ActionHandler(Core::Context(Constants::MODEL_EDITOR_ID), this);
|
||||||
|
setEditorCreator([this] { return new ModelEditor(m_uiController, m_actionHandler); });
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelEditorFactory::~ModelEditorFactory()
|
ModelEditorFactory::~ModelEditorFactory()
|
||||||
{
|
{
|
||||||
delete d->actionHandler;
|
delete m_actionHandler;
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::IEditor *ModelEditorFactory::createEditor()
|
|
||||||
{
|
|
||||||
return new ModelEditor(d->uiController, d->actionHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelEditorFactory::extensionsInitialized()
|
void ModelEditorFactory::extensionsInitialized()
|
||||||
{
|
{
|
||||||
d->actionHandler->createActions();
|
m_actionHandler->createActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -30,24 +30,21 @@
|
|||||||
namespace ModelEditor {
|
namespace ModelEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
class ActionHandler;
|
||||||
class ModelEditor;
|
class ModelEditor;
|
||||||
class UiController;
|
class UiController;
|
||||||
|
|
||||||
class ModelEditorFactory :
|
class ModelEditorFactory : public Core::IEditorFactory
|
||||||
public Core::IEditorFactory
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
class ModelEditorFactoryPrivate;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ModelEditorFactory(UiController *uiController);
|
explicit ModelEditorFactory(UiController *uiController);
|
||||||
~ModelEditorFactory();
|
~ModelEditorFactory();
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
void extensionsInitialized();
|
void extensionsInitialized();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ModelEditorFactoryPrivate *d;
|
UiController *m_uiController = nullptr;
|
||||||
|
ActionHandler *m_actionHandler = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -71,11 +71,6 @@ NimEditorFactory::NimEditorFactory()
|
|||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IEditor *NimEditorFactory::createEditor()
|
|
||||||
{
|
|
||||||
return TextEditorFactory::createEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NimEditorFactory::decorateEditor(TextEditorWidget *editor)
|
void NimEditorFactory::decorateEditor(TextEditorWidget *editor)
|
||||||
{
|
{
|
||||||
editor->textDocument()->setSyntaxHighlighter(new NimHighlighter());
|
editor->textDocument()->setSyntaxHighlighter(new NimHighlighter());
|
||||||
|
@@ -36,7 +36,6 @@ class NimEditorFactory : public TextEditor::TextEditorFactory
|
|||||||
public:
|
public:
|
||||||
NimEditorFactory();
|
NimEditorFactory();
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
static void decorateEditor(TextEditor::TextEditorWidget *editor);
|
static void decorateEditor(TextEditor::TextEditorWidget *editor);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -40,8 +40,7 @@ using namespace ResourceEditor::Internal;
|
|||||||
using namespace ResourceEditor::Constants;
|
using namespace ResourceEditor::Constants;
|
||||||
|
|
||||||
ResourceEditorFactory::ResourceEditorFactory(ResourceEditorPlugin *plugin) :
|
ResourceEditorFactory::ResourceEditorFactory(ResourceEditorPlugin *plugin) :
|
||||||
Core::IEditorFactory(plugin),
|
Core::IEditorFactory(plugin)
|
||||||
m_plugin(plugin)
|
|
||||||
{
|
{
|
||||||
setId(RESOURCEEDITOR_ID);
|
setId(RESOURCEEDITOR_ID);
|
||||||
setMimeTypes(QStringList(QLatin1String(C_RESOURCE_MIMETYPE)));
|
setMimeTypes(QStringList(QLatin1String(C_RESOURCE_MIMETYPE)));
|
||||||
@@ -49,10 +48,8 @@ ResourceEditorFactory::ResourceEditorFactory(ResourceEditorPlugin *plugin) :
|
|||||||
|
|
||||||
Core::FileIconProvider::registerIconOverlayForSuffix(
|
Core::FileIconProvider::registerIconOverlayForSuffix(
|
||||||
ProjectExplorer::Constants::FILEOVERLAY_QRC, "qrc");
|
ProjectExplorer::Constants::FILEOVERLAY_QRC, "qrc");
|
||||||
}
|
|
||||||
|
|
||||||
Core::IEditor *ResourceEditorFactory::createEditor()
|
setEditorCreator([plugin] {
|
||||||
{
|
return new ResourceEditorW(Core::Context(C_RESOURCEEDITOR), plugin);
|
||||||
Core::Context context(C_RESOURCEEDITOR);
|
});
|
||||||
return new ResourceEditorW(context, m_plugin);
|
|
||||||
}
|
}
|
||||||
|
@@ -26,26 +26,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||||
#include <coreplugin/icontext.h>
|
|
||||||
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
namespace ResourceEditor {
|
namespace ResourceEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class ResourceEditorPlugin;
|
class ResourceEditorPlugin;
|
||||||
|
|
||||||
class ResourceEditorFactory : public Core::IEditorFactory
|
class ResourceEditorFactory final : public Core::IEditorFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ResourceEditorFactory(ResourceEditorPlugin *plugin);
|
explicit ResourceEditorFactory(ResourceEditorPlugin *plugin);
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
ResourceEditorPlugin *m_plugin;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -46,15 +46,14 @@ ScxmlEditorFactory::ScxmlEditorFactory(QObject *parent)
|
|||||||
addMimeType(ProjectExplorer::Constants::SCXML_MIMETYPE);
|
addMimeType(ProjectExplorer::Constants::SCXML_MIMETYPE);
|
||||||
|
|
||||||
Core::FileIconProvider::registerIconOverlayForSuffix(":/projectexplorer/images/fileoverlay_scxml.png", "scxml");
|
Core::FileIconProvider::registerIconOverlayForSuffix(":/projectexplorer/images/fileoverlay_scxml.png", "scxml");
|
||||||
}
|
|
||||||
|
|
||||||
Core::IEditor *ScxmlEditorFactory::createEditor()
|
setEditorCreator([this] {
|
||||||
{
|
if (!m_editorData) {
|
||||||
if (!m_editorData) {
|
m_editorData = new ScxmlEditorData(this);
|
||||||
m_editorData = new ScxmlEditorData(this);
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
m_editorData->fullInit();
|
||||||
m_editorData->fullInit();
|
QGuiApplication::restoreOverrideCursor();
|
||||||
QGuiApplication::restoreOverrideCursor();
|
}
|
||||||
}
|
return m_editorData->createEditor();
|
||||||
return m_editorData->createEditor();
|
});
|
||||||
}
|
}
|
||||||
|
@@ -32,15 +32,11 @@ namespace Internal {
|
|||||||
|
|
||||||
class ScxmlEditorData;
|
class ScxmlEditorData;
|
||||||
|
|
||||||
class ScxmlEditorFactory : public Core::IEditorFactory
|
class ScxmlEditorFactory final : public Core::IEditorFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ScxmlEditorFactory(QObject *parent);
|
explicit ScxmlEditorFactory(QObject *parent);
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScxmlEditorData* m_editorData = nullptr;
|
ScxmlEditorData* m_editorData = nullptr;
|
||||||
};
|
};
|
||||||
|
@@ -8506,8 +8506,7 @@ class TextEditorFactoryPrivate
|
|||||||
public:
|
public:
|
||||||
TextEditorFactoryPrivate(TextEditorFactory *parent) :
|
TextEditorFactoryPrivate(TextEditorFactory *parent) :
|
||||||
q(parent),
|
q(parent),
|
||||||
m_widgetCreator([]() { return new TextEditorWidget; }),
|
m_widgetCreator([]() { return new TextEditorWidget; })
|
||||||
m_editorCreator([]() { return new BaseTextEditor; })
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BaseTextEditor *duplicateTextEditor(BaseTextEditor *other)
|
BaseTextEditor *duplicateTextEditor(BaseTextEditor *other)
|
||||||
@@ -8540,7 +8539,9 @@ public:
|
|||||||
|
|
||||||
TextEditorFactory::TextEditorFactory(QObject *parent)
|
TextEditorFactory::TextEditorFactory(QObject *parent)
|
||||||
: IEditorFactory(parent), d(new TextEditorFactoryPrivate(this))
|
: IEditorFactory(parent), d(new TextEditorFactoryPrivate(this))
|
||||||
{}
|
{
|
||||||
|
setEditorCreator([]() { return new BaseTextEditor; });
|
||||||
|
}
|
||||||
|
|
||||||
TextEditorFactory::~TextEditorFactory()
|
TextEditorFactory::~TextEditorFactory()
|
||||||
{
|
{
|
||||||
@@ -8562,6 +8563,21 @@ void TextEditorFactory::setEditorWidgetCreator(const EditorWidgetCreator &creato
|
|||||||
void TextEditorFactory::setEditorCreator(const EditorCreator &creator)
|
void TextEditorFactory::setEditorCreator(const EditorCreator &creator)
|
||||||
{
|
{
|
||||||
d->m_editorCreator = creator;
|
d->m_editorCreator = creator;
|
||||||
|
IEditorFactory::setEditorCreator([this] {
|
||||||
|
static DocumentContentCompletionProvider basicSnippetProvider;
|
||||||
|
TextDocumentPtr doc(d->m_documentCreator());
|
||||||
|
|
||||||
|
if (d->m_indenterCreator)
|
||||||
|
doc->setIndenter(d->m_indenterCreator(doc->document()));
|
||||||
|
|
||||||
|
if (d->m_syntaxHighlighterCreator)
|
||||||
|
doc->setSyntaxHighlighter(d->m_syntaxHighlighterCreator());
|
||||||
|
|
||||||
|
doc->setCompletionAssistProvider(d->m_completionAssistProvider ? d->m_completionAssistProvider
|
||||||
|
: &basicSnippetProvider);
|
||||||
|
|
||||||
|
return d->createEditorHelper(doc);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorFactory::setIndenterCreator(const IndenterCreator &creator)
|
void TextEditorFactory::setIndenterCreator(const IndenterCreator &creator)
|
||||||
@@ -8629,23 +8645,6 @@ void TextEditorFactory::setParenthesesMatchingEnabled(bool on)
|
|||||||
d->m_paranthesesMatchinEnabled = on;
|
d->m_paranthesesMatchinEnabled = on;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEditor *TextEditorFactory::createEditor()
|
|
||||||
{
|
|
||||||
static DocumentContentCompletionProvider basicSnippetProvider;
|
|
||||||
TextDocumentPtr doc(d->m_documentCreator());
|
|
||||||
|
|
||||||
if (d->m_indenterCreator)
|
|
||||||
doc->setIndenter(d->m_indenterCreator(doc->document()));
|
|
||||||
|
|
||||||
if (d->m_syntaxHighlighterCreator)
|
|
||||||
doc->setSyntaxHighlighter(d->m_syntaxHighlighterCreator());
|
|
||||||
|
|
||||||
doc->setCompletionAssistProvider(d->m_completionAssistProvider ? d->m_completionAssistProvider
|
|
||||||
: &basicSnippetProvider);
|
|
||||||
|
|
||||||
return d->createEditorHelper(doc);
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentPtr &document)
|
BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentPtr &document)
|
||||||
{
|
{
|
||||||
TextEditorWidget *widget = m_widgetCreator();
|
TextEditorWidget *widget = m_widgetCreator();
|
||||||
|
@@ -666,8 +666,6 @@ public:
|
|||||||
void setParenthesesMatchingEnabled(bool on);
|
void setParenthesesMatchingEnabled(bool on);
|
||||||
void setCodeFoldingSupported(bool on);
|
void setCodeFoldingSupported(bool on);
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class BaseTextEditor;
|
friend class BaseTextEditor;
|
||||||
friend class PlainTextEditorFactory;
|
friend class PlainTextEditorFactory;
|
||||||
|
@@ -44,12 +44,18 @@ VcsSubmitEditorFactory::VcsSubmitEditorFactory
|
|||||||
(const VcsBaseSubmitEditorParameters *parameters,
|
(const VcsBaseSubmitEditorParameters *parameters,
|
||||||
const EditorCreator &editorCreator,
|
const EditorCreator &editorCreator,
|
||||||
VcsBasePluginPrivate *plugin)
|
VcsBasePluginPrivate *plugin)
|
||||||
: IEditorFactory(plugin), m_editorCreator(editorCreator)
|
: IEditorFactory(plugin)
|
||||||
{
|
{
|
||||||
setId(parameters->id);
|
setId(parameters->id);
|
||||||
setDisplayName(QLatin1String(parameters->displayName));
|
setDisplayName(QLatin1String(parameters->displayName));
|
||||||
addMimeType(parameters->mimeType);
|
addMimeType(parameters->mimeType);
|
||||||
|
|
||||||
|
setEditorCreator([this, editorCreator] {
|
||||||
|
VcsBaseSubmitEditor *editor = editorCreator();
|
||||||
|
editor->registerActions(m_undoAction, m_redoAction, m_submitAction, m_diffAction);
|
||||||
|
return editor;
|
||||||
|
});
|
||||||
|
|
||||||
Context context(parameters->id);
|
Context context(parameters->id);
|
||||||
m_undoAction = new QAction(tr("&Undo"), this);
|
m_undoAction = new QAction(tr("&Undo"), this);
|
||||||
ActionManager::registerAction(m_undoAction, Core::Constants::UNDO, context);
|
ActionManager::registerAction(m_undoAction, Core::Constants::UNDO, context);
|
||||||
@@ -68,11 +74,4 @@ VcsSubmitEditorFactory::VcsSubmitEditorFactory
|
|||||||
ActionManager::registerAction(m_diffAction, DIFF_SELECTED, context);
|
ActionManager::registerAction(m_diffAction, DIFF_SELECTED, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IEditor *VcsSubmitEditorFactory::createEditor()
|
|
||||||
{
|
|
||||||
VcsBaseSubmitEditor *editor = m_editorCreator();
|
|
||||||
editor->registerActions(m_undoAction, m_redoAction, m_submitAction, m_diffAction);
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace VcsBase
|
} // namespace VcsBase
|
||||||
|
@@ -51,10 +51,7 @@ public:
|
|||||||
const EditorCreator &editorCreator,
|
const EditorCreator &editorCreator,
|
||||||
VcsBasePluginPrivate *plugin);
|
VcsBasePluginPrivate *plugin);
|
||||||
|
|
||||||
Core::IEditor *createEditor() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EditorCreator m_editorCreator;
|
|
||||||
QAction *m_submitAction = nullptr;
|
QAction *m_submitAction = nullptr;
|
||||||
QAction *m_diffAction = nullptr;
|
QAction *m_diffAction = nullptr;
|
||||||
QAction *m_undoAction = nullptr;
|
QAction *m_undoAction = nullptr;
|
||||||
|
Reference in New Issue
Block a user