TextEditor: Hide plugin class definition in .cpp

Change-Id: Ib796333a0c46311fbead63de0e4562918d14a59f
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-01-17 09:56:06 +01:00
parent f662009bca
commit a9621ef1fd
4 changed files with 36 additions and 41 deletions

View File

@@ -188,7 +188,7 @@ void TextEditorActionHandlerPrivate::createActions()
registerAction(SELECTALL,
[] (TextEditorWidget *w) { w->selectAll(); }, true);
registerAction(GOTO, [](TextEditorWidget *) {
LocatorManager::showFilter(TextEditorPlugin::lineNumberFilter());
LocatorManager::showFilter(lineNumberFilter());
});
m_modifyingActions << registerAction(PRINT, [](TextEditorWidget *widget) {
widget->print(ICore::printer());

View File

@@ -16,7 +16,6 @@
#include "markdowneditor.h"
#include "outlinefactory.h"
#include "plaintexteditorfactory.h"
#include "snippets/snippet.h"
#include "snippets/snippetprovider.h"
#include "tabsettings.h"
#include "textdocument.h"
@@ -43,6 +42,7 @@
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/iplugin.h>
#include <utils/fancylineedit.h>
#include <utils/qtcassert.h>
@@ -263,22 +263,35 @@ void TextEditorPluginPrivate::requestContextMenu(TextEditorWidget *widget,
menu->addAction(&m_editBookmarkAction);
}
static TextEditorPlugin *m_instance = nullptr;
static class TextEditorPlugin *m_instance = nullptr;
TextEditorPlugin::TextEditorPlugin()
class TextEditorPlugin final : public ExtensionSystem::IPlugin
{
QTC_ASSERT(!m_instance, return);
m_instance = this;
}
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TextEditor.json")
TextEditorPlugin::~TextEditorPlugin()
{
delete d;
d = nullptr;
m_instance = nullptr;
}
public:
TextEditorPlugin()
{
m_instance = this;
}
TextEditorPlugin *TextEditorPlugin::instance()
~TextEditorPlugin() final
{
delete d;
d = nullptr;
m_instance = nullptr;
}
ShutdownFlag aboutToShutdown() final;
void initialize() final;
void extensionsInitialized() final;
TextEditorPluginPrivate *d = nullptr;
};
QObject *pluginInstance()
{
return m_instance;
}
@@ -439,7 +452,7 @@ void TextEditorPlugin::extensionsInitialized()
});
}
LineNumberFilter *TextEditorPlugin::lineNumberFilter()
LineNumberFilter *lineNumberFilter()
{
return &m_instance->d->lineNumberFilter;
}
@@ -532,3 +545,5 @@ void TextEditorPluginPrivate::createStandardContextMenu()
}
} // namespace TextEditor::Internal
#include "texteditorplugin.moc"

View File

@@ -3,33 +3,13 @@
#pragma once
#include <extensionsystem/iplugin.h>
#include <QObject>
namespace TextEditor {
namespace Internal {
namespace TextEditor::Internal {
class LineNumberFilter;
LineNumberFilter *lineNumberFilter();
class TextEditorPlugin final : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "TextEditor.json")
QObject *pluginInstance();
public:
TextEditorPlugin();
~TextEditorPlugin() final;
static TextEditorPlugin *instance();
static LineNumberFilter *lineNumberFilter();
ShutdownFlag aboutToShutdown() override;
private:
void initialize() final;
void extensionsInitialized() final;
class TextEditorPluginPrivate *d = nullptr;
};
} // namespace Internal
} // namespace TextEditor
} // TextEditor::Internal

View File

@@ -493,7 +493,7 @@ bool TextMarkRegistry::remove(TextMark *mark)
TextMarkRegistry *TextMarkRegistry::instance()
{
if (!m_instance)
m_instance = new TextMarkRegistry(TextEditorPlugin::instance());
m_instance = new TextMarkRegistry(pluginInstance());
return m_instance;
}