diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 3a09841e96dcc..2af3ee20dee77 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #if QT_VERSION < 0x050000 #include @@ -461,6 +462,18 @@ void RPCConsole::setClientModel(ClientModel *model) ui->buildDate->setText(model->formatBuildDate()); ui->startupTime->setText(model->formatClientStartupTime()); ui->networkName->setText(QString::fromStdString(Params().NetworkIDString())); + + //Setup autocomplete and attach it + QStringList wordList; + std::vector commandList = tableRPC.listCommands(); + for (size_t i = 0; i < commandList.size(); ++i) + { + wordList << commandList[i].c_str(); + } + + autoCompleter = new QCompleter(wordList, this); + ui->lineEdit->setCompleter(autoCompleter); + } } diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index f3d366d584297..63735c21e4a47 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -11,6 +11,7 @@ #include "net.h" #include +#include class ClientModel; class PlatformStyle; @@ -150,6 +151,7 @@ public Q_SLOTS: RPCTimerInterface *rpcTimerInterface; QMenu *peersTableContextMenu; QMenu *banTableContextMenu; + QCompleter *autoCompleter; }; #endif // BITCOIN_QT_RPCCONSOLE_H diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index ce07e2575cfaf..1e9bb1ca3ed59 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -553,6 +553,17 @@ UniValue CRPCTable::execute(const std::string &strMethod, const UniValue ¶ms g_rpcSignals.PostCommand(*pcmd); } +std::vector CRPCTable::listCommands() const +{ + std::vector commandList; + typedef std::map commandMap; + + std::transform( mapCommands.begin(), mapCommands.end(), + std::back_inserter(commandList), + boost::bind(&commandMap::value_type::first,_1) ); + return commandList; +} + std::string HelpExampleCli(const std::string& methodname, const std::string& args) { return "> dash-cli " + methodname + " " + args + "\n"; diff --git a/src/rpcserver.h b/src/rpcserver.h index a1e30d9220ba7..b7a4c17c2e435 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -142,6 +142,12 @@ class CRPCTable * @throws an exception (UniValue) when an error happens. */ UniValue execute(const std::string &method, const UniValue ¶ms) const; + + /** + * Returns a list of registered commands + * @returns List of registered commands. + */ + std::vector listCommands() const; }; extern const CRPCTable tableRPC;