New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Qt] support for persisted rpc console history #5891

Closed
wants to merge 2 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+54 −9
Diff settings

Always

Just for now

View
@@ -53,6 +53,9 @@ const struct {
{NULL, NULL}
};
//don't add private key handling cmd's to the history
const QStringList RPCConsole::historyFilter = QStringList() << "importprivkey" << "signrawtransaction" << "walletpassphrase" << "walletpassphrasechange" << "encryptwallet";
/* Object for executing console RPC commands in a separate thread.
*/
class RPCExecutor : public QObject
@@ -238,11 +241,32 @@ RPCConsole::RPCConsole(QWidget *parent) :
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
clear();
//load history
QSettings settings;
int size = settings.beginReadArray("nRPCConsoleWindowHistory");
history.clear();
for (int i=0; i<size; i++){
settings.setArrayIndex(i);
history.append(settings.value("cmd").toString());
}
historyPtr = history.size();
settings.endArray();
}
RPCConsole::~RPCConsole()
{
GUIUtil::saveWindowGeometry("nRPCConsoleWindow", this);
//persist history
QSettings settings;
settings.beginWriteArray("nRPCConsoleWindowHistory");
for (int i = 0; i < history.size(); ++i) {
settings.setArrayIndex(i);
settings.setValue("cmd", history.at(i));
}
settings.endArray();
emit stopExecutor();
delete ui;
}
@@ -417,24 +441,41 @@ void RPCConsole::on_lineEdit_returnPressed()
if(!cmd.isEmpty())
{
cmdBeforeBrowsing = QString();
message(CMD_REQUEST, cmd);
emit cmdRequest(cmd);
// Remove command, if already in history
history.removeOne(cmd);
// Append command to history
history.append(cmd);
// Enforce maximum history size
while(history.size() > CONSOLE_HISTORY)
history.removeFirst();
// Set pointer to end of history
historyPtr = history.size();
bool storeHistory = true;
foreach(QString unallowedCmd, historyFilter)
{
if(cmd.trimmed().startsWith(unallowedCmd))
storeHistory = false; break;
}
if (storeHistory)
{
// Remove command, if already in history
history.removeOne(cmd);
// Append command to history
history.append(cmd);
// Enforce maximum history size
while(history.size() > CONSOLE_HISTORY)
history.removeFirst();
// Set pointer to end of history
historyPtr = history.size();
}
// Scroll console view to end
scrollToEnd();
}
}
void RPCConsole::browseHistory(int offset)
{
// store current text when start browsing through the history
if(historyPtr == history.size())
cmdBeforeBrowsing = ui->lineEdit->text();
historyPtr += offset;
if(historyPtr < 0)
historyPtr = 0;
@@ -443,6 +484,8 @@ void RPCConsole::browseHistory(int offset)
QString cmd;
if(historyPtr < history.size())
cmd = history.at(historyPtr);
else if(historyPtr == history.size() && !cmdBeforeBrowsing.isNull())
cmd = cmdBeforeBrowsing;
ui->lineEdit->setText(cmd);
}
View
@@ -97,6 +97,8 @@ public slots:
ClientModel *clientModel;
QStringList history;
int historyPtr;
const static QStringList historyFilter;
QString cmdBeforeBrowsing;
NodeId cachedNodeid;
};
ProTip! Use n and p to navigate between commits in a pull request.