mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 08:37:26 +00:00
Run Commands from ConsoleWidget in AsyncTask
This commit is contained in:
parent
8b293bfe8c
commit
c0397fdcb5
@ -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<QLabel *>(tasksIndicator);
|
||||
l->setText(running ? "running" : "");
|
||||
//tasksIndicator->setVisible(running);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionExtraGraph_triggered()
|
||||
|
@ -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<QDockWidget *> dockWidgets;
|
||||
|
@ -82,6 +82,13 @@ void AsyncTaskManager::start(AsyncTask::Ptr task)
|
||||
QWeakPointer<AsyncTask> 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();
|
||||
}
|
||||
|
@ -70,6 +70,10 @@ public:
|
||||
~AsyncTaskManager();
|
||||
|
||||
void start(AsyncTask::Ptr task);
|
||||
bool getTasksRunning();
|
||||
|
||||
signals:
|
||||
void tasksChanged();
|
||||
};
|
||||
|
||||
|
||||
|
@ -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<CommandTask>(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;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <memory>
|
||||
#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> commandTask;
|
||||
|
||||
std::unique_ptr<Ui::ConsoleWidget> ui;
|
||||
QList<QAction *> actions;
|
||||
|
Loading…
Reference in New Issue
Block a user