forked from qt-creator/qt-creator
TextEditor: add option to remember highlighter definition
Add a button to the multiple definition found info that saves the definition of the current highlighter for the open document. Change-Id: I04b1b7571a864d781747547a1d315ec25bb6b5a1 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
@@ -613,6 +613,7 @@ public:
|
||||
void reconfigure();
|
||||
void updateSyntaxInfoBar(const Highlighter::Definitions &definitions, const QString &fileName);
|
||||
void configureGenericHighlighter(const KSyntaxHighlighting::Definition &definition);
|
||||
void rememberCurrentSyntaxDefinition();
|
||||
|
||||
public:
|
||||
TextEditorWidget *q;
|
||||
@@ -3306,6 +3307,11 @@ void TextEditorWidgetPrivate::updateSyntaxInfoBar(const Highlighter::Definitions
|
||||
this->configureGenericHighlighter(Highlighter::definitionForName(definition));
|
||||
});
|
||||
|
||||
info.setCustomButtonInfo(BaseTextEditor::tr("Remember My Choice"), [multiple, this]() {
|
||||
m_document->infoBar()->removeInfo(multiple);
|
||||
rememberCurrentSyntaxDefinition();
|
||||
});
|
||||
|
||||
infoBar->removeInfo(missing);
|
||||
infoBar->addInfo(info);
|
||||
} else {
|
||||
@@ -3333,6 +3339,16 @@ void TextEditorWidgetPrivate::configureGenericHighlighter(
|
||||
m_document->setFontSettings(TextEditorSettings::fontSettings());
|
||||
}
|
||||
|
||||
void TextEditorWidgetPrivate::rememberCurrentSyntaxDefinition()
|
||||
{
|
||||
auto highlighter = qobject_cast<Highlighter *>(m_document->syntaxHighlighter());
|
||||
if (!highlighter)
|
||||
return;
|
||||
const Highlighter::Definition &definition = highlighter->definition();
|
||||
if (definition.isValid())
|
||||
Highlighter::rememberDefintionForDocument(definition, m_document.data());
|
||||
}
|
||||
|
||||
bool TextEditorWidget::codeFoldingVisible() const
|
||||
{
|
||||
return d->m_codeFoldingVisible;
|
||||
@@ -8543,7 +8559,7 @@ QString TextEditorWidget::textAt(int from, int to) const
|
||||
|
||||
void TextEditorWidget::configureGenericHighlighter()
|
||||
{
|
||||
const Highlighter::Definitions definitions = Highlighter::definitionsForDocument(textDocument());
|
||||
Highlighter::Definitions definitions = Highlighter::definitionsForDocument(textDocument());
|
||||
d->configureGenericHighlighter(definitions.isEmpty() ? Highlighter::Definition()
|
||||
: definitions.first());
|
||||
d->updateSyntaxInfoBar(definitions, textDocument()->filePath().fileName());
|
||||
|
||||
Reference in New Issue
Block a user