forked from qt-creator/qt-creator
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:
@@ -27,9 +27,12 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
#include <utils/macroexpander.h>
|
#include <utils/macroexpander.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
@@ -89,11 +92,15 @@ void ExecuteFilter::accept(const LocatorFilterEntry &selection,
|
|||||||
auto p = const_cast<ExecuteFilter *>(this);
|
auto p = const_cast<ExecuteFilter *>(this);
|
||||||
|
|
||||||
const QString value = selection.displayName.trimmed();
|
const QString value = selection.displayName.trimmed();
|
||||||
|
|
||||||
const int index = m_commandHistory.indexOf(value);
|
const int index = m_commandHistory.indexOf(value);
|
||||||
if (index != -1 && index != 0)
|
if (index != -1 && index != 0)
|
||||||
p->m_commandHistory.removeAt(index);
|
p->m_commandHistory.removeAt(index);
|
||||||
if (index != 0)
|
if (index != 0)
|
||||||
p->m_commandHistory.prepend(value);
|
p->m_commandHistory.prepend(value);
|
||||||
|
static const int maxHistory = 100;
|
||||||
|
while (p->m_commandHistory.size() > maxHistory)
|
||||||
|
p->m_commandHistory.removeLast();
|
||||||
|
|
||||||
bool found;
|
bool found;
|
||||||
QString workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Path", &found);
|
QString workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Path", &found);
|
||||||
@@ -202,6 +209,20 @@ void ExecuteFilter::removeProcess()
|
|||||||
m_process = nullptr;
|
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
|
QString ExecuteFilter::headCommand() const
|
||||||
{
|
{
|
||||||
if (m_taskQueue.isEmpty())
|
if (m_taskQueue.isEmpty())
|
||||||
|
@@ -63,6 +63,9 @@ private:
|
|||||||
void createProcess();
|
void createProcess();
|
||||||
void removeProcess();
|
void removeProcess();
|
||||||
|
|
||||||
|
void saveState(QJsonObject &object) const final;
|
||||||
|
void restoreState(const QJsonObject &object) final;
|
||||||
|
|
||||||
QString headCommand() const;
|
QString headCommand() const;
|
||||||
|
|
||||||
QQueue<ExecuteData> m_taskQueue;
|
QQueue<ExecuteData> m_taskQueue;
|
||||||
|
Reference in New Issue
Block a user