From 60b5f084d4aed974391b28d23ad2d762c1929bfe Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 7 Jul 2014 10:22:31 +0400 Subject: [PATCH] file open dialog - continue development --- examples/example1/src/main.d | 15 +++++++++++++ src/dlangui/dialogs/dialog.d | 40 ++++++++++++++++++++++++++++++++--- src/dlangui/dialogs/filedlg.d | 13 +++++++++++- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/examples/example1/src/main.d b/examples/example1/src/main.d index f4c39c29..06c9018d 100644 --- a/examples/example1/src/main.d +++ b/examples/example1/src/main.d @@ -16,6 +16,7 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com module main; import dlangui.all; +import dlangui.dialogs.dialog; import dlangui.dialogs.filedlg; import std.stdio; import std.conv; @@ -92,6 +93,17 @@ class AnimatedDrawable : Drawable { } +class TextEditorWidget : VerticalLayout { + EditBox _edit; + this(string ID) { + super(ID); + _edit = new EditBox("editor"); + _edit.layoutWidth = FILL_PARENT; + _edit.layoutHeight = FILL_PARENT; + addChild(_edit); + } +} + class SampleAnimationWidget : VerticalLayout { AnimatedDrawable drawable; DrawableRef drawableRef; @@ -280,6 +292,9 @@ extern (C) int UIAppMain(string[] args) { UIString caption; caption = "Open Text File"d; FileDialog dlg = new FileDialog(caption, window); + dlg.onDialogResult = delegate(Dialog dlg, Action result) { + // + }; dlg.show(); return true; } else if (window.focusedWidget) diff --git a/src/dlangui/dialogs/dialog.d b/src/dlangui/dialogs/dialog.d index 4908ce86..0ee5f8ae 100644 --- a/src/dlangui/dialogs/dialog.d +++ b/src/dlangui/dialogs/dialog.d @@ -18,9 +18,12 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com module dlangui.dialogs.dialog; import dlangui.core.i18n; +import dlangui.core.signals; import dlangui.widgets.layouts; import dlangui.widgets.controls; -import dlangui.platforms.common.platform; +import dlangui.platforms.common.platform; + +import std.conv; /// dialog flag bits enum DialogFlag : uint { @@ -29,13 +32,19 @@ enum DialogFlag : uint { /// dialog can be resized Resizable = 2, } + +interface DialogResultHandler { + public void onDialogResult(Dialog dlg, Action result); +} /// base for all dialogs class Dialog : VerticalLayout { protected Window _window; protected Window _parentWindow; protected UIString _caption; - protected uint _flags; + protected uint _flags; + + Signal!DialogResultHandler onDialogResult; this(UIString caption, Window parentWindow = null, uint flags = DialogFlag.Modal) { super("dlg"); @@ -60,9 +69,34 @@ class Dialog : VerticalLayout { _window.windowCaption = caption; return this; } + + /// create panel with buttons based on list of actions + Widget createButtonsPanel(const Action[] actions, int defaultActionIndex, int splitBeforeIndex) { + LinearLayout res = new HorizontalLayout("buttons"); + res.layoutWidth(FILL_PARENT); + for (int i = 0; i < actions.length; i++) { + if (splitBeforeIndex == i) + res.addChild(new HSpacer()); + const Action a = actions[i]; + string id = "btn" ~ to!string(a.id); + ImageTextButton btn = new ImageTextButton(id, a.iconId, a.label); + if (defaultActionIndex == i) + btn.setState(State.Default); + btn.onClickListener = delegate(Widget source) { + return handleAction(a); + }; + res.addChild(btn); + } + return res; + } + + /// override to implement creation of dialog controls + void init() { + } /// shows dialog - void show() { + void show() { + init(); uint wflags = 0; if (_flags & DialogFlag.Modal) wflags |= WindowFlag.Modal; diff --git a/src/dlangui/dialogs/filedlg.d b/src/dlangui/dialogs/filedlg.d index 813b93e6..6ff434b6 100644 --- a/src/dlangui/dialogs/filedlg.d +++ b/src/dlangui/dialogs/filedlg.d @@ -25,11 +25,13 @@ module dlangui.dialogs.filedlg; import dlangui.core.events; import dlangui.core.i18n; +import dlangui.core.stdaction; import dlangui.widgets.controls; import dlangui.widgets.lists; import dlangui.widgets.popup; +import dlangui.widgets.layouts; import dlangui.platforms.common.platform; -import dlangui.dialogs.dialog; +import dlangui.dialogs.dialog; /// flags for file dialog options enum FileDialogFlag : uint { @@ -48,4 +50,13 @@ class FileDialog : Dialog { this(UIString caption, Window parent, uint fileDialogFlags = DialogFlag.Modal | FileDialogFlag.FileMustExist) { super(caption, parent, fileDialogFlags); } + /// override to implement creation of dialog controls + override void init() { + layoutWidth(FILL_PARENT); + layoutWidth(FILL_PARENT); + LinearLayout content = new LinearLayout("dlgcontent"); + content.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).minWidth(400).minHeight(300); + addChild(content); + addChild(createButtonsPanel([ACTION_OK, ACTION_CANCEL], 0, 1)); + } }