1
0
Fork 0

Added command history from #839

This commit is contained in:
justin 2016-07-13 14:57:14 -06:00 committed by mrexodia
parent a15a126ce9
commit 8daf1f5942
No known key found for this signature in database
GPG Key ID: D72F9A4FAA0073B4
4 changed files with 40 additions and 3 deletions

View File

@ -1,17 +1,43 @@
#include "HistoryLineEdit.h"
#include "Bridge.h"
HistoryLineEdit::HistoryLineEdit(QWidget* parent) : QLineEdit(parent)
{
mCmdHistory.clear();
mCmdIndex = -1;
bSixPressed = false;
}
void HistoryLineEdit::loadSettings(QString sectionPrefix)
{
char buffer[MAX_SETTING_SIZE];
for(int i = 1; BridgeSettingGet(sectionPrefix.toUtf8().constData(),
QString("Line%1").arg(i).toUtf8().constData(),
buffer) && buffer[0] && i < mCmdHistoryMaxSize; i++)
{
QString entry = QString::fromUtf8(buffer);
mCmdHistory.append(entry);
}
}
void HistoryLineEdit::saveSettings(QString sectionPrefix)
{
int i = 1;
for(i = 1; i <= mCmdHistory.size(); i++)
{
BridgeSettingSet(sectionPrefix.toUtf8().constData(),
QString("Line%1").arg(i).toUtf8().constData(),
mCmdHistory.at(i - 1).toUtf8().constData());
}
// Sentinel in case we saved less than is in the store currently
BridgeSettingSet(sectionPrefix.toUtf8().constData(),
QString("Line%1").arg(i).toUtf8().constData(),
"");
}
void HistoryLineEdit::addLineToHistory(QString parLine)
{
mCmdHistory.prepend(parLine);
if(mCmdHistory.size() > 32)
if(mCmdHistory.size() > mCmdHistoryMaxSize)
mCmdHistory.removeLast();
mCmdIndex = -1;

View File

@ -12,11 +12,13 @@ public:
void keyPressEvent(QKeyEvent* event);
void addLineToHistory(QString parLine);
void setFocus();
void loadSettings(QString sectionPrefix);
void saveSettings(QString sectionPrefix);
signals:
void keyPressed(int parKey);
private:
int mCmdHistoryMaxSize = 1000;
QList<QString> mCmdHistory;
int mCmdIndex;
bool bSixPressed;

View File

@ -16,6 +16,8 @@ CommandLineEdit::CommandLineEdit(QWidget* parent)
mCompleterModel = (QStringListModel*)mCompleter->model();
this->setCompleter(mCompleter);
loadSettings("CommandLine");
//Setup signals & slots
connect(mCompleter, SIGNAL(activated(const QString &)), this, SLOT(clear()), Qt::QueuedConnection);
connect(this, SIGNAL(textEdited(QString)), this, SLOT(autoCompleteUpdate(QString)));
@ -27,6 +29,11 @@ CommandLineEdit::CommandLineEdit(QWidget* parent)
connect(mCmdScriptType, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptTypeChanged(int)));
}
CommandLineEdit::~CommandLineEdit()
{
saveSettings("CommandLine");
}
void CommandLineEdit::keyPressEvent(QKeyEvent* event)
{
if(event->type() == QEvent::KeyPress && event->key() == Qt::Key_Tab)

View File

@ -14,6 +14,8 @@ class CommandLineEdit : public HistoryLineEdit
public:
explicit CommandLineEdit(QWidget* parent = 0);
~CommandLineEdit();
void keyPressEvent(QKeyEvent* event);
bool focusNextPrevChild(bool next);