mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-24 05:45:27 +00:00
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:
parent
8c6db6e3bb
commit
57231192f4
@ -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 \
|
||||
|
@ -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
29
src/RunScriptTask.cpp
Normal 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
32
src/RunScriptTask.h
Normal 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
|
Loading…
Reference in New Issue
Block a user