Merge #7613: Add autocomplete to bitcoin-qt's console window.

ce7413f Add autocomplete to bitcoin-qt's console window. (Luv Khemani)
This commit is contained in:
Jonas Schnelli 2016-03-14 09:18:51 +01:00
commit 3798e5de33
No known key found for this signature in database
GPG key ID: 29D4BCB6416F53EC
4 changed files with 32 additions and 0 deletions

View file

@ -36,6 +36,7 @@
#include <QThread> #include <QThread>
#include <QTime> #include <QTime>
#include <QTimer> #include <QTimer>
#include <QStringList>
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
#include <QUrl> #include <QUrl>
@ -446,6 +447,18 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->buildDate->setText(model->formatBuildDate()); ui->buildDate->setText(model->formatBuildDate());
ui->startupTime->setText(model->formatClientStartupTime()); ui->startupTime->setText(model->formatClientStartupTime());
ui->networkName->setText(QString::fromStdString(Params().NetworkIDString())); ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
//Setup autocomplete and attach it
QStringList wordList;
std::vector<std::string> 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);
} }
} }

View file

@ -11,6 +11,7 @@
#include "net.h" #include "net.h"
#include <QWidget> #include <QWidget>
#include <QCompleter>
class ClientModel; class ClientModel;
class PlatformStyle; class PlatformStyle;
@ -138,6 +139,7 @@ private:
QMenu *peersTableContextMenu; QMenu *peersTableContextMenu;
QMenu *banTableContextMenu; QMenu *banTableContextMenu;
int consoleFontSize; int consoleFontSize;
QCompleter *autoCompleter;
}; };
#endif // BITCOIN_QT_RPCCONSOLE_H #endif // BITCOIN_QT_RPCCONSOLE_H

View file

@ -499,6 +499,17 @@ UniValue CRPCTable::execute(const std::string &strMethod, const UniValue &params
g_rpcSignals.PostCommand(*pcmd); g_rpcSignals.PostCommand(*pcmd);
} }
std::vector<std::string> CRPCTable::listCommands() const
{
std::vector<std::string> commandList;
typedef std::map<std::string, const CRPCCommand*> 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) std::string HelpExampleCli(const std::string& methodname, const std::string& args)
{ {
return "> bitcoin-cli " + methodname + " " + args + "\n"; return "> bitcoin-cli " + methodname + " " + args + "\n";

View file

@ -145,6 +145,12 @@ public:
*/ */
UniValue execute(const std::string &method, const UniValue &params) const; UniValue execute(const std::string &method, const UniValue &params) const;
/**
* Returns a list of registered commands
* @returns List of registered commands.
*/
std::vector<std::string> listCommands() const;
/** /**
* Appends a CRPCCommand to the dispatch table. * Appends a CRPCCommand to the dispatch table.