AlertWindow::triggerClick


#1

I’m using a ThreadWithProgressWindow, and I want to “fake” clicking on the cancel button.
Is it possible to add AlertWindow::triggerClick or ::dismiss ?

Currently I’m doing alertWindow->exitModalState(0), but I “guessed” 0 from userTriedToCloseWindow callback value.


#2

That will work fine, but I normally just setVisible (false) on the AlertWindow to achieve the same effect.


#3

I wasn’t very clear. I’m not trying to hide the AlertWindow, I want the ThreadWithProgressWindow::runThread to return false (since it calls back “void run()”, there is no “direct” way of it returning false on error).
If I do AlertWindow::setVisible(false), the window goes hidden, but the thread continue (which I don’t want).

Ideally, the callback method signature could be changed from “void run()” to “bool run()”, but I’ve done it by calling getAlertWindow()->exitModalState(0);
I don’t like passing “hidden” expectation like cancel button always returning “0” in the modal loop. If any day you change this, it’ll be quite impossible to debug.
What do you think of this, then:

void AlertWindow::triggerClick(const String & buttonName)
{
     if (buttonName == "Cancel") { exitModalState(0); return; } // Or whatever the current mapping 
     if (buttonName == "Ok") { exitModalState(1); return; }
     [...]
}

It would probably be more explicit ?


#4

Maybe I’m still not understanding correctly, but it’s certainly true that setVisible(false) will exit the modal loop, just like calling exitModalState(0).

But yes, there’s certainly an argument for adding an explicit way to trigger a button click - I’ll add something for that…