From 5ece12d4ea9291f1063b9c7ec71fb9764537cfdb Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 4 Nov 2019 10:03:27 +0100 Subject: Highlighter: clarify 'Update Definitions' action by renaming it to Download Definitions and adding a tooltip stating that it collects all definitions that are missing or were updated after the release and downloads it to the ksyntax highlighting user folder. Also adding a separate reload definitions button in the settings behind the user path. Change-Id: I059cc98e33147cae910fa4fdb35631d1dca81448 Reviewed-by: Leena Miettinen Reviewed-by: Eike Ziller --- src/plugins/texteditor/highlighter.cpp | 15 ++++++++++++++- src/plugins/texteditor/highlighter.h | 3 ++- src/plugins/texteditor/highlightersettingspage.cpp | 9 ++++++--- src/plugins/texteditor/highlightersettingspage.ui | 17 +++++++++++++++-- src/plugins/texteditor/texteditor.cpp | 6 +++--- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/plugins/texteditor/highlighter.cpp b/src/plugins/texteditor/highlighter.cpp index 1a12d96882..09f9b88ff9 100644 --- a/src/plugins/texteditor/highlighter.cpp +++ b/src/plugins/texteditor/highlighter.cpp @@ -29,7 +29,9 @@ #include "textdocumentlayout.h" #include "tabsettings.h" #include "texteditorsettings.h" +#include "texteditor.h" +#include #include #include #include @@ -250,7 +252,7 @@ void Highlighter::addCustomHighlighterPath(const Utils::FilePath &path) highlightRepository()->addCustomSearchPath(path.toString()); } -void Highlighter::updateDefinitions(std::function callback) { +void Highlighter::downloadDefinitions(std::function callback) { auto downloader = new KSyntaxHighlighting::DefinitionDownloader(highlightRepository()); connect(downloader, &KSyntaxHighlighting::DefinitionDownloader::done, @@ -271,6 +273,17 @@ void Highlighter::updateDefinitions(std::function callback) { downloader->start(); } +void Highlighter::reload() +{ + highlightRepository()->reload(); + for (auto editor : Core::DocumentModel::editorsForOpenedDocuments()) { + if (auto textEditor = qobject_cast(editor)) { + if (qobject_cast(textEditor->textDocument()->syntaxHighlighter())) + textEditor->editorWidget()->configureGenericHighlighter(); + } + } +} + void Highlighter::handleShutdown() { delete highlightRepository(); diff --git a/src/plugins/texteditor/highlighter.h b/src/plugins/texteditor/highlighter.h index e0ddc8132d..0a23009c23 100644 --- a/src/plugins/texteditor/highlighter.h +++ b/src/plugins/texteditor/highlighter.h @@ -58,7 +58,8 @@ public: static void clearDefintionForDocumentCache(); static void addCustomHighlighterPath(const Utils::FilePath &path); - static void updateDefinitions(std::function callback = nullptr); + static void downloadDefinitions(std::function callback = nullptr); + static void reload(); static void handleShutdown(); diff --git a/src/plugins/texteditor/highlightersettingspage.cpp b/src/plugins/texteditor/highlightersettingspage.cpp index 86a1a7fdbf..20cfa591ea 100644 --- a/src/plugins/texteditor/highlightersettingspage.cpp +++ b/src/plugins/texteditor/highlightersettingspage.cpp @@ -104,14 +104,17 @@ QWidget *HighlighterSettingsPage::widget() m_d->m_page->setupUi(m_d->m_widget); m_d->m_page->definitionFilesPath->setExpectedKind(Utils::PathChooser::ExistingDirectory); m_d->m_page->definitionFilesPath->setHistoryCompleter(QLatin1String("TextEditor.Highlighter.History")); - connect(m_d->m_page->updateDefinitions, + connect(m_d->m_page->downloadDefinitions, &QPushButton::pressed, [label = QPointer(m_d->m_page->updateStatus)]() { - Highlighter::updateDefinitions([label](){ + Highlighter::downloadDefinitions([label](){ if (label) - label->setText(tr("Update finished")); + label->setText(tr("Download finished")); }); }); + connect(m_d->m_page->reloadDefinitions, &QPushButton::pressed, []() { + Highlighter::reload(); + }); connect(m_d->m_page->resetCache, &QPushButton::clicked, []() { Highlighter::clearDefintionForDocumentCache(); }); diff --git a/src/plugins/texteditor/highlightersettingspage.ui b/src/plugins/texteditor/highlightersettingspage.ui index 7b1e6c9e0d..5bd32a8a87 100644 --- a/src/plugins/texteditor/highlightersettingspage.ui +++ b/src/plugins/texteditor/highlightersettingspage.ui @@ -64,9 +64,12 @@ - + + + Download missing and update existing syntax definition files. + - Update Definitions + Download Definitions @@ -108,6 +111,16 @@ + + + + Reload externally modified definition files. + + + Reload Definitions + + + diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 1419b045c2..b03cef1de3 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -3100,11 +3100,11 @@ void TextEditorWidgetPrivate::updateSyntaxInfoBar(const Highlighter::Definitions && !TextEditorSettings::highlighterSettings().isIgnoredFilePattern(fileName)) { InfoBarEntry info(missing, BaseTextEditor::tr("A highlight definition was not found for this file. " - "Would you like to update highlight definition files?"), + "Would you like to download additional highlight definition files?"), InfoBarEntry::GlobalSuppression::Enabled); - info.setCustomButtonInfo(BaseTextEditor::tr("Update Definitions"), [missing, this]() { + info.setCustomButtonInfo(BaseTextEditor::tr("Download Definitions"), [missing, this]() { m_document->infoBar()->removeInfo(missing); - Highlighter::updateDefinitions([widget = QPointer(q)]() { + Highlighter::downloadDefinitions([widget = QPointer(q)]() { if (widget) widget->configureGenericHighlighter(); }); -- cgit v1.2.1