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:
Vanellope 2018-10-11 03:09:07 +09:00 committed by xarkes
parent 7c7cb4083c
commit c18912b74c
2 changed files with 29 additions and 3 deletions

View File

@ -4,6 +4,7 @@
#include <QAction> #include <QAction>
#include <QShortcut> #include <QShortcut>
#include <QStringListModel> #include <QStringListModel>
#include <QTimer>
#include "Cutter.h" #include "Cutter.h"
#include "ConsoleWidget.h" #include "ConsoleWidget.h"
#include "ui_ConsoleWidget.h" #include "ui_ConsoleWidget.h"
@ -167,19 +168,40 @@ void ConsoleWidget::focusInputLineEdit()
ui->inputLineEdit->setFocus(); 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) void ConsoleWidget::executeCommand(const QString &command)
{ {
if (!commandTask.isNull()) { if (!commandTask.isNull()) {
return; return;
} }
ui->inputLineEdit->setEnabled(false); 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)); commandTask = QSharedPointer<CommandTask>(new CommandTask(command));
connect(commandTask.data(), &CommandTask::finished, this, [this, cmd_line, 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); ui->outputTextEdit->appendPlainText(cmd_line + result);
scrollOutputToEnd(); scrollOutputToEnd();
historyAdd(command); historyAdd(command);
@ -187,6 +209,9 @@ void ConsoleWidget::executeCommand(const QString &command)
ui->inputLineEdit->setEnabled(true); ui->inputLineEdit->setEnabled(true);
ui->inputLineEdit->setFocus(); ui->inputLineEdit->setFocus();
}); });
connect(commandTask.data(), &CommandTask::finished, timer, &QTimer::stop);
timer->start();
Core()->getAsyncTaskManager()->start(commandTask); Core()->getAsyncTaskManager()->start(commandTask);
} }

View File

@ -54,6 +54,7 @@ private:
void scrollOutputToEnd(); void scrollOutputToEnd();
void historyAdd(const QString &input); void historyAdd(const QString &input);
void invalidateHistoryPosition(); void invalidateHistoryPosition();
void removeLastLine();
void executeCommand(const QString &command); void executeCommand(const QString &command);
QSharedPointer<CommandTask> commandTask; QSharedPointer<CommandTask> commandTask;