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>
This commit is contained in:
Eike Ziller
2022-04-28 15:42:33 +02:00
parent 57fbf9bef9
commit 1eabb6f185
2 changed files with 24 additions and 0 deletions

View File

@@ -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())

View File

@@ -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;