Skip to content
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

Add autocomplete to dash-qt's console window. #742

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QThread>
#include <QTime>
#include <QTimer>
#include <QStringList>

#if QT_VERSION < 0x050000
#include <QUrl>
Expand Down Expand Up @@ -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<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);

}
}

Expand Down
2 changes: 2 additions & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "net.h"

#include <QWidget>
#include <QCompleter>

class ClientModel;
class PlatformStyle;
Expand Down Expand Up @@ -150,6 +151,7 @@ public Q_SLOTS:
RPCTimerInterface *rpcTimerInterface;
QMenu *peersTableContextMenu;
QMenu *banTableContextMenu;
QCompleter *autoCompleter;
};

#endif // BITCOIN_QT_RPCCONSOLE_H
11 changes: 11 additions & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,17 @@ UniValue CRPCTable::execute(const std::string &strMethod, const UniValue &params
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)
{
return "> dash-cli " + methodname + " " + args + "\n";
Expand Down
6 changes: 6 additions & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ class CRPCTable
* @throws an exception (UniValue) when an error happens.
*/
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;
};

extern const CRPCTable tableRPC;
Expand Down