Skip to content

Commit

Permalink
qt, rpc, refactor: Add RPCConsole::clearAndFocusPrompt
Browse files Browse the repository at this point in the history
This changes removes duplicated code.
  • Loading branch information
hebasto committed Oct 28, 2020
1 parent 0dadb82 commit 0b8b653
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,19 +770,16 @@ void RPCConsole::setFontSize(int newSize)
void RPCConsole::clear(bool clearHistory)
{
ui->messagesWidget->clear();
if(clearHistory)
{
if (clearHistory) {
history.clear();
historyPtr = 0;
}
ui->lineEdit->clear();
ui->lineEdit->setEnabled(true);
ui->lineEdit->setFocus();

clearAndFocusPrompt();

// Add smoothly scaled icon images.
// (when using width/height on an img, Qt uses nearest instead of linear interpolation)
for(int i=0; ICON_MAPPING[i].url; ++i)
{
for (int i = 0; ICON_MAPPING[i].url; ++i) {
ui->messagesWidget->document()->addResource(
QTextDocument::ImageResource,
QUrl(ICON_MAPPING[i].url),
Expand Down Expand Up @@ -971,9 +968,7 @@ void RPCConsole::startExecutor()
// Replies from executor object must go to this object
connect(executor, &RPCExecutor::reply, this, [this](int category, const QString& command) {
message(category, command);
ui->lineEdit->clear();
ui->lineEdit->setEnabled(true);
ui->lineEdit->setFocus();
clearAndFocusPrompt();
});

// Requests from this object must go to executor
Expand Down Expand Up @@ -1307,3 +1302,10 @@ void RPCConsole::updateAlerts(const QString& warnings)
this->ui->label_alerts->setVisible(!warnings.isEmpty());
this->ui->label_alerts->setText(warnings);
}

void RPCConsole::clearAndFocusPrompt()
{
ui->lineEdit->clear();
ui->lineEdit->setEnabled(true);
ui->lineEdit->setFocus();
}
5 changes: 5 additions & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public Q_SLOTS:
/** Update UI with latest network info from model. */
void updateNetworkState();

/**
* Clear the prompt line on the Console tab, and set focus on it.
*/
void clearAndFocusPrompt();

private Q_SLOTS:
void updateAlerts(const QString& warnings);
};
Expand Down

0 comments on commit 0b8b653

Please sign in to comment.