1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

AlertWindow: Add 'getButton' method

This commit is contained in:
Oliver James 2023-03-20 14:53:38 +00:00
parent 9d909fc3fe
commit d7f1e59422
2 changed files with 32 additions and 8 deletions

View file

@ -150,16 +150,24 @@ int AlertWindow::getNumButtons() const
return buttons.size();
}
Button* AlertWindow::getButton (int index) const
{
return buttons[index];
}
Button* AlertWindow::getButton (const String& buttonName) const
{
for (auto* button : buttons)
if (buttonName == button->getName())
return button;
return nullptr;
}
void AlertWindow::triggerButtonClick (const String& buttonName)
{
for (auto* b : buttons)
{
if (buttonName == b->getName())
{
b->triggerClick();
break;
}
}
if (auto* button = getButton (buttonName))
button->triggerClick();
}
void AlertWindow::setEscapeKeyCancels (bool shouldEscapeKeyCancel)

View file

@ -92,6 +92,22 @@ public:
/** Returns the number of buttons that the window currently has. */
int getNumButtons() const;
/** Returns a Button that was added to the AlertWindow.
@param index the index of the button in order that it was added with the addButton() method.
@returns the Button component, or nullptr if the index is out of bounds.
@see getNumButtons
*/
Button* getButton (int index) const;
/** Returns a Button that was added to the AlertWindow.
@param buttonName the name that was passed into the addButton() method
@returns the Button component, or nullptr if none was found for the given name.
*/
Button* getButton (const String& buttonName) const;
/** Invokes a click of one of the buttons. */
void triggerButtonClick (const String& buttonName);