From baa1e3c2e15af93804fa0f8b3158b2422f25b585 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 9 Jan 2023 13:14:39 +0100 Subject: [PATCH] Editor: Allow to hide annotations for a group of text marks The hiding is not persistent, so on the next Qt Creator start all annotations are visible again. This is meant to quickly get rid of annotations if there are to many irrelevant of a specific kind. Change-Id: I4862e56e0f5624f30aadda26efc9dea672ab1f57 Reviewed-by: Christian Stenger --- src/plugins/autotest/testeditormark.cpp | 3 +- src/plugins/bookmarks/bookmark.cpp | 2 +- src/plugins/clangcodemodel/clangtextmark.cpp | 7 +++- src/plugins/clangtools/diagnosticmark.cpp | 3 +- .../clangtools/documentclangtoolrunner.cpp | 2 +- src/plugins/coco/cocolanguageclient.cpp | 2 +- src/plugins/cppcheck/cppchecktextmark.cpp | 13 +++--- src/plugins/cppeditor/cppeditordocument.cpp | 9 ++-- src/plugins/debugger/breakhandler.cpp | 10 ++++- src/plugins/debugger/debuggerengine.cpp | 4 +- src/plugins/debugger/disassembleragent.cpp | 6 ++- src/plugins/debugger/sourceagent.cpp | 7 +++- src/plugins/debugger/sourceutils.cpp | 5 ++- src/plugins/git/gitplugin.cpp | 4 +- .../languageclient/diagnosticmanager.cpp | 8 ++-- .../languageclient/languageclientsettings.cpp | 11 +++-- src/plugins/projectexplorer/taskhub.cpp | 9 ++-- src/plugins/qmljseditor/qmljstextmark.cpp | 5 ++- .../qmlprofiler/qmlprofilertextmark.cpp | 3 +- src/plugins/squish/squishtools.cpp | 2 +- src/plugins/texteditor/textdocument.cpp | 41 +++++++++++++++++++ src/plugins/texteditor/textdocument.h | 3 ++ src/plugins/texteditor/texteditor.cpp | 7 ++-- src/plugins/texteditor/textmark.cpp | 20 ++++++++- src/plugins/texteditor/textmark.h | 13 ++++-- src/plugins/valgrind/callgrindtextmark.cpp | 7 +++- 26 files changed, 159 insertions(+), 47 deletions(-) diff --git a/src/plugins/autotest/testeditormark.cpp b/src/plugins/autotest/testeditormark.cpp index 2b06f1f89b1..1ef4d231a0e 100644 --- a/src/plugins/autotest/testeditormark.cpp +++ b/src/plugins/autotest/testeditormark.cpp @@ -3,13 +3,14 @@ #include "testeditormark.h" +#include "autotesttr.h" #include "testresultspane.h" namespace Autotest { namespace Internal { TestEditorMark::TestEditorMark(QPersistentModelIndex item, const Utils::FilePath &file, int line) - : TextEditor::TextMark(file, line, Utils::Id(Constants::TASK_MARK_ID)), + : TextEditor::TextMark(file, line, {Tr::tr("Auto Test"), Utils::Id(Constants::TASK_MARK_ID)}), m_item(item) { } diff --git a/src/plugins/bookmarks/bookmark.cpp b/src/plugins/bookmarks/bookmark.cpp index ceb26990995..c6ded3986d0 100644 --- a/src/plugins/bookmarks/bookmark.cpp +++ b/src/plugins/bookmarks/bookmark.cpp @@ -16,7 +16,7 @@ using namespace Utils; namespace Bookmarks::Internal { Bookmark::Bookmark(int lineNumber, BookmarkManager *manager) : - TextMark(FilePath(), lineNumber, Constants::BOOKMARKS_TEXT_MARK_CATEGORY), + TextMark(FilePath(), lineNumber, {Tr::tr("Bookmark"), Constants::BOOKMARKS_TEXT_MARK_CATEGORY}), m_manager(manager) { setColor(Theme::Bookmarks_TextMarkColor); diff --git a/src/plugins/clangcodemodel/clangtextmark.cpp b/src/plugins/clangcodemodel/clangtextmark.cpp index 148ee98790b..db653711af3 100644 --- a/src/plugins/clangcodemodel/clangtextmark.cpp +++ b/src/plugins/clangcodemodel/clangtextmark.cpp @@ -271,9 +271,12 @@ ClangdTextMark::ClangdTextMark(const FilePath &filePath, const Diagnostic &diagnostic, bool isProjectFile, ClangdClient *client) - : TextEditor::TextMark(filePath, int(diagnostic.range().start().line() + 1), client->id()) + : TextEditor::TextMark(filePath, + int(diagnostic.range().start().line() + 1), + {client->name(), client->id()}) , m_lspDiagnostic(diagnostic) - , m_diagnostic(convertDiagnostic(ClangdDiagnostic(diagnostic), filePath, client->hostPathMapper())) + , m_diagnostic( + convertDiagnostic(ClangdDiagnostic(diagnostic), filePath, client->hostPathMapper())) , m_client(client) { setSettingsPage(CppEditor::Constants::CPP_CLANGD_SETTINGS_ID); diff --git a/src/plugins/clangtools/diagnosticmark.cpp b/src/plugins/clangtools/diagnosticmark.cpp index 1bed6ed682c..a1d60ef956e 100644 --- a/src/plugins/clangtools/diagnosticmark.cpp +++ b/src/plugins/clangtools/diagnosticmark.cpp @@ -4,6 +4,7 @@ #include "diagnosticmark.h" #include "clangtoolsconstants.h" +#include "clangtoolstr.h" #include "clangtoolsutils.h" #include "diagnosticconfigswidget.h" @@ -18,7 +19,7 @@ namespace Internal { DiagnosticMark::DiagnosticMark(const Diagnostic &diagnostic) : TextEditor::TextMark(diagnostic.location.filePath, diagnostic.location.line, - Utils::Id(Constants::DIAGNOSTIC_MARK_ID)) + {Tr::tr("Clang Tools"), Utils::Id(Constants::DIAGNOSTIC_MARK_ID)}) , m_diagnostic(diagnostic) { setSettingsPage(Constants::SETTINGS_PAGE_ID); diff --git a/src/plugins/clangtools/documentclangtoolrunner.cpp b/src/plugins/clangtools/documentclangtoolrunner.cpp index fd018643aad..11f01f31b6d 100644 --- a/src/plugins/clangtools/documentclangtoolrunner.cpp +++ b/src/plugins/clangtools/documentclangtoolrunner.cpp @@ -70,7 +70,7 @@ Diagnostics DocumentClangToolRunner::diagnosticsAtLine(int lineNumber) const Diagnostics diagnostics; if (auto textDocument = qobject_cast(m_document)) { for (auto mark : textDocument->marksAt(lineNumber)) { - if (mark->category() == Constants::DIAGNOSTIC_MARK_ID) + if (mark->category().id == Constants::DIAGNOSTIC_MARK_ID) diagnostics << static_cast(mark)->diagnostic(); } } diff --git a/src/plugins/coco/cocolanguageclient.cpp b/src/plugins/coco/cocolanguageclient.cpp index 6ed18a5b1d2..8d99e17154e 100644 --- a/src/plugins/coco/cocolanguageclient.cpp +++ b/src/plugins/coco/cocolanguageclient.cpp @@ -131,7 +131,7 @@ class CocoTextMark : public TextEditor::TextMark { public: CocoTextMark(const FilePath &fileName, const CocoDiagnostic &diag, const Id &clientId) - : TextEditor::TextMark(fileName, diag.range().start().line() + 1, clientId) + : TextEditor::TextMark(fileName, diag.range().start().line() + 1, {"Coco", clientId}) , m_severity(diag.cocoSeverity()) { setLineAnnotation(diag.message()); diff --git a/src/plugins/cppcheck/cppchecktextmark.cpp b/src/plugins/cppcheck/cppchecktextmark.cpp index cd6749b5cc2..fcfe6edf437 100644 --- a/src/plugins/cppcheck/cppchecktextmark.cpp +++ b/src/plugins/cppcheck/cppchecktextmark.cpp @@ -4,6 +4,7 @@ #include "cppcheckconstants.h" #include "cppcheckdiagnostic.h" #include "cppchecktextmark.h" +#include "cppchecktr.h" #include #include @@ -44,11 +45,13 @@ static Visual getVisual(Diagnostic::Severity type) return visuals.value(type, {Color::IconsInfoColor, Priority::LowPriority, Icons::INFO.icon()}); } -CppcheckTextMark::CppcheckTextMark (const Diagnostic &diagnostic) - : TextMark(diagnostic.fileName, diagnostic.lineNumber, Id(Constants::TEXTMARK_CATEGORY_ID)), - m_severity(diagnostic.severity), - m_checkId(diagnostic.checkId), - m_message(diagnostic.message) +CppcheckTextMark::CppcheckTextMark(const Diagnostic &diagnostic) + : TextEditor::TextMark(diagnostic.fileName, + diagnostic.lineNumber, + {Tr::tr("Cppcheck"), Utils::Id(Constants::TEXTMARK_CATEGORY_ID)}) + , m_severity(diagnostic.severity) + , m_checkId(diagnostic.checkId) + , m_message(diagnostic.message) { const Visual visual = getVisual(diagnostic.severity); setPriority(visual.priority); diff --git a/src/plugins/cppeditor/cppeditordocument.cpp b/src/plugins/cppeditor/cppeditordocument.cpp index d7039b2c2cc..239c3230d1e 100644 --- a/src/plugins/cppeditor/cppeditordocument.cpp +++ b/src/plugins/cppeditor/cppeditordocument.cpp @@ -11,6 +11,7 @@ #include "cppmodelmanager.h" #include "cppeditorconstants.h" #include "cppeditorplugin.h" +#include "cppeditortr.h" #include "cpphighlighter.h" #include "cppquickfixassistant.h" @@ -503,7 +504,7 @@ void CppEditorDocument::onDiagnosticsChanged(const QString &fileName, const QStr [&category, &diagnostic](TextMark *existing) { return (diagnostic.line() == existing->lineNumber() && diagnostic.text() == existing->lineAnnotation() - && category == existing->category()); + && category == existing->category().id); }); if (it != std::end(removedMarks)) { @@ -511,7 +512,9 @@ void CppEditorDocument::onDiagnosticsChanged(const QString &fileName, const QStr continue; } - auto mark = new TextMark(filePath(), diagnostic.line(), category); + auto mark = new TextMark(filePath(), + diagnostic.line(), + {Tr::tr("C++ Code Model"), category}); mark->setLineAnnotation(diagnostic.text()); mark->setToolTip(diagnostic.text()); @@ -526,7 +529,7 @@ void CppEditorDocument::onDiagnosticsChanged(const QString &fileName, const QStr } for (auto it = removedMarks.begin(); it != removedMarks.end(); ++it) { - if ((*it)->category() == category) { + if ((*it)->category().id == category) { removeMark(*it); delete *it; } diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp index 596ce2924c5..6581dfa39c9 100644 --- a/src/plugins/debugger/breakhandler.cpp +++ b/src/plugins/debugger/breakhandler.cpp @@ -68,7 +68,10 @@ class BreakpointMarker : public TextEditor::TextMark { public: BreakpointMarker(const Breakpoint &bp, const FilePath &fileName, int lineNumber) - : TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY_BREAKPOINT), m_bp(bp) + : TextMark(fileName, + lineNumber, + {Tr::tr("Breakpoint"), Constants::TEXT_MARK_CATEGORY_BREAKPOINT}) + , m_bp(bp) { setColor(Theme::Debugger_Breakpoint_TextMarkColor); setDefaultToolTip(Tr::tr("Breakpoint")); @@ -126,7 +129,10 @@ class GlobalBreakpointMarker : public TextEditor::TextMark { public: GlobalBreakpointMarker(GlobalBreakpoint gbp, const FilePath &fileName, int lineNumber) - : TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY_BREAKPOINT), m_gbp(gbp) + : TextMark(fileName, + lineNumber, + {Tr::tr("Breakpoint"), Constants::TEXT_MARK_CATEGORY_BREAKPOINT}) + , m_gbp(gbp) { setDefaultToolTip(Tr::tr("Breakpoint")); setPriority(TextEditor::TextMark::NormalPriority); diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp index a8757c96aa6..f9d6cfa005a 100644 --- a/src/plugins/debugger/debuggerengine.cpp +++ b/src/plugins/debugger/debuggerengine.cpp @@ -151,9 +151,9 @@ Location::Location(const StackFrame &frame, bool marker) m_from = frame.module; } - LocationMark::LocationMark(DebuggerEngine *engine, const FilePath &file, int line) - : TextMark(file, line, Constants::TEXT_MARK_CATEGORY_LOCATION), m_engine(engine) + : TextMark(file, line, {Tr::tr("Debugger Location"), Constants::TEXT_MARK_CATEGORY_LOCATION}) + , m_engine(engine) { setPriority(TextMark::HighPriority); setIsLocationMarker(true); diff --git a/src/plugins/debugger/disassembleragent.cpp b/src/plugins/debugger/disassembleragent.cpp index 7bbb715987e..d4e3caa6f1b 100644 --- a/src/plugins/debugger/disassembleragent.cpp +++ b/src/plugins/debugger/disassembleragent.cpp @@ -7,6 +7,7 @@ #include "debuggeractions.h" #include "debuggerengine.h" #include "debuggerinternalconstants.h" +#include "debuggertr.h" #include "disassemblerlines.h" #include "sourceutils.h" @@ -42,7 +43,10 @@ class DisassemblerBreakpointMarker : public TextMark { public: DisassemblerBreakpointMarker(const Breakpoint &bp, int lineNumber) - : TextMark(Utils::FilePath(), lineNumber, Constants::TEXT_MARK_CATEGORY_BREAKPOINT), m_bp(bp) + : TextMark(Utils::FilePath(), + lineNumber, + {Tr::tr("Breakpoint"), Constants::TEXT_MARK_CATEGORY_BREAKPOINT}) + , m_bp(bp) { setIcon(bp->icon()); setPriority(TextMark::NormalPriority); diff --git a/src/plugins/debugger/sourceagent.cpp b/src/plugins/debugger/sourceagent.cpp index 5e53e016425..fc55d6ff022 100644 --- a/src/plugins/debugger/sourceagent.cpp +++ b/src/plugins/debugger/sourceagent.cpp @@ -6,6 +6,7 @@ #include "debuggerengine.h" #include "debuggericons.h" #include "debuggerinternalconstants.h" +#include "debuggertr.h" #include "stackhandler.h" #include @@ -114,8 +115,10 @@ void SourceAgent::updateLocationMarker() if (d->engine->stackHandler()->currentFrame().file == Utils::FilePath::fromString(d->path)) { int lineNumber = d->engine->stackHandler()->currentFrame().line; - d->locationMark = new TextMark(Utils::FilePath(), lineNumber, - Constants::TEXT_MARK_CATEGORY_LOCATION); + d->locationMark = new TextMark(Utils::FilePath(), + lineNumber, + {Tr::tr("Debugger Location"), + Constants::TEXT_MARK_CATEGORY_LOCATION}); d->locationMark->setIcon(Icons::LOCATION.icon()); d->locationMark->setPriority(TextMark::HighPriority); diff --git a/src/plugins/debugger/sourceutils.cpp b/src/plugins/debugger/sourceutils.cpp index 07d2976c3f7..2149821662f 100644 --- a/src/plugins/debugger/sourceutils.cpp +++ b/src/plugins/debugger/sourceutils.cpp @@ -5,6 +5,7 @@ #include "debuggerinternalconstants.h" #include "debuggerengine.h" +#include "debuggertr.h" #include "disassemblerlines.h" #include "watchdata.h" #include "watchutils.h" @@ -333,7 +334,9 @@ class DebuggerValueMark : public TextEditor::TextMark { public: DebuggerValueMark(const FilePath &fileName, int lineNumber, const QString &value) - : TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY_VALUE) + : TextMark(fileName, + lineNumber, + {Tr::tr("Debugger Value"), Constants::TEXT_MARK_CATEGORY_VALUE}) { setPriority(TextEditor::TextMark::HighPriority); setToolTipProvider([] { return QString(); }); diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index fe17e5adc92..e92c4c36716 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -195,7 +195,9 @@ class BlameMark : public TextEditor::TextMark { public: BlameMark(const FilePath &fileName, int lineNumber, const CommitInfo &info) - : TextEditor::TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY_BLAME) + : TextEditor::TextMark(fileName, + lineNumber, + {Tr::tr("Git Blame"), Constants::TEXT_MARK_CATEGORY_BLAME}) { const QString text = info.shortAuthor + " " + info.authorTime.toString("yyyy-MM-dd"); diff --git a/src/plugins/languageclient/diagnosticmanager.cpp b/src/plugins/languageclient/diagnosticmanager.cpp index a02a1c7b441..6f518c70af8 100644 --- a/src/plugins/languageclient/diagnosticmanager.cpp +++ b/src/plugins/languageclient/diagnosticmanager.cpp @@ -30,8 +30,10 @@ namespace LanguageClient { class TextMark : public TextEditor::TextMark { public: - TextMark(const FilePath &fileName, const Diagnostic &diag, const Id &clientId) - : TextEditor::TextMark(fileName, diag.range().start().line() + 1, clientId) + TextMark(const FilePath &fileName, const Diagnostic &diag, const Client *client) + : TextEditor::TextMark(fileName, + diag.range().start().line() + 1, + {client->name(), client->id()}) { setLineAnnotation(diag.message()); setToolTip(diag.message()); @@ -121,7 +123,7 @@ TextEditor::TextMark *DiagnosticManager::createTextMark(const FilePath &filePath { static const auto icon = QIcon::fromTheme("edit-copy", Utils::Icons::COPY.icon()); static const QString tooltip = tr("Copy to Clipboard"); - auto mark = new TextMark(filePath, diagnostic, m_client->id()); + auto mark = new TextMark(filePath, diagnostic, m_client); mark->setActionsProvider([text = diagnostic.message()] { QAction *action = new QAction(); action->setIcon(icon); diff --git a/src/plugins/languageclient/languageclientsettings.cpp b/src/plugins/languageclient/languageclientsettings.cpp index e2827e5c4e7..ac98ffe834f 100644 --- a/src/plugins/languageclient/languageclientsettings.cpp +++ b/src/plugins/languageclient/languageclientsettings.cpp @@ -1061,8 +1061,11 @@ TextEditor::BaseTextEditor *jsonEditor() widget->setCodeFoldingSupported(false); QObject::connect(document, &TextDocument::contentsChanged, widget, [document](){ const Utils::Id jsonMarkId("LanguageClient.JsonTextMarkId"); - qDeleteAll( - Utils::filtered(document->marks(), Utils::equal(&TextMark::category, jsonMarkId))); + const TextMarks marks = document->marks(); + for (TextMark *mark : marks) { + if (mark->category().id == jsonMarkId) + delete mark; + } const QString content = document->plainText().trimmed(); if (content.isEmpty()) return; @@ -1074,7 +1077,9 @@ TextEditor::BaseTextEditor *jsonEditor() = Utils::Text::convertPosition(document->document(), error.offset); if (!lineColumn.has_value()) return; - auto mark = new TextMark(Utils::FilePath(), lineColumn->line, jsonMarkId); + auto mark = new TextMark(Utils::FilePath(), + lineColumn->line, + {Tr::tr("JSON Error"), jsonMarkId}); mark->setLineAnnotation(error.errorString()); mark->setColor(Utils::Theme::CodeModel_Error_TextMarkColor); mark->setIcon(Utils::Icons::CODEMODEL_ERROR.icon()); diff --git a/src/plugins/projectexplorer/taskhub.cpp b/src/plugins/projectexplorer/taskhub.cpp index fcef9da5d60..a9ebef81f8d 100644 --- a/src/plugins/projectexplorer/taskhub.cpp +++ b/src/plugins/projectexplorer/taskhub.cpp @@ -3,6 +3,7 @@ #include "taskhub.h" #include "projectexplorerconstants.h" +#include "projectexplorertr.h" #include #include @@ -25,15 +26,15 @@ const char TASK_MARK_ERROR[] = "Task.Mark.Error"; static TaskHub *m_instance = nullptr; QVector TaskHub::m_registeredCategories; -static Utils::Id categoryForType(Task::TaskType type) +static TextEditor::TextMarkCategory categoryForType(Task::TaskType type) { switch (type) { case Task::Error: - return TASK_MARK_ERROR; + return {Tr::tr("Taskhub Error", TASK_MARK_ERROR)}; case Task::Warning: - return TASK_MARK_WARNING; + return {Tr::tr("Taskhub Warning"), TASK_MARK_WARNING}; default: - return Utils::Id(); + return {}; } } diff --git a/src/plugins/qmljseditor/qmljstextmark.cpp b/src/plugins/qmljseditor/qmljstextmark.cpp index 003f8493b24..973e20913ce 100644 --- a/src/plugins/qmljseditor/qmljstextmark.cpp +++ b/src/plugins/qmljseditor/qmljstextmark.cpp @@ -33,9 +33,10 @@ static bool isWarning(QmlJS::Severity::Enum kind) return false; } -static Utils::Id cartegoryForSeverity(QmlJS::Severity::Enum kind) +static TextMarkCategory cartegoryForSeverity(QmlJS::Severity::Enum kind) { - return isWarning(kind) ? QMLJS_WARNING : QMLJS_ERROR; + return isWarning(kind) ? TextMarkCategory{"QML Warning", QMLJS_WARNING} + : TextMarkCategory{"QML Error", QMLJS_ERROR}; } QmlJSTextMark::QmlJSTextMark(const FilePath &fileName, diff --git a/src/plugins/qmlprofiler/qmlprofilertextmark.cpp b/src/plugins/qmlprofiler/qmlprofilertextmark.cpp index 827126c55d1..1f0bd927835 100644 --- a/src/plugins/qmlprofiler/qmlprofilertextmark.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertextmark.cpp @@ -6,6 +6,7 @@ #include "qmlprofilerconstants.h" #include "qmlprofilerviewmanager.h" #include "qmlprofilerstatisticsview.h" +#include "qmlprofilertr.h" #include #include @@ -18,7 +19,7 @@ namespace Internal { QmlProfilerTextMark::QmlProfilerTextMark(QmlProfilerViewManager *viewManager, int typeId, const FilePath &fileName, int lineNumber) - : TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY) + : TextMark(fileName, lineNumber, {Tr::tr("QML Profiler"), Constants::TEXT_MARK_CATEGORY}) , m_viewManager(viewManager) { addTypeId(typeId); diff --git a/src/plugins/squish/squishtools.cpp b/src/plugins/squish/squishtools.cpp index aefd8f27505..c31e9364ef6 100644 --- a/src/plugins/squish/squishtools.cpp +++ b/src/plugins/squish/squishtools.cpp @@ -87,7 +87,7 @@ class SquishLocationMark : public TextEditor::TextMark { public: SquishLocationMark(const FilePath &filePath, int line) - : TextEditor::TextMark(filePath, line, Id("Squish.LocationMark")) + : TextEditor::TextMark(filePath, line, {Tr::tr("Squish"), Id("Squish.LocationMark")}) { setIsLocationMarker(true); setIcon(Debugger::Icons::LOCATION.icon()); diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 155efc5d3c8..e69bdd9692f 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -1065,6 +1065,47 @@ void TextDocument::removeMarkFromMarksCache(TextMark *mark) documentLayout->requestExtraAreaUpdate(); } +static QSet &hiddenMarksIds() +{ + static QSet ids; + return ids; +} + +void TextDocument::temporaryHideMarksAnnotation(const Utils::Id &category) +{ + hiddenMarksIds().insert(category); + const QList documents = DocumentModel::openedDocuments(); + for (auto document : documents) { + if (auto textDocument = qobject_cast(document)) { + const TextMarks marks = textDocument->marks(); + for (const auto mark : marks) { + if (mark->category().id == category) + mark->updateMarker(); + } + } + } +} + +void TextDocument::showMarksAnnotation(const Utils::Id &category) +{ + hiddenMarksIds().remove(category); + const QList documents = DocumentModel::openedDocuments(); + for (auto document : documents) { + if (auto textDocument = qobject_cast(document)) { + const TextMarks marks = textDocument->marks(); + for (const auto mark : marks) { + if (mark->category().id == category) + mark->updateMarker(); + } + } + } +} + +bool TextDocument::marksAnnotationHidden(const Utils::Id &category) +{ + return hiddenMarksIds().contains(category); +} + void TextDocument::removeMark(TextMark *mark) { QTextBlock block = d->m_document.findBlockByNumber(mark->lineNumber() - 1); diff --git a/src/plugins/texteditor/textdocument.h b/src/plugins/texteditor/textdocument.h index b4385e47278..dc52e1e9a8e 100644 --- a/src/plugins/texteditor/textdocument.h +++ b/src/plugins/texteditor/textdocument.h @@ -95,6 +95,9 @@ public: void updateMark(TextMark *mark); void moveMark(TextMark *mark, int previousLine); void removeMarkFromMarksCache(TextMark *mark); + static void temporaryHideMarksAnnotation(const Utils::Id &category); + static void showMarksAnnotation(const Utils::Id &category); + static bool marksAnnotationHidden(const Utils::Id &category); // IDocument implementation. bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override; diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index e4e975a250b..74439da7546 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -4043,8 +4043,9 @@ void TextEditorWidgetPrivate::updateLineAnnotation(const PaintEventData &data, if (!blockUserData) return; - TextMarks marks = Utils::filtered(blockUserData->marks(), [](const TextMark* mark){ - return !mark->lineAnnotation().isEmpty() && mark->isVisible(); + TextMarks marks = Utils::filtered(blockUserData->marks(), [](const TextMark *mark) { + return !mark->lineAnnotation().isEmpty() && mark->isVisible() + && !TextDocument::marksAnnotationHidden(mark->category().id); }); const bool annotationsVisible = !marks.isEmpty(); @@ -6603,7 +6604,7 @@ void TextEditorWidgetPrivate::addSearchResultsToScrollBar(const QVectorcategory(), + return Highlight(mark->category().id, lineNumber, mark->color().value_or(Utils::Theme::TextColorNormal), textMarkPrioToScrollBarPrio(mark->priority())); diff --git a/src/plugins/texteditor/textmark.cpp b/src/plugins/texteditor/textmark.cpp index a0f74624b72..5a8460f2d0c 100644 --- a/src/plugins/texteditor/textmark.cpp +++ b/src/plugins/texteditor/textmark.cpp @@ -7,6 +7,7 @@ #include "textdocument.h" #include "texteditor.h" #include "texteditorplugin.h" +#include "texteditortr.h" #include #include @@ -62,7 +63,7 @@ private: TextMarkRegistry *m_instance = nullptr; -TextMark::TextMark(const FilePath &fileName, int lineNumber, Id category) +TextMark::TextMark(const FilePath &fileName, int lineNumber, TextMarkCategory category) : m_fileName(fileName) , m_lineNumber(lineNumber) , m_visible(true) @@ -278,6 +279,23 @@ void TextMark::addToToolTipLayout(QGridLayout *target) const QList actions{m_actions.begin(), m_actions.end()}; if (m_actionsProvider) actions = m_actionsProvider(); + if (m_category.id.isValid() && !m_lineAnnotation.isEmpty()) { + auto visibilityAction = new QAction; + const bool isHidden = TextDocument::marksAnnotationHidden(m_category.id); + visibilityAction->setIcon(Utils::Icons::EYE_OPEN_TOOLBAR.icon()); + const QString tooltip = (isHidden ? Tr::tr("Show inline annotations for %1") + : Tr::tr("Tempoary hide inline annotations for %1")) + .arg(m_category.displayName); + visibilityAction->setToolTip(tooltip); + auto callback = [id = m_category.id, isHidden] { + if (isHidden) + TextDocument::showMarksAnnotation(id); + else + TextDocument::temporaryHideMarksAnnotation(id); + }; + QObject::connect(visibilityAction, &QAction::triggered, Core::ICore::instance(), callback); + actions.append(visibilityAction); + } if (m_settingsPage.isValid()) { auto settingsAction = new QAction; settingsAction->setIcon(Utils::Icons::SETTINGS_TOOLBAR.icon()); diff --git a/src/plugins/texteditor/textmark.h b/src/plugins/texteditor/textmark.h index 9bc190ea761..62bb51a1f2c 100644 --- a/src/plugins/texteditor/textmark.h +++ b/src/plugins/texteditor/textmark.h @@ -28,13 +28,20 @@ namespace TextEditor { class TextDocument; +class TextMarkCategory +{ +public: + QString displayName; + Utils::Id id; +}; + class TEXTEDITOR_EXPORT TextMark { Q_DECLARE_TR_FUNCTIONS(TextEditor::TextMark) public: TextMark(const Utils::FilePath &fileName, int lineNumber, - Utils::Id category); + TextMarkCategory category); TextMark() = delete; virtual ~TextMark(); @@ -89,7 +96,7 @@ public: void setPriority(Priority prioriy); bool isVisible() const; void setVisible(bool isVisible); - Utils::Id category() const { return m_category; } + TextMarkCategory category() const { return m_category; } std::optional color() const; void setColor(const Utils::Theme::Color &color); @@ -129,7 +136,7 @@ private: std::function m_iconProvider; std::optional m_color; bool m_visible = false; - Utils::Id m_category; + TextMarkCategory m_category; QString m_lineAnnotation; QString m_toolTip; std::function m_toolTipProvider; diff --git a/src/plugins/valgrind/callgrindtextmark.cpp b/src/plugins/valgrind/callgrindtextmark.cpp index 251af62295b..07b6af16c24 100644 --- a/src/plugins/valgrind/callgrindtextmark.cpp +++ b/src/plugins/valgrind/callgrindtextmark.cpp @@ -23,8 +23,11 @@ using namespace Valgrind::Callgrind; namespace Constants { const char CALLGRIND_TEXT_MARK_CATEGORY[] = "Callgrind.Textmark"; } CallgrindTextMark::CallgrindTextMark(const QPersistentModelIndex &index, - const FilePath &fileName, int lineNumber) - : TextEditor::TextMark(fileName, lineNumber, Constants::CALLGRIND_TEXT_MARK_CATEGORY) + const FilePath &fileName, + int lineNumber) + : TextEditor::TextMark(fileName, + lineNumber, + {Tr::tr("Callgrind"), Constants::CALLGRIND_TEXT_MARK_CATEGORY}) , m_modelIndex(index) { setPriority(TextEditor::TextMark::HighPriority);