1 module dlangui.dialogs.inputbox; 2 3 import dlangui.core.i18n; 4 import dlangui.core.signals; 5 import dlangui.core.stdaction; 6 import dlangui.widgets.layouts; 7 import dlangui.widgets.controls; 8 import dlangui.widgets.editors; 9 import dlangui.platforms.common.platform; 10 import dlangui.dialogs.dialog; 11 12 /// Message box 13 class InputBox : Dialog { 14 protected UIString _message; 15 protected const(Action)[] _actions; 16 protected EditLine _editor; 17 protected dstring _text; 18 this(UIString caption, UIString message, Window parentWindow, dstring initialText, void delegate(dstring result) handler) { 19 super(caption, parentWindow, DialogFlag.Modal | (Platform.instance.uiDialogDisplayMode & DialogDisplayMode.inputBoxInPopup ? DialogFlag.Popup : 0)); 20 _message = message; 21 _actions = [ACTION_OK, ACTION_CANCEL]; 22 _defaultButtonIndex = 0; 23 _text = initialText; 24 if (handler) { 25 dialogResult = delegate (Dialog dlg, const Action action) { 26 if (action.id == ACTION_OK.id) { 27 handler(_text); 28 } 29 }; 30 } 31 } 32 /// override to implement creation of dialog controls 33 override void initialize() { 34 TextWidget msg = new MultilineTextWidget("msg", _message); 35 padding(Rect(10, 10, 10, 10)); 36 msg.padding(Rect(10, 10, 10, 10)); 37 _editor = new EditLine("inputbox_editor"); 38 _editor.layoutWidth = FILL_PARENT; 39 _editor.text = _text; 40 _editor.enterKey = delegate (EditWidgetBase editor) { 41 close(_buttonActions[_defaultButtonIndex]); 42 return true; 43 }; 44 _editor.contentChange = delegate(EditableContent content) { 45 _text = content.text; 46 }; 47 addChild(msg); 48 addChild(_editor); 49 addChild(createButtonsPanel(_actions, _defaultButtonIndex, 0)); 50 } 51 52 /// called after window with dialog is shown 53 override void onShow() { 54 super.onShow(); 55 _editor.selectAll(); 56 _editor.setFocus(); 57 } 58 }