diff --git a/dlanguilib.visualdproj b/dlanguilib.visualdproj
index 7a330f81..3b55b66e 100644
--- a/dlanguilib.visualdproj
+++ b/dlanguilib.visualdproj
@@ -305,6 +305,7 @@
+
diff --git a/examples/example1/src/main.d b/examples/example1/src/main.d
index 1749c6ea..cdc55c58 100644
--- a/examples/example1/src/main.d
+++ b/examples/example1/src/main.d
@@ -18,6 +18,7 @@ module main;
import dlangui.all;
import dlangui.dialogs.dialog;
import dlangui.dialogs.filedlg;
+import dlangui.dialogs.msgbox;
import std.stdio;
import std.conv;
import std.utf;
@@ -295,6 +296,9 @@ extern (C) int UIAppMain(string[] args) {
FileDialog dlg = new FileDialog(caption, window, null);
dlg.onDialogResult = delegate(Dialog dlg, const Action result) {
Log.d("FileDialog.onDialogResult: ", result, " param=", result.stringParam);
+ window.showMessageBox(UIString("FileOpen result"d), UIString(toUTF32(result.stringParam)));
+ import dlangui.core.stdaction;
+
};
dlg.show();
return true;
diff --git a/src/dlangui/core/stdaction.d b/src/dlangui/core/stdaction.d
index 3163890c..d9d57fbf 100644
--- a/src/dlangui/core/stdaction.d
+++ b/src/dlangui/core/stdaction.d
@@ -32,20 +32,20 @@ enum StandardAction : int {
Save,
}
-immutable Action ACTION_OK;
-immutable Action ACTION_CANCEL;
-immutable Action ACTION_YES;
-immutable Action ACTION_NO;
-immutable Action ACTION_CLOSE;
-immutable Action ACTION_ABORT;
-immutable Action ACTION_RETRY;
-immutable Action ACTION_IGNORE;
-immutable Action ACTION_OPEN;
-immutable Action ACTION_SAVE;
+const Action ACTION_OK;
+const Action ACTION_CANCEL;
+const Action ACTION_YES;
+const Action ACTION_NO;
+const Action ACTION_CLOSE;
+const Action ACTION_ABORT;
+const Action ACTION_RETRY;
+const Action ACTION_IGNORE;
+const Action ACTION_OPEN;
+const Action ACTION_SAVE;
static this()
{
- ACTION_OK = cast(immutable(Action)) new Action(StandardAction.Ok, "ACTION_OK"c);
+ ACTION_OK = new Action(StandardAction.Ok, "ACTION_OK"c);
ACTION_CANCEL = cast(immutable(Action)) new Action(StandardAction.Cancel, "ACTION_CANCEL"c);
ACTION_YES = cast(immutable(Action)) new Action(StandardAction.Yes, "ACTION_YES"c);
ACTION_NO = cast(immutable(Action)) new Action(StandardAction.No, "ACTION_NO"c);
diff --git a/src/dlangui/dialogs/dialog.d b/src/dlangui/dialogs/dialog.d
index 5b825496..56b86d68 100644
--- a/src/dlangui/dialogs/dialog.d
+++ b/src/dlangui/dialogs/dialog.d
@@ -4,10 +4,12 @@
This module contains common Dialog implementation.
+Use to create custom dialogs.
+
Synopsis:
----
-import dlangui.platforms.common.platform;
+import dlangui.dialogs.dialog;
----
@@ -19,6 +21,7 @@ module dlangui.dialogs.dialog;
import dlangui.core.i18n;
import dlangui.core.signals;
+import dlangui.core.stdaction;
import dlangui.widgets.layouts;
import dlangui.widgets.controls;
import dlangui.platforms.common.platform;
@@ -33,6 +36,7 @@ enum DialogFlag : uint {
Resizable = 2,
}
+/// slot to pass dialog result
interface DialogResultHandler {
public void onDialogResult(Dialog dlg, const Action result);
}
@@ -90,6 +94,7 @@ class Dialog : VerticalLayout {
protected const(Action) [] _buttonActions;
+ protected ImageTextButton _defaultButton;
/// create panel with buttons based on list of actions
Widget createButtonsPanel(const(Action) [] actions, int defaultActionIndex, int splitBeforeIndex) {
_buttonActions = actions;
@@ -102,8 +107,10 @@ class Dialog : VerticalLayout {
const Action a = actions[i];
string id = "btn" ~ to!string(a.id);
ImageTextButton btn = new ImageTextButton(id, a.iconId, a.label);
- if (defaultActionIndex == i)
+ if (defaultActionIndex == i) {
btn.setState(State.Default);
+ _defaultButton = btn;
+ }
btn.action = a.clone();
res.addChild(btn);
}
@@ -161,5 +168,8 @@ class Dialog : VerticalLayout {
/// called after window with dialog is shown
void onShow() {
// override to do something useful
+ if (_defaultButton)
+ _defaultButton.setFocus();
}
}
+
diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d
index 0641ac64..abfb7502 100644
--- a/src/dlangui/platforms/common/platform.d
+++ b/src/dlangui/platforms/common/platform.d
@@ -24,6 +24,8 @@ import dlangui.core.collections;
import dlangui.widgets.widget;
import dlangui.widgets.popup;
import dlangui.graphics.drawbuf;
+import dlangui.core.stdaction;
+import dlangui.dialogs.msgbox;
private import dlangui.graphics.gldrawbuf;
private import std.algorithm;
@@ -597,6 +599,13 @@ class Window {
abstract void invalidate();
/// close window
abstract void close();
+
+ /// Show message box with specified title and message
+ void showMessageBox(UIString title, UIString message, const (Action)[] actions = [ACTION_OK], int defaultActionIndex = 0, bool delegate(const Action result) handler = null) {
+ MessageBox dlg = new MessageBox(title, message, this, actions, defaultActionIndex, handler);
+ dlg.show();
+ }
+
}
/**