diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 10c45135..0bb8494e 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -143,6 +143,9 @@ void MainWindow::initUI() spacer->setMinimumSize(20, 20); ui->mainToolBar->addWidget(spacer); + tasksIndicator = new QLabel(this); + ui->mainToolBar->addWidget(tasksIndicator); + // Visual navigation tool bar this->visualNavbar = new VisualNavbar(this); this->visualNavbar->setMovable(false); @@ -226,6 +229,17 @@ void MainWindow::initUI() connect(refresh_shortcut, SIGNAL(activated()), this, SLOT(refreshAll())); connect(core, SIGNAL(projectSaved(const QString &)), this, SLOT(projectSaved(const QString &))); + + updateTasksIndicator(); + connect(core->getAsyncTaskManager(), &AsyncTaskManager::tasksChanged, this, &MainWindow::updateTasksIndicator); +} + +void MainWindow::updateTasksIndicator() +{ + bool running = Core()->getAsyncTaskManager()->getTasksRunning(); + QLabel *l = static_cast(tasksIndicator); + l->setText(running ? "running" : ""); + //tasksIndicator->setVisible(running); } void MainWindow::on_actionExtraGraph_triggered() diff --git a/src/MainWindow.h b/src/MainWindow.h index 4054959d..782521e4 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -165,6 +165,8 @@ private slots: void projectSaved(const QString &name); + void updateTasksIndicator(); + void mousePressEvent(QMouseEvent *event) override; bool eventFilter(QObject *object, QEvent *event); @@ -181,6 +183,8 @@ private: AsciiHighlighter *hex_highlighter; VisualNavbar *visualNavbar; Omnibar *omnibar; + QWidget *tasksIndicator; + Configuration *configuration; QList dockWidgets; diff --git a/src/utils/AsyncTask.cpp b/src/utils/AsyncTask.cpp index f6291e9a..b2a52519 100644 --- a/src/utils/AsyncTask.cpp +++ b/src/utils/AsyncTask.cpp @@ -82,6 +82,13 @@ void AsyncTaskManager::start(AsyncTask::Ptr task) QWeakPointer weakPtr = task; connect(task.data(), &AsyncTask::finished, this, [this, weakPtr]() { tasks.removeOne(weakPtr); + emit tasksChanged(); }); threadPool->start(task.data()); + emit tasksChanged(); +} + +bool AsyncTaskManager::getTasksRunning() +{ + return !tasks.isEmpty(); } diff --git a/src/utils/AsyncTask.h b/src/utils/AsyncTask.h index 1426d18c..627a3ddd 100644 --- a/src/utils/AsyncTask.h +++ b/src/utils/AsyncTask.h @@ -70,6 +70,10 @@ public: ~AsyncTaskManager(); void start(AsyncTask::Ptr task); + bool getTasksRunning(); + +signals: + void tasksChanged(); }; diff --git a/src/widgets/ConsoleWidget.cpp b/src/widgets/ConsoleWidget.cpp index 95b58e74..0309b3c9 100644 --- a/src/widgets/ConsoleWidget.cpp +++ b/src/widgets/ConsoleWidget.cpp @@ -168,16 +168,30 @@ void ConsoleWidget::focusInputLineEdit() ui->inputLineEdit->setFocus(); } +void ConsoleWidget::executeCommand(const QString &command) +{ + if (!commandTask.isNull()) { + return; + } + + QString cmd_line = "[" + RAddressString(Core()->getOffset()) + "]> " + command + "\n"; + + commandTask = QSharedPointer(new CommandTask(command)); + connect(commandTask.data(), &CommandTask::finished, this, [this, cmd_line, command] (const QString &result) { + ui->outputTextEdit->appendPlainText(cmd_line + result); + scrollOutputToEnd(); + historyAdd(command); + commandTask = nullptr; + }); + Core()->getAsyncTaskManager()->start(commandTask); +} + void ConsoleWidget::on_inputLineEdit_returnPressed() { QString input = ui->inputLineEdit->text(); if (!input.isEmpty()) { if (!isForbidden(input)) { - QString res = Core()->cmd(input); - QString cmd_line = "[" + RAddressString(Core()->getOffset()) + "]> " + input + "\n"; - ui->outputTextEdit->appendPlainText(cmd_line + res); - scrollOutputToEnd(); - historyAdd(input); + executeCommand(input); } else { addDebugOutput(tr("command forbidden: ") + input); } @@ -258,7 +272,6 @@ void ConsoleWidget::historyAdd(const QString &input) invalidateHistoryPosition(); } - void ConsoleWidget::invalidateHistoryPosition() { lastHistoryPosition = invalidHistoryPos; diff --git a/src/widgets/ConsoleWidget.h b/src/widgets/ConsoleWidget.h index 586449ba..9039ddea 100644 --- a/src/widgets/ConsoleWidget.h +++ b/src/widgets/ConsoleWidget.h @@ -4,6 +4,7 @@ #include #include "MainWindow.h" #include "CutterDockWidget.h" +#include "utils/CommandTask.h" namespace Ui { class ConsoleWidget; @@ -53,7 +54,9 @@ private: void scrollOutputToEnd(); void historyAdd(const QString &input); void invalidateHistoryPosition(); - QString executeCommand(QString command); + void executeCommand(const QString &command); + + QSharedPointer commandTask; std::unique_ptr ui; QList actions;