mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +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>
|
||||
@ -446,8 +449,8 @@ void MainWindow::setFilename(const QString &fn)
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
QMessageBox::StandardButton ret = QMessageBox::question(this, APPNAME,
|
||||
tr("Do you really want to exit?\nSave your project before closing!"),
|
||||
(QMessageBox::StandardButtons)(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel));
|
||||
tr("Do you really want to exit?\nSave your project before closing!"),
|
||||
(QMessageBox::StandardButtons)(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel));
|
||||
if (ret == QMessageBox::Cancel) {
|
||||
event->ignore();
|
||||
return;
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -840,8 +854,8 @@ void MainWindow::on_actionReset_settings_triggered()
|
||||
{
|
||||
QMessageBox::StandardButton ret =
|
||||
(QMessageBox::StandardButton)QMessageBox::question(this, APPNAME,
|
||||
tr("Do you really want to clear all settings?"),
|
||||
QMessageBox::Ok | QMessageBox::Cancel);
|
||||
tr("Do you really want to clear all settings?"),
|
||||
QMessageBox::Ok | QMessageBox::Cancel);
|
||||
if (ret == QMessageBox::Ok) {
|
||||
Config()->resetAll();
|
||||
}
|
||||
|
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