message box

This commit is contained in:
Vadim Lopatin 2014-12-22 16:04:58 +03:00
parent 7fc0e7eee9
commit 1a2a5f1aae
5 changed files with 37 additions and 13 deletions
dlanguilib.visualdproj
examples/example1/src
src/dlangui
core
dialogs
platforms/common

View File

@ -305,6 +305,7 @@
<Folder name="dialogs">
<File path="src\dlangui\dialogs\dialog.d" />
<File path="src\dlangui\dialogs\filedlg.d" />
<File path="src\dlangui\dialogs\msgbox.d" />
</Folder>
<Folder name="graphics">
<File path="src\dlangui\graphics\drawbuf.d" />

View File

@ -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;

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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();
}
}
/**