From 1eabb6f1855d68afbe48064b4e25bce50fa5418b Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 28 Apr 2022 15:42:33 +0200 Subject: [PATCH] Locator: Save history of execute filter Fixes: QTCREATORBUG-27381 Change-Id: I2a053e4e2e978034fcbfc15a6ecfff04a057ffaf Reviewed-by: David Schulz Reviewed-by: Reviewed-by: Qt CI Bot --- .../coreplugin/locator/executefilter.cpp | 21 +++++++++++++++++++ .../coreplugin/locator/executefilter.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/plugins/coreplugin/locator/executefilter.cpp b/src/plugins/coreplugin/locator/executefilter.cpp index 327731f1e26..ba74db177cd 100644 --- a/src/plugins/coreplugin/locator/executefilter.cpp +++ b/src/plugins/coreplugin/locator/executefilter.cpp @@ -27,9 +27,12 @@ #include #include +#include #include #include +#include +#include #include using namespace Core; @@ -89,11 +92,15 @@ void ExecuteFilter::accept(const LocatorFilterEntry &selection, auto p = const_cast(this); const QString value = selection.displayName.trimmed(); + const int index = m_commandHistory.indexOf(value); if (index != -1 && index != 0) p->m_commandHistory.removeAt(index); if (index != 0) p->m_commandHistory.prepend(value); + static const int maxHistory = 100; + while (p->m_commandHistory.size() > maxHistory) + p->m_commandHistory.removeLast(); bool found; QString workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Path", &found); @@ -202,6 +209,20 @@ void ExecuteFilter::removeProcess() m_process = nullptr; } +const char historyKey[] = "history"; + +void ExecuteFilter::saveState(QJsonObject &object) const +{ + if (!m_commandHistory.isEmpty()) + object.insert(historyKey, QJsonArray::fromStringList(m_commandHistory)); +} + +void ExecuteFilter::restoreState(const QJsonObject &object) +{ + m_commandHistory = Utils::transform(object.value(historyKey).toArray().toVariantList(), + &QVariant::toString); +} + QString ExecuteFilter::headCommand() const { if (m_taskQueue.isEmpty()) diff --git a/src/plugins/coreplugin/locator/executefilter.h b/src/plugins/coreplugin/locator/executefilter.h index 85c84bbb6eb..7742637cda4 100644 --- a/src/plugins/coreplugin/locator/executefilter.h +++ b/src/plugins/coreplugin/locator/executefilter.h @@ -63,6 +63,9 @@ private: void createProcess(); void removeProcess(); + void saveState(QJsonObject &object) const final; + void restoreState(const QJsonObject &object) final; + QString headCommand() const; QQueue m_taskQueue;