1
0
mirror of synced 2025-01-31 03:53:44 +01:00

feat: Allow task stop button to abort pattern evaluation

This commit is contained in:
WerWolv 2022-09-13 16:05:41 +02:00
parent 5b00c8ee08
commit 20a2331504
3 changed files with 13 additions and 1 deletions

View File

@ -40,6 +40,8 @@ namespace hex {
void interrupt();
void setInterruptCallback(std::function<void()> callback);
private:
void finish();
void interruption();
@ -51,6 +53,7 @@ namespace hex {
std::string m_unlocalizedName;
u64 m_currValue, m_maxValue;
std::thread m_thread;
std::function<void()> m_interruptCallback;
bool m_shouldInterrupt = false;

View File

@ -72,6 +72,13 @@ namespace hex {
std::scoped_lock lock(this->m_mutex);
this->m_shouldInterrupt = true;
if (this->m_interruptCallback)
this->m_interruptCallback();
}
void Task::setInterruptCallback(std::function<void()> callback) {
this->m_interruptCallback = std::move(callback);
}
bool Task::isFinished() const {

View File

@ -822,7 +822,9 @@ namespace hex::plugin::builtin {
EventManager::post<EventHighlightingChanged>();
TaskManager::createTask("hex.builtin.view.pattern_editor.evaluating", TaskManager::NoProgress, [this, &runtime, code](auto &) {
TaskManager::createTask("hex.builtin.view.pattern_editor.evaluating", TaskManager::NoProgress, [this, &runtime, code](auto &task) {
task.setInterruptCallback([&runtime] { runtime->abort(); });
std::map<std::string, pl::core::Token::Literal> envVars;
for (const auto &[id, name, value, type] : this->m_envVarEntries)
envVars.insert({ name, value });