mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 20:06:12 +00:00
Indicator that tells a command is being executed is implemented. (#789)
* Indicator that tells a command is being executed is implemented.
This commit is contained in:
parent
7c7cb4083c
commit
c18912b74c
@ -4,6 +4,7 @@
|
||||
#include <QAction>
|
||||
#include <QShortcut>
|
||||
#include <QStringListModel>
|
||||
#include <QTimer>
|
||||
#include "Cutter.h"
|
||||
#include "ConsoleWidget.h"
|
||||
#include "ui_ConsoleWidget.h"
|
||||
@ -167,19 +168,40 @@ void ConsoleWidget::focusInputLineEdit()
|
||||
ui->inputLineEdit->setFocus();
|
||||
}
|
||||
|
||||
void ConsoleWidget::removeLastLine()
|
||||
{
|
||||
ui->outputTextEdit->setFocus();
|
||||
QTextCursor cur = ui->outputTextEdit->textCursor();
|
||||
ui->outputTextEdit->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
|
||||
ui->outputTextEdit->moveCursor(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
|
||||
ui->outputTextEdit->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor);
|
||||
ui->outputTextEdit->textCursor().removeSelectedText();
|
||||
ui->outputTextEdit->textCursor().deletePreviousChar();
|
||||
ui->outputTextEdit->setTextCursor(cur);
|
||||
}
|
||||
|
||||
void ConsoleWidget::executeCommand(const QString &command)
|
||||
{
|
||||
if (!commandTask.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ui->inputLineEdit->setEnabled(false);
|
||||
|
||||
QString cmd_line = "[" + RAddressString(Core()->getOffset()) + "]> " + command + "\n";
|
||||
const int originalLines = ui->outputTextEdit->blockCount();
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setInterval(500);
|
||||
timer->setSingleShot(true);
|
||||
connect(timer, &QTimer::timeout, [this]() {
|
||||
ui->outputTextEdit->appendPlainText("Executing the command...");
|
||||
});
|
||||
|
||||
QString cmd_line = "[" + RAddressString(Core()->getOffset()) + "]> " + command + "\n";
|
||||
commandTask = QSharedPointer<CommandTask>(new CommandTask(command));
|
||||
connect(commandTask.data(), &CommandTask::finished, this, [this, cmd_line,
|
||||
command] (const QString & result) {
|
||||
command, originalLines] (const QString & result) {
|
||||
if (originalLines < ui->outputTextEdit->blockCount()) {
|
||||
removeLastLine();
|
||||
}
|
||||
ui->outputTextEdit->appendPlainText(cmd_line + result);
|
||||
scrollOutputToEnd();
|
||||
historyAdd(command);
|
||||
@ -187,6 +209,9 @@ void ConsoleWidget::executeCommand(const QString &command)
|
||||
ui->inputLineEdit->setEnabled(true);
|
||||
ui->inputLineEdit->setFocus();
|
||||
});
|
||||
connect(commandTask.data(), &CommandTask::finished, timer, &QTimer::stop);
|
||||
|
||||
timer->start();
|
||||
Core()->getAsyncTaskManager()->start(commandTask);
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ private:
|
||||
void scrollOutputToEnd();
|
||||
void historyAdd(const QString &input);
|
||||
void invalidateHistoryPosition();
|
||||
void removeLastLine();
|
||||
void executeCommand(const QString &command);
|
||||
|
||||
QSharedPointer<CommandTask> commandTask;
|
||||
|
Loading…
Reference in New Issue
Block a user