feat: Allow task stop button to abort pattern evaluation
This commit is contained in:
parent
5b00c8ee08
commit
20a2331504
@ -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;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 });
|
||||
|
Loading…
x
Reference in New Issue
Block a user