From: svost Date: Mon, 6 Feb 2017 09:03:42 +0000 (+0300) Subject: Add autocomplete to novacoin-qt's console window X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=b92e09336df23b27305ac58c85553074bd23124f Add autocomplete to novacoin-qt's console window Origin: https://github.com/bitcoin/bitcoin/pull/7613 --- diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 0c7e278..e1d38ea 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1109,6 +1109,16 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s } } +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; +} Object CallRPC(const string& strMethod, const Array& params) { diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index a5888a9..d304686 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -119,6 +119,11 @@ public: * @throws an exception (json_spirit::Value) when an error happens. */ json_spirit::Value execute(const std::string &method, const json_spirit::Array ¶ms) const; + /** + * Returns a list of registered commands + * @returns List of registered commands. + */ + std::vector listCommands() const; }; extern const CRPCTable tableRPC; diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 1c86ddd..e9c0987 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -243,6 +244,14 @@ bool RPCConsole::eventFilter(QObject* obj, QEvent *event) return true; } break; + case Qt::Key_Return: + case Qt::Key_Enter: + // forward these events to lineEdit + if(obj == autoCompleter->popup()) { + QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt)); + return true; + } + break; default: // Typing in messages widget brings focus to line edit, and redirects key there // Exclude most combinations and keys that emit no text, except paste shortcuts @@ -282,6 +291,20 @@ void RPCConsole::setClientModel(ClientModel *model) ui->isTestNet->setChecked(model->isTestNet()); setNumBlocks(model->getNumBlocks(), model->getNumBlocksOfPeers()); + + //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); + + // clear the lineEdit after activating from QCompleter + autoCompleter->popup()->installEventFilter(this); } } diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index aa8c8f3..d5f9b69 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -2,6 +2,7 @@ #define RPCCONSOLE_H #include +#include namespace Ui { class RPCConsole; @@ -82,6 +83,7 @@ private: int historyPtr; void startExecutor(); + QCompleter *autoCompleter; }; #endif // RPCCONSOLE_H