Added dialog to show infinite progress-bar while running script (#1145)

* Added dialog to show infinite progress-bar while running script

* Replaced loadScript with cmdTask for thread safe execution.
This commit is contained in:
Gaurav Kumar Ghildiyal 2019-01-28 19:07:20 +05:30 committed by Itay Cohen
parent 8c6db6e3bb
commit 57231192f4
4 changed files with 84 additions and 7 deletions

View File

@ -225,7 +225,8 @@ SOURCES += \
common/QtResImporter.cpp \
common/CutterSeekable.cpp \
common/RefreshDeferrer.cpp \
dialogs/WelcomeDialog.cpp
dialogs/WelcomeDialog.cpp \
RunScriptTask.cpp
HEADERS += \
@ -333,7 +334,8 @@ HEADERS += \
common/QtResImporter.h \
common/CutterSeekable.h \
common/RefreshDeferrer.h \
dialogs/WelcomeDialog.h
dialogs/WelcomeDialog.h \
RunScriptTask.h
FORMS += \
dialogs/AboutDialog.ui \

View File

@ -51,6 +51,7 @@
#include "dialogs/RenameDialog.h"
#include "dialogs/preferences/PreferencesDialog.h"
#include "dialogs/OpenFileDialog.h"
#include "dialogs/AsyncTaskDialog.h"
// Widgets Headers
#include "widgets/DisassemblerGraphView.h"
@ -86,6 +87,8 @@
#include "widgets/BreakpointWidget.h"
#include "widgets/RegisterRefsWidget.h"
#include "RunScriptTask.h"
// Graphics
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
@ -810,7 +813,18 @@ void MainWindow::on_actionRun_Script_triggered()
const QString &fileName = QDir::toNativeSeparators(dialog.getOpenFileName(this, tr("Select radare2 script")));
if (fileName.isEmpty()) // Cancel was pressed
return;
core->loadScript(fileName);
RunScriptTask *runScriptTask = new RunScriptTask();
runScriptTask->setFileName(fileName);
AsyncTask::Ptr runScriptTaskPtr(runScriptTask);
AsyncTaskDialog *taskDialog = new AsyncTaskDialog(runScriptTaskPtr, this);
taskDialog->setInterruptOnClose(true);
taskDialog->setAttribute(Qt::WA_DeleteOnClose);
taskDialog->show();
Core()->getAsyncTaskManager()->start(runScriptTaskPtr);
}
/**

29
src/RunScriptTask.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "Cutter.h"
#include "RunScriptTask.h"
#include "MainWindow.h"
RunScriptTask::RunScriptTask() :
AsyncTask()
{
}
RunScriptTask::~RunScriptTask()
{
}
void RunScriptTask::interrupt()
{
AsyncTask::interrupt();
r_cons_singleton()->context->breaked = true;
}
void RunScriptTask::runTask()
{
if (!this->fileName.isNull()) {
log(tr("Executing script..."));
Core()->cmdTask(". " + this->fileName);
if (isInterrupted()) {
return;
}
}
}

32
src/RunScriptTask.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef RUNSCRIPTTHREAD_H
#define RUNSCRIPTTHREAD_H
#include "common/AsyncTask.h"
#include "Cutter.h"
class RunScriptTask : public AsyncTask
{
Q_OBJECT
public:
explicit RunScriptTask();
~RunScriptTask();
QString getTitle() override {
return tr("Run Script");
}
void setFileName(const QString &fileName) {
this->fileName = fileName;
}
void interrupt() override;
protected:
void runTask() override;
private:
QString fileName;
};
#endif // RUNSCRIPTTHREAD_H