forked from qt-creator/qt-creator
TextEditor: Setup TextMarkFactory more canonically
Change-Id: Iaa360615c47ed7c4c3e2ace95ad53006e99aa2d0 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -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;
|
||||
|
@@ -10,6 +10,4 @@ namespace TextEditor::Internal {
|
||||
class LineNumberFilter;
|
||||
LineNumberFilter *lineNumberFilter();
|
||||
|
||||
QObject *pluginInstance();
|
||||
|
||||
} // TextEditor::Internal
|
||||
|
@@ -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<Utils::FilePath, QSet<TextMark *> > m_marks;
|
||||
};
|
||||
|
||||
TextMarkRegistry *m_instance = nullptr;
|
||||
|
||||
class AnnotationColors
|
||||
{
|
||||
public:
|
||||
@@ -64,8 +66,6 @@ private:
|
||||
static QHash<SourceColors, AnnotationColors> 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"
|
||||
|
@@ -152,4 +152,6 @@ private:
|
||||
friend class TextDocumentLayout;
|
||||
};
|
||||
|
||||
void setupTextMarkRegistry(QObject *guard);
|
||||
|
||||
} // namespace TextEditor
|
||||
|
Reference in New Issue
Block a user