forked from qt-creator/qt-creator
TextEditor: add highlighter configure based on mimetype
The default implementation configures the generic highlighter based on the documents file name and content. Add a way to force the highlighter to use a highlight definition for a specific mime type. Change-Id: I1c6fca1be9bcb5c4276b5aa2dbb724680fe98ddc Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -642,6 +642,7 @@ public:
|
|||||||
|
|
||||||
void reconfigure();
|
void reconfigure();
|
||||||
void updateSyntaxInfoBar(const Highlighter::Definitions &definitions, const QString &fileName);
|
void updateSyntaxInfoBar(const Highlighter::Definitions &definitions, const QString &fileName);
|
||||||
|
void removeSyntaxInfoBar();
|
||||||
void configureGenericHighlighter(const KSyntaxHighlighting::Definition &definition);
|
void configureGenericHighlighter(const KSyntaxHighlighting::Definition &definition);
|
||||||
void rememberCurrentSyntaxDefinition();
|
void rememberCurrentSyntaxDefinition();
|
||||||
void openLinkUnderCursor(bool openInNextSplit);
|
void openLinkUnderCursor(bool openInNextSplit);
|
||||||
@@ -3263,6 +3264,13 @@ void TextEditorWidgetPrivate::updateSyntaxInfoBar(const Highlighter::Definitions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorWidgetPrivate::removeSyntaxInfoBar()
|
||||||
|
{
|
||||||
|
InfoBar *infoBar = m_document->infoBar();
|
||||||
|
infoBar->removeInfo(Constants::INFO_MISSING_SYNTAX_DEFINITION);
|
||||||
|
infoBar->removeInfo(Constants::INFO_MULTIPLE_SYNTAX_DEFINITIONS);
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorWidgetPrivate::configureGenericHighlighter(
|
void TextEditorWidgetPrivate::configureGenericHighlighter(
|
||||||
const KSyntaxHighlighting::Definition &definition)
|
const KSyntaxHighlighting::Definition &definition)
|
||||||
{
|
{
|
||||||
@@ -8163,6 +8171,14 @@ void TextEditorWidget::configureGenericHighlighter()
|
|||||||
d->updateSyntaxInfoBar(definitions, textDocument()->filePath().fileName());
|
d->updateSyntaxInfoBar(definitions, textDocument()->filePath().fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorWidget::configureGenericHighlighter(const Utils::MimeType &mimeType)
|
||||||
|
{
|
||||||
|
Highlighter::Definitions definitions = Highlighter::definitionsForMimeType(mimeType.name());
|
||||||
|
d->configureGenericHighlighter(definitions.isEmpty() ? Highlighter::Definition()
|
||||||
|
: definitions.first());
|
||||||
|
d->removeSyntaxInfoBar();
|
||||||
|
}
|
||||||
|
|
||||||
int TextEditorWidget::blockNumberForVisibleRow(int row) const
|
int TextEditorWidget::blockNumberForVisibleRow(int row) const
|
||||||
{
|
{
|
||||||
QTextBlock block = blockForVisibleRow(row);
|
QTextBlock block = blockForVisibleRow(row);
|
||||||
|
@@ -457,7 +457,11 @@ public:
|
|||||||
/// Abort code assistant if it is running.
|
/// Abort code assistant if it is running.
|
||||||
void abortAssist();
|
void abortAssist();
|
||||||
|
|
||||||
|
/// Overwrite the current highlighter with a new generic highlighter based on the mimetype of
|
||||||
|
/// the current document
|
||||||
void configureGenericHighlighter();
|
void configureGenericHighlighter();
|
||||||
|
/// Overwrite the current highlighter with a new generic highlighter based on the given mimetype
|
||||||
|
void configureGenericHighlighter(const Utils::MimeType &mimeType);
|
||||||
|
|
||||||
Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim.
|
Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user