forked from qt-creator/qt-creator
BinEditor: Re-organize plugin setup
Adapt to recent development. Change-Id: I9c121e5b793469e5dae319ea50d74c59f6ee68b9 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -2340,33 +2340,22 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////// BinEditorPluginPrivate //////////////////////////////////
|
static FactoryServiceImpl &binEditorService()
|
||||||
|
{
|
||||||
|
static FactoryServiceImpl theFactoryService;
|
||||||
|
return theFactoryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////// BinEditorFactory //////////////////////////////////
|
||||||
|
|
||||||
class BinEditorFactory final : public QObject, public IEditorFactory
|
class BinEditorFactory final : public QObject, public IEditorFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BinEditorFactory();
|
BinEditorFactory()
|
||||||
};
|
|
||||||
|
|
||||||
class BinEditorPluginPrivate : public QObject
|
|
||||||
{
|
{
|
||||||
public:
|
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
|
||||||
BinEditorPluginPrivate();
|
setDisplayName(::Core::Tr::tr("Binary Editor"));
|
||||||
~BinEditorPluginPrivate() override;
|
addMimeType(Utils::Constants::OCTET_STREAM_MIMETYPE);
|
||||||
|
|
||||||
QAction *m_undoAction = nullptr;
|
|
||||||
QAction *m_redoAction = nullptr;
|
|
||||||
QAction *m_copyAction = nullptr;
|
|
||||||
QAction *m_selectAllAction = nullptr;
|
|
||||||
|
|
||||||
FactoryServiceImpl m_factoryService;
|
|
||||||
BinEditorFactory m_editorFactory;
|
|
||||||
};
|
|
||||||
|
|
||||||
BinEditorPluginPrivate::BinEditorPluginPrivate()
|
|
||||||
{
|
|
||||||
ExtensionSystem::PluginManager::addObject(&m_factoryService);
|
|
||||||
ExtensionSystem::PluginManager::addObject(&m_editorFactory);
|
|
||||||
|
|
||||||
m_undoAction = new QAction(Tr::tr("&Undo"), this);
|
m_undoAction = new QAction(Tr::tr("&Undo"), this);
|
||||||
m_redoAction = new QAction(Tr::tr("&Redo"), this);
|
m_redoAction = new QAction(Tr::tr("&Redo"), this);
|
||||||
@@ -2381,37 +2370,20 @@ BinEditorPluginPrivate::BinEditorPluginPrivate()
|
|||||||
ActionManager::registerAction(m_redoAction, Core::Constants::REDO, context);
|
ActionManager::registerAction(m_redoAction, Core::Constants::REDO, context);
|
||||||
ActionManager::registerAction(m_copyAction, Core::Constants::COPY, context);
|
ActionManager::registerAction(m_copyAction, Core::Constants::COPY, context);
|
||||||
ActionManager::registerAction(m_selectAllAction, Core::Constants::SELECTALL, context);
|
ActionManager::registerAction(m_selectAllAction, Core::Constants::SELECTALL, context);
|
||||||
}
|
|
||||||
|
|
||||||
BinEditorPluginPrivate::~BinEditorPluginPrivate()
|
setEditorCreator([this] {
|
||||||
{
|
|
||||||
ExtensionSystem::PluginManager::removeObject(&m_editorFactory);
|
|
||||||
ExtensionSystem::PluginManager::removeObject(&m_factoryService);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BinEditorPluginPrivate *dd = nullptr;
|
|
||||||
|
|
||||||
///////////////////////////////// BinEditorFactory //////////////////////////////////
|
|
||||||
|
|
||||||
BinEditorFactory::BinEditorFactory()
|
|
||||||
{
|
|
||||||
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
|
|
||||||
setDisplayName(::Core::Tr::tr("Binary Editor"));
|
|
||||||
addMimeType(Utils::Constants::OCTET_STREAM_MIMETYPE);
|
|
||||||
|
|
||||||
setEditorCreator([] {
|
|
||||||
auto widget = new BinEditorWidget();
|
auto widget = new BinEditorWidget();
|
||||||
auto editor = new BinEditorImpl(widget);
|
auto editor = new BinEditorImpl(widget);
|
||||||
|
|
||||||
connect(dd->m_undoAction, &QAction::triggered, widget, &BinEditorWidget::undo);
|
connect(m_undoAction, &QAction::triggered, widget, &BinEditorWidget::undo);
|
||||||
connect(dd->m_redoAction, &QAction::triggered, widget, &BinEditorWidget::redo);
|
connect(m_redoAction, &QAction::triggered, widget, &BinEditorWidget::redo);
|
||||||
connect(dd->m_copyAction, &QAction::triggered, widget, &BinEditorWidget::copy);
|
connect(m_copyAction, &QAction::triggered, widget, &BinEditorWidget::copy);
|
||||||
connect(dd->m_selectAllAction, &QAction::triggered, widget, &BinEditorWidget::selectAll);
|
connect(m_selectAllAction, &QAction::triggered, widget, &BinEditorWidget::selectAll);
|
||||||
|
|
||||||
auto updateActions = [widget] {
|
auto updateActions = [this, widget] {
|
||||||
dd->m_selectAllAction->setEnabled(true);
|
m_selectAllAction->setEnabled(true);
|
||||||
dd->m_undoAction->setEnabled(widget->isUndoAvailable());
|
m_undoAction->setEnabled(widget->isUndoAvailable());
|
||||||
dd->m_redoAction->setEnabled(widget->isRedoAvailable());
|
m_redoAction->setEnabled(widget->isRedoAvailable());
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(widget, &BinEditorWidget::undoAvailable, widget, updateActions);
|
connect(widget, &BinEditorWidget::undoAvailable, widget, updateActions);
|
||||||
@@ -2426,6 +2398,19 @@ BinEditorFactory::BinEditorFactory()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QAction *m_undoAction = nullptr;
|
||||||
|
QAction *m_redoAction = nullptr;
|
||||||
|
QAction *m_copyAction = nullptr;
|
||||||
|
QAction *m_selectAllAction = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
static BinEditorFactory &binEditorFactory()
|
||||||
|
{
|
||||||
|
static BinEditorFactory theBinEditorFactory;
|
||||||
|
return theBinEditorFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////// BinEditorPlugin //////////////////////////////////
|
///////////////////////////////// BinEditorPlugin //////////////////////////////////
|
||||||
|
|
||||||
class BinEditorPlugin final : public ExtensionSystem::IPlugin
|
class BinEditorPlugin final : public ExtensionSystem::IPlugin
|
||||||
@@ -2433,15 +2418,16 @@ class BinEditorPlugin final : public ExtensionSystem::IPlugin
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "BinEditor.json")
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "BinEditor.json")
|
||||||
|
|
||||||
~BinEditorPlugin() override
|
~BinEditorPlugin() final
|
||||||
{
|
{
|
||||||
delete dd;
|
ExtensionSystem::PluginManager::removeObject(&binEditorService());
|
||||||
dd = nullptr;
|
ExtensionSystem::PluginManager::removeObject(&binEditorFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize() final
|
void initialize() final
|
||||||
{
|
{
|
||||||
dd = new BinEditorPluginPrivate;
|
ExtensionSystem::PluginManager::addObject(&binEditorService());
|
||||||
|
ExtensionSystem::PluginManager::addObject(&binEditorFactory());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user