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 "texteditorconstants.h"
|
||||||
#include "texteditorsettings.h"
|
#include "texteditorsettings.h"
|
||||||
#include "texteditortr.h"
|
#include "texteditortr.h"
|
||||||
|
#include "textmark.h"
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
#include "codeassist/codeassist_test.h"
|
#include "codeassist/codeassist_test.h"
|
||||||
@@ -291,11 +292,6 @@ public:
|
|||||||
TextEditorPluginPrivate *d = nullptr;
|
TextEditorPluginPrivate *d = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
QObject *pluginInstance()
|
|
||||||
{
|
|
||||||
return m_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextEditorPlugin::initialize()
|
void TextEditorPlugin::initialize()
|
||||||
{
|
{
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
@@ -305,6 +301,7 @@ void TextEditorPlugin::initialize()
|
|||||||
addTestCreator(createSnippetParserTest);
|
addTestCreator(createSnippetParserTest);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
setupTextMarkRegistry(this);
|
||||||
setupOutlineFactory();
|
setupOutlineFactory();
|
||||||
|
|
||||||
d = new TextEditorPluginPrivate;
|
d = new TextEditorPluginPrivate;
|
||||||
|
@@ -10,6 +10,4 @@ namespace TextEditor::Internal {
|
|||||||
class LineNumberFilter;
|
class LineNumberFilter;
|
||||||
LineNumberFilter *lineNumberFilter();
|
LineNumberFilter *lineNumberFilter();
|
||||||
|
|
||||||
QObject *pluginInstance();
|
|
||||||
|
|
||||||
} // TextEditor::Internal
|
} // TextEditor::Internal
|
||||||
|
@@ -33,13 +33,13 @@ class TextMarkRegistry : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
TextMarkRegistry(QObject *parent);
|
||||||
|
|
||||||
static void add(TextMark *mark);
|
static void add(TextMark *mark);
|
||||||
static void add(TextMark *mark, TextDocument *document);
|
static void add(TextMark *mark, TextDocument *document);
|
||||||
static bool remove(TextMark *mark);
|
static bool remove(TextMark *mark);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextMarkRegistry(QObject *parent);
|
|
||||||
static TextMarkRegistry* instance();
|
|
||||||
void editorOpened(Core::IEditor *editor);
|
void editorOpened(Core::IEditor *editor);
|
||||||
void documentRenamed(Core::IDocument *document,
|
void documentRenamed(Core::IDocument *document,
|
||||||
const FilePath &oldPath,
|
const FilePath &oldPath,
|
||||||
@@ -49,6 +49,8 @@ private:
|
|||||||
QHash<Utils::FilePath, QSet<TextMark *> > m_marks;
|
QHash<Utils::FilePath, QSet<TextMark *> > m_marks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TextMarkRegistry *m_instance = nullptr;
|
||||||
|
|
||||||
class AnnotationColors
|
class AnnotationColors
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -64,8 +66,6 @@ private:
|
|||||||
static QHash<SourceColors, AnnotationColors> m_colorCache;
|
static QHash<SourceColors, AnnotationColors> m_colorCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextMarkRegistry *m_instance = nullptr;
|
|
||||||
|
|
||||||
TextMark::TextMark(const FilePath &filePath, int lineNumber, TextMarkCategory category)
|
TextMark::TextMark(const FilePath &filePath, int lineNumber, TextMarkCategory category)
|
||||||
: m_fileName(filePath)
|
: m_fileName(filePath)
|
||||||
, m_lineNumber(lineNumber)
|
, m_lineNumber(lineNumber)
|
||||||
@@ -464,6 +464,8 @@ void TextMark::setIsLocationMarker(bool newIsLocationMarker)
|
|||||||
TextMarkRegistry::TextMarkRegistry(QObject *parent)
|
TextMarkRegistry::TextMarkRegistry(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
|
m_instance = this;
|
||||||
|
|
||||||
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
||||||
this, &TextMarkRegistry::editorOpened);
|
this, &TextMarkRegistry::editorOpened);
|
||||||
|
|
||||||
@@ -480,21 +482,14 @@ void TextMarkRegistry::add(TextMark *mark)
|
|||||||
|
|
||||||
void TextMarkRegistry::add(TextMark *mark, TextDocument *document)
|
void TextMarkRegistry::add(TextMark *mark, TextDocument *document)
|
||||||
{
|
{
|
||||||
instance()->m_marks[mark->filePath()].insert(mark);
|
m_instance->m_marks[mark->filePath()].insert(mark);
|
||||||
if (document)
|
if (document)
|
||||||
document->addMark(mark);
|
document->addMark(mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextMarkRegistry::remove(TextMark *mark)
|
bool TextMarkRegistry::remove(TextMark *mark)
|
||||||
{
|
{
|
||||||
return instance()->m_marks[mark->filePath()].remove(mark);
|
return m_instance->m_marks[mark->filePath()].remove(mark);
|
||||||
}
|
|
||||||
|
|
||||||
TextMarkRegistry *TextMarkRegistry::instance()
|
|
||||||
{
|
|
||||||
if (!m_instance)
|
|
||||||
m_instance = new TextMarkRegistry(pluginInstance());
|
|
||||||
return m_instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextMarkRegistry::editorOpened(IEditor *editor)
|
void TextMarkRegistry::editorOpened(IEditor *editor)
|
||||||
@@ -574,6 +569,11 @@ AnnotationColors &AnnotationColors::getAnnotationColors(const QColor &markColor,
|
|||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setupTextMarkRegistry(QObject *guard)
|
||||||
|
{
|
||||||
|
(void) new TextMarkRegistry(guard);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|
||||||
#include "textmark.moc"
|
#include "textmark.moc"
|
||||||
|
@@ -152,4 +152,6 @@ private:
|
|||||||
friend class TextDocumentLayout;
|
friend class TextDocumentLayout;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void setupTextMarkRegistry(QObject *guard);
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
Reference in New Issue
Block a user