mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 16:47: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);
|
spacer->setMinimumSize(20, 20);
|
||||||
ui->mainToolBar->addWidget(spacer);
|
ui->mainToolBar->addWidget(spacer);
|
||||||
|
|
||||||
|
tasksIndicator = new QLabel(this);
|
||||||
|
ui->mainToolBar->addWidget(tasksIndicator);
|
||||||
|
|
||||||
// Visual navigation tool bar
|
// Visual navigation tool bar
|
||||||
this->visualNavbar = new VisualNavbar(this);
|
this->visualNavbar = new VisualNavbar(this);
|
||||||
this->visualNavbar->setMovable(false);
|
this->visualNavbar->setMovable(false);
|
||||||
@ -226,6 +229,17 @@ void MainWindow::initUI()
|
|||||||
connect(refresh_shortcut, SIGNAL(activated()), this, SLOT(refreshAll()));
|
connect(refresh_shortcut, SIGNAL(activated()), this, SLOT(refreshAll()));
|
||||||
|
|
||||||
connect(core, SIGNAL(projectSaved(const QString &)), this, SLOT(projectSaved(const QString &)));
|
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()
|
void MainWindow::on_actionExtraGraph_triggered()
|
||||||
|
@ -165,6 +165,8 @@ private slots:
|
|||||||
|
|
||||||
void projectSaved(const QString &name);
|
void projectSaved(const QString &name);
|
||||||
|
|
||||||
|
void updateTasksIndicator();
|
||||||
|
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
bool eventFilter(QObject *object, QEvent *event);
|
bool eventFilter(QObject *object, QEvent *event);
|
||||||
|
|
||||||
@ -181,6 +183,8 @@ private:
|
|||||||
AsciiHighlighter *hex_highlighter;
|
AsciiHighlighter *hex_highlighter;
|
||||||
VisualNavbar *visualNavbar;
|
VisualNavbar *visualNavbar;
|
||||||
Omnibar *omnibar;
|
Omnibar *omnibar;
|
||||||
|
QWidget *tasksIndicator;
|
||||||
|
|
||||||
Configuration *configuration;
|
Configuration *configuration;
|
||||||
|
|
||||||
QList<QDockWidget *> dockWidgets;
|
QList<QDockWidget *> dockWidgets;
|
||||||
|
@ -82,6 +82,13 @@ void AsyncTaskManager::start(AsyncTask::Ptr task)
|
|||||||
QWeakPointer<AsyncTask> weakPtr = task;
|
QWeakPointer<AsyncTask> weakPtr = task;
|
||||||
connect(task.data(), &AsyncTask::finished, this, [this, weakPtr]() {
|
connect(task.data(), &AsyncTask::finished, this, [this, weakPtr]() {
|
||||||
tasks.removeOne(weakPtr);
|
tasks.removeOne(weakPtr);
|
||||||
|
emit tasksChanged();
|
||||||
});
|
});
|
||||||
threadPool->start(task.data());
|
threadPool->start(task.data());
|
||||||
|
emit tasksChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AsyncTaskManager::getTasksRunning()
|
||||||
|
{
|
||||||
|
return !tasks.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,10 @@ public:
|
|||||||
~AsyncTaskManager();
|
~AsyncTaskManager();
|
||||||
|
|
||||||
void start(AsyncTask::Ptr task);
|
void start(AsyncTask::Ptr task);
|
||||||
|
bool getTasksRunning();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void tasksChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,16 +168,30 @@ void ConsoleWidget::focusInputLineEdit()
|
|||||||
ui->inputLineEdit->setFocus();
|
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()
|
void ConsoleWidget::on_inputLineEdit_returnPressed()
|
||||||
{
|
{
|
||||||
QString input = ui->inputLineEdit->text();
|
QString input = ui->inputLineEdit->text();
|
||||||
if (!input.isEmpty()) {
|
if (!input.isEmpty()) {
|
||||||
if (!isForbidden(input)) {
|
if (!isForbidden(input)) {
|
||||||
QString res = Core()->cmd(input);
|
executeCommand(input);
|
||||||
QString cmd_line = "[" + RAddressString(Core()->getOffset()) + "]> " + input + "\n";
|
|
||||||
ui->outputTextEdit->appendPlainText(cmd_line + res);
|
|
||||||
scrollOutputToEnd();
|
|
||||||
historyAdd(input);
|
|
||||||
} else {
|
} else {
|
||||||
addDebugOutput(tr("command forbidden: ") + input);
|
addDebugOutput(tr("command forbidden: ") + input);
|
||||||
}
|
}
|
||||||
@ -258,7 +272,6 @@ void ConsoleWidget::historyAdd(const QString &input)
|
|||||||
|
|
||||||
invalidateHistoryPosition();
|
invalidateHistoryPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleWidget::invalidateHistoryPosition()
|
void ConsoleWidget::invalidateHistoryPosition()
|
||||||
{
|
{
|
||||||
lastHistoryPosition = invalidHistoryPos;
|
lastHistoryPosition = invalidHistoryPos;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "CutterDockWidget.h"
|
#include "CutterDockWidget.h"
|
||||||
|
#include "utils/CommandTask.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ConsoleWidget;
|
class ConsoleWidget;
|
||||||
@ -53,7 +54,9 @@ private:
|
|||||||
void scrollOutputToEnd();
|
void scrollOutputToEnd();
|
||||||
void historyAdd(const QString &input);
|
void historyAdd(const QString &input);
|
||||||
void invalidateHistoryPosition();
|
void invalidateHistoryPosition();
|
||||||
QString executeCommand(QString command);
|
void executeCommand(const QString &command);
|
||||||
|
|
||||||
|
QSharedPointer<CommandTask> commandTask;
|
||||||
|
|
||||||
std::unique_ptr<Ui::ConsoleWidget> ui;
|
std::unique_ptr<Ui::ConsoleWidget> ui;
|
||||||
QList<QAction *> actions;
|
QList<QAction *> actions;
|
||||||
|
Loading…
Reference in New Issue
Block a user