diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index b6981823a55..f5272a81a29 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -24,6 +24,7 @@ #include "texteditorconstants.h" #include "texteditorsettings.h" #include "texteditortr.h" +#include "textmark.h" #ifdef WITH_TESTS #include "codeassist/codeassist_test.h" @@ -291,11 +292,6 @@ public: TextEditorPluginPrivate *d = nullptr; }; -QObject *pluginInstance() -{ - return m_instance; -} - void TextEditorPlugin::initialize() { #ifdef WITH_TESTS @@ -305,6 +301,7 @@ void TextEditorPlugin::initialize() addTestCreator(createSnippetParserTest); #endif + setupTextMarkRegistry(this); setupOutlineFactory(); d = new TextEditorPluginPrivate; diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h index 35376c3b584..3a3f61fb46d 100644 --- a/src/plugins/texteditor/texteditorplugin.h +++ b/src/plugins/texteditor/texteditorplugin.h @@ -10,6 +10,4 @@ namespace TextEditor::Internal { class LineNumberFilter; LineNumberFilter *lineNumberFilter(); -QObject *pluginInstance(); - } // TextEditor::Internal diff --git a/src/plugins/texteditor/textmark.cpp b/src/plugins/texteditor/textmark.cpp index 2dd9deefd53..d988fdb5c23 100644 --- a/src/plugins/texteditor/textmark.cpp +++ b/src/plugins/texteditor/textmark.cpp @@ -33,13 +33,13 @@ class TextMarkRegistry : public QObject { Q_OBJECT public: + TextMarkRegistry(QObject *parent); + static void add(TextMark *mark); static void add(TextMark *mark, TextDocument *document); static bool remove(TextMark *mark); private: - TextMarkRegistry(QObject *parent); - static TextMarkRegistry* instance(); void editorOpened(Core::IEditor *editor); void documentRenamed(Core::IDocument *document, const FilePath &oldPath, @@ -49,6 +49,8 @@ private: QHash > m_marks; }; +TextMarkRegistry *m_instance = nullptr; + class AnnotationColors { public: @@ -64,8 +66,6 @@ private: static QHash m_colorCache; }; -TextMarkRegistry *m_instance = nullptr; - TextMark::TextMark(const FilePath &filePath, int lineNumber, TextMarkCategory category) : m_fileName(filePath) , m_lineNumber(lineNumber) @@ -464,6 +464,8 @@ void TextMark::setIsLocationMarker(bool newIsLocationMarker) TextMarkRegistry::TextMarkRegistry(QObject *parent) : QObject(parent) { + m_instance = this; + connect(EditorManager::instance(), &EditorManager::editorOpened, this, &TextMarkRegistry::editorOpened); @@ -480,21 +482,14 @@ void TextMarkRegistry::add(TextMark *mark) void TextMarkRegistry::add(TextMark *mark, TextDocument *document) { - instance()->m_marks[mark->filePath()].insert(mark); + m_instance->m_marks[mark->filePath()].insert(mark); if (document) document->addMark(mark); } bool TextMarkRegistry::remove(TextMark *mark) { - return instance()->m_marks[mark->filePath()].remove(mark); -} - -TextMarkRegistry *TextMarkRegistry::instance() -{ - if (!m_instance) - m_instance = new TextMarkRegistry(pluginInstance()); - return m_instance; + return m_instance->m_marks[mark->filePath()].remove(mark); } void TextMarkRegistry::editorOpened(IEditor *editor) @@ -574,6 +569,11 @@ AnnotationColors &AnnotationColors::getAnnotationColors(const QColor &markColor, return colors; } +void setupTextMarkRegistry(QObject *guard) +{ + (void) new TextMarkRegistry(guard); +} + } // namespace TextEditor #include "textmark.moc" diff --git a/src/plugins/texteditor/textmark.h b/src/plugins/texteditor/textmark.h index b04e98ba5c3..27b0ef5e5cc 100644 --- a/src/plugins/texteditor/textmark.h +++ b/src/plugins/texteditor/textmark.h @@ -152,4 +152,6 @@ private: friend class TextDocumentLayout; }; +void setupTextMarkRegistry(QObject *guard); + } // namespace TextEditor