-
Notifications
You must be signed in to change notification settings - Fork 15
/
messagebox.d
64 lines (57 loc) · 1.7 KB
/
messagebox.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
Message box implementation.
Synopsis:
---
// show message box with single Ok button
new MessageBox(window, "Dialog title"d, "Some message"d).show();
// show message box with OK and CANCEL buttons, cancel by default, and handle its result
new MessageBox(
window,
tr("Dialog title"), tr("Some message"),
[ACTION_OK, ACTION_CANCEL], 1, (a) {
if (a is ACTION_OK)
Log.d("OK pressed");
else if (a is ACTION_CANCEL)
Log.d("CANCEL pressed");
}
).show();
---
Copyright: Vadim Lopatin 2014-2017
License: Boost License 1.0
Authors: Vadim Lopatin
*/
module beamui.dialogs.messagebox;
/+
import beamui.core.actions;
import beamui.core.i18n;
import beamui.core.signals;
import beamui.core.stdaction;
import beamui.dialogs.dialog;
import beamui.platforms.common.platform;
import beamui.widgets.text;
/// Message box
class MessageBox : Dialog
{
private dstring _message;
private Action[] _actions;
/// Create a message box with specified title and message
this(Window parentWindow, dstring caption, dstring message,
Action[] buttons = [ACTION_OK], int defaultButtonIndex = 0,
void delegate(const Action result) handler = null)
{
super(caption, parentWindow, DialogFlag.modal |
(platform.uiDialogDisplayMode & DialogDisplayMode.messageBoxInPopup ? DialogFlag.popup : 0));
_message = message;
_actions = buttons;
_defaultButtonIndex = defaultButtonIndex;
if (handler)
onClose ~= handler;
}
override void initialize()
{
auto msg = new Label(_message);
addChild(msg);
addChild(createButtonsPanel(_actions, _defaultButtonIndex, 0));
}
}
+/