diff options
author | Eike Ziller <eike.ziller@qt.io> | 2022-04-28 15:42:33 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2022-04-29 12:22:57 +0000 |
commit | 1eabb6f1855d68afbe48064b4e25bce50fa5418b (patch) | |
tree | eb819c2866be620bd8e765156e925f6b53e17146 | |
parent | 57fbf9bef945711142acbc6d47a9b7fd9f2b0a3f (diff) |
Locator: Save history of execute filter
Fixes: QTCREATORBUG-27381
Change-Id: I2a053e4e2e978034fcbfc15a6ecfff04a057ffaf
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | src/plugins/coreplugin/locator/executefilter.cpp | 21 | ||||
-rw-r--r-- | src/plugins/coreplugin/locator/executefilter.h | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/plugins/coreplugin/locator/executefilter.cpp b/src/plugins/coreplugin/locator/executefilter.cpp index 327731f1e2..ba74db177c 100644 --- a/src/plugins/coreplugin/locator/executefilter.cpp +++ b/src/plugins/coreplugin/locator/executefilter.cpp @@ -27,9 +27,12 @@ #include <coreplugin/icore.h> #include <coreplugin/messagemanager.h> +#include <utils/algorithm.h> #include <utils/macroexpander.h> #include <utils/qtcassert.h> +#include <QJsonArray> +#include <QJsonObject> #include <QMessageBox> using namespace Core; @@ -89,11 +92,15 @@ void ExecuteFilter::accept(const LocatorFilterEntry &selection, auto p = const_cast<ExecuteFilter *>(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 85c84bbb6e..7742637cda 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<ExecuteData> m_taskQueue; |