Skip to content

Commit 4ce2b02

Browse files
GamerSgschinzelh
authored andcommitted
Add autocomplete to bitcoin-qt's console window.
Removed externs Added listCommands() to CRPCTable Move autocomplete init to RPCConsole::setClientModel() Closes #742
1 parent eaf57b3 commit 4ce2b02

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/qt/rpcconsole.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <QThread>
3434
#include <QTime>
3535
#include <QTimer>
36+
#include <QStringList>
3637

3738
#if QT_VERSION < 0x050000
3839
#include <QUrl>
@@ -461,6 +462,18 @@ void RPCConsole::setClientModel(ClientModel *model)
461462
ui->buildDate->setText(model->formatBuildDate());
462463
ui->startupTime->setText(model->formatClientStartupTime());
463464
ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
465+
466+
//Setup autocomplete and attach it
467+
QStringList wordList;
468+
std::vector<std::string> commandList = tableRPC.listCommands();
469+
for (size_t i = 0; i < commandList.size(); ++i)
470+
{
471+
wordList << commandList[i].c_str();
472+
}
473+
474+
autoCompleter = new QCompleter(wordList, this);
475+
ui->lineEdit->setCompleter(autoCompleter);
476+
464477
}
465478
}
466479

src/qt/rpcconsole.h

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "net.h"
1212

1313
#include <QWidget>
14+
#include <QCompleter>
1415

1516
class ClientModel;
1617
class PlatformStyle;
@@ -150,6 +151,7 @@ public Q_SLOTS:
150151
RPCTimerInterface *rpcTimerInterface;
151152
QMenu *peersTableContextMenu;
152153
QMenu *banTableContextMenu;
154+
QCompleter *autoCompleter;
153155
};
154156

155157
#endif // BITCOIN_QT_RPCCONSOLE_H

src/rpcserver.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,17 @@ UniValue CRPCTable::execute(const std::string &strMethod, const UniValue &params
554554
g_rpcSignals.PostCommand(*pcmd);
555555
}
556556

557+
std::vector<std::string> CRPCTable::listCommands() const
558+
{
559+
std::vector<std::string> commandList;
560+
typedef std::map<std::string, const CRPCCommand*> commandMap;
561+
562+
std::transform( mapCommands.begin(), mapCommands.end(),
563+
std::back_inserter(commandList),
564+
boost::bind(&commandMap::value_type::first,_1) );
565+
return commandList;
566+
}
567+
557568
std::string HelpExampleCli(const std::string& methodname, const std::string& args)
558569
{
559570
return "> dash-cli " + methodname + " " + args + "\n";

src/rpcserver.h

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ class CRPCTable
142142
* @throws an exception (UniValue) when an error happens.
143143
*/
144144
UniValue execute(const std::string &method, const UniValue &params) const;
145+
146+
/**
147+
* Returns a list of registered commands
148+
* @returns List of registered commands.
149+
*/
150+
std::vector<std::string> listCommands() const;
145151
};
146152

147153
extern const CRPCTable tableRPC;

0 commit comments

Comments
 (0)