mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-03 03:30:06 +00:00
Added a new method NativeMessageBox::showMessageBox which asynchronously opens a native dialog box and calls a C++ lambda when dismissed
This commit is contained in:
parent
e2c8e30d72
commit
8483aa4aea
2 changed files with 65 additions and 4 deletions
|
|
@ -725,4 +725,35 @@ bool AlertWindow::showNativeDialogBox (const String& title,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
struct NativeMessageBoxCallback : ModalComponentManager::Callback
|
||||||
|
{
|
||||||
|
NativeMessageBoxCallback (std::function<void (int)> && lambda)
|
||||||
|
: callback (static_cast<std::function<void (int)>&&> (lambda))
|
||||||
|
{}
|
||||||
|
|
||||||
|
void modalStateFinished (int returnValue) override { if (callback) callback (returnValue); }
|
||||||
|
|
||||||
|
std::function<void (int)> callback;
|
||||||
|
|
||||||
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeMessageBoxCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
void NativeMessageBox::showMessageBox (MessageBoxType dialogType, AlertWindow::AlertIconType iconType,
|
||||||
|
const String& title, const String& message,
|
||||||
|
std::function<void (int)> && lambda, Component* associatedComponent)
|
||||||
|
{
|
||||||
|
auto* callback = new NativeMessageBoxCallback (static_cast<std::function<void (int)>&&> (lambda));
|
||||||
|
|
||||||
|
switch (dialogType)
|
||||||
|
{
|
||||||
|
case okType: showMessageBoxAsync (iconType, title, message, associatedComponent, callback); break;
|
||||||
|
case okCancelType: showOkCancelBox (iconType, title, message, associatedComponent, callback); break;
|
||||||
|
case yesNoType: showYesNoBox (iconType, title, message, associatedComponent, callback); break;
|
||||||
|
case yesNoCancelType: showYesNoCancelBox (iconType, title, message, associatedComponent, callback); break;
|
||||||
|
default:
|
||||||
|
jassertfalse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace juce
|
} // namespace juce
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,15 @@ namespace juce
|
||||||
class NativeMessageBox
|
class NativeMessageBox
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/** A set of enums describing the type of dialog box */
|
||||||
|
enum MessageBoxType
|
||||||
|
{
|
||||||
|
okType, /** A message box with a simple ok button. */
|
||||||
|
okCancelType, /** A message box with an ok and cancel button. */
|
||||||
|
yesNoType, /** A message box with a yes and no button. */
|
||||||
|
yesNoCancelType, /** A message box with a yes, no and cancel button. */
|
||||||
|
};
|
||||||
|
|
||||||
/** Shows a dialog box that just has a message and a single 'ok' button to close it.
|
/** Shows a dialog box that just has a message and a single 'ok' button to close it.
|
||||||
|
|
||||||
The box is shown modally, and the method will block until the user has clicked its
|
The box is shown modally, and the method will block until the user has clicked its
|
||||||
|
|
@ -53,6 +62,27 @@ public:
|
||||||
Component* associatedComponent = nullptr);
|
Component* associatedComponent = nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Shows a dialog box asynchronously triggering a lambda when the user dismisses the box.
|
||||||
|
|
||||||
|
The box will be displayed and placed into a modal state, but this method will return
|
||||||
|
immediately, and the lambda will be invoked later when the user dismisses the box.
|
||||||
|
|
||||||
|
@param dialogType the type of the dialog
|
||||||
|
@param iconType the type of icon to show
|
||||||
|
@param title the headline to show at the top of the box
|
||||||
|
@param message a longer, more descriptive message to show underneath the title
|
||||||
|
@param lambda a lambda which will be triggered when the box is dismissed
|
||||||
|
@param associatedComponent if this is non-null, it specifies the component that the
|
||||||
|
alert window should be associated with. Depending on the look
|
||||||
|
and feel, this might be used for positioning of the alert window.
|
||||||
|
*/
|
||||||
|
static void JUCE_CALLTYPE showMessageBox (MessageBoxType dialogType,
|
||||||
|
AlertWindow::AlertIconType iconType,
|
||||||
|
const String& title,
|
||||||
|
const String& message,
|
||||||
|
std::function<void (int)> && lambda = {},
|
||||||
|
Component* associatedComponent = nullptr);
|
||||||
|
|
||||||
/** Shows a dialog box that just has a message and a single 'ok' button to close it.
|
/** Shows a dialog box that just has a message and a single 'ok' button to close it.
|
||||||
|
|
||||||
The box will be displayed and placed into a modal state, but this method will return
|
The box will be displayed and placed into a modal state, but this method will return
|
||||||
|
|
@ -71,10 +101,10 @@ public:
|
||||||
before it gets called.
|
before it gets called.
|
||||||
*/
|
*/
|
||||||
static void JUCE_CALLTYPE showMessageBoxAsync (AlertWindow::AlertIconType iconType,
|
static void JUCE_CALLTYPE showMessageBoxAsync (AlertWindow::AlertIconType iconType,
|
||||||
const String& title,
|
const String& title,
|
||||||
const String& message,
|
const String& message,
|
||||||
Component* associatedComponent = nullptr,
|
Component* associatedComponent = nullptr,
|
||||||
ModalComponentManager::Callback* callback = nullptr);
|
ModalComponentManager::Callback* callback = nullptr);
|
||||||
|
|
||||||
/** Shows a dialog box with two buttons.
|
/** Shows a dialog box with two buttons.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue