mirror of https://github.com/buggins/dlangui.git
file open dialog - continue development
This commit is contained in:
parent
cee53890a7
commit
60b5f084d4
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -18,10 +18,13 @@ 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 std.conv;
|
||||
|
||||
/// dialog flag bits
|
||||
enum DialogFlag : uint {
|
||||
/// dialog is modal
|
||||
|
|
@ -30,6 +33,10 @@ enum DialogFlag : uint {
|
|||
Resizable = 2,
|
||||
}
|
||||
|
||||
interface DialogResultHandler {
|
||||
public void onDialogResult(Dialog dlg, Action result);
|
||||
}
|
||||
|
||||
/// base for all dialogs
|
||||
class Dialog : VerticalLayout {
|
||||
protected Window _window;
|
||||
|
|
@ -37,6 +44,8 @@ class Dialog : VerticalLayout {
|
|||
protected UIString _caption;
|
||||
protected uint _flags;
|
||||
|
||||
Signal!DialogResultHandler onDialogResult;
|
||||
|
||||
this(UIString caption, Window parentWindow = null, uint flags = DialogFlag.Modal) {
|
||||
super("dlg");
|
||||
_caption = caption;
|
||||
|
|
@ -61,8 +70,33 @@ class Dialog : VerticalLayout {
|
|||
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() {
|
||||
init();
|
||||
uint wflags = 0;
|
||||
if (_flags & DialogFlag.Modal)
|
||||
wflags |= WindowFlag.Modal;
|
||||
|
|
|
|||
|
|
@ -25,9 +25,11 @@ 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;
|
||||
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue