file open dialog - continue development

This commit is contained in:
Vadim Lopatin 2014-07-07 10:22:31 +04:00
parent cee53890a7
commit 60b5f084d4
3 changed files with 64 additions and 4 deletions

View File

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

View File

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

View File

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