From c32df24ad90d00a76d09d41c2bc02d021b144719 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Fri, 22 Apr 2016 12:17:11 +0300 Subject: [PATCH] ComboEdit enhancements - issue #224 --- examples/helloworld/src/helloworld.d | 1 + src/dlangui/widgets/combobox.d | 33 ++++++++++++++++++++++------ src/dlangui/widgets/editors.d | 6 +++++ src/dlangui/widgets/lists.d | 8 +++++++ 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/examples/helloworld/src/helloworld.d b/examples/helloworld/src/helloworld.d index df5d1f53..506fddce 100644 --- a/examples/helloworld/src/helloworld.d +++ b/examples/helloworld/src/helloworld.d @@ -49,6 +49,7 @@ extern (C) int UIAppMain(string[] args) { ComboEdit { id: ce1; text: "some text"; minWidth: 100; items: ["Item 1", "Item 2", "Additional item"] } } } + EditBox { layoutWidth: 300; layoutHeight: 80 } HorizontalLayout { Button { id: btnOk; text: "Ok" } Button { id: btnCancel; text: "Cancel" } diff --git a/src/dlangui/widgets/combobox.d b/src/dlangui/widgets/combobox.d index 6768fc7b..135321d3 100644 --- a/src/dlangui/widgets/combobox.d +++ b/src/dlangui/widgets/combobox.d @@ -118,6 +118,9 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler { _button.layout(rc); } + protected void popupClosed() { + } + protected void showPopup() { if (!_adapter || !_adapter.itemCount) return; // don't show empty popup @@ -138,6 +141,7 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler { if (_popup !is null) { _popup.close(); _popup = null; + popupClosed(); } return true; }; @@ -490,14 +494,29 @@ class ComboEdit : ComboBox { focusable = false; clickable = false; _edit.focusable = true; - keyEvent = delegate(Widget source, KeyEvent event) { - if (event.keyCode == KeyCode.DOWN) { - if (event.action == KeyAction.KeyDown) { - showPopup(); - } + } + + /// process key event, return true if event is processed. + override bool onKeyEvent(KeyEvent event) { + if (event.keyCode == KeyCode.DOWN && enabled) { + if (event.action == KeyAction.KeyDown) { + showPopup(); } - return _edit.onKeyEvent(event); - }; + return true; + } + if ((event.keyCode == KeyCode.SPACE || event.keyCode == KeyCode.RETURN) && readOnly && enabled) { + if (event.action == KeyAction.KeyDown) { + showPopup(); + } + return true; + } + if (_edit.onKeyEvent(event)) + return true; + return super.onKeyEvent(event); + } + + override protected void popupClosed() { + _edit.setFocus(); } // called to process click and notify listeners diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index d1de89a4..1ea5304d 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -1624,6 +1624,12 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction } return true; } + if (event.keyCode == KeyCode.SPACE && !readOnly) { + return true; + } + if (event.keyCode == KeyCode.RETURN && !readOnly && !_content.multiline) { + return true; + } return super.onKeyEvent(event); } diff --git a/src/dlangui/widgets/lists.d b/src/dlangui/widgets/lists.d index 579fcfa1..a500fc71 100644 --- a/src/dlangui/widgets/lists.d +++ b/src/dlangui/widgets/lists.d @@ -1211,6 +1211,14 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler { // TODO } } + if ((event.keyCode == KeyCode.SPACE || event.keyCode == KeyCode.RETURN)) { + if (event.action == KeyAction.KeyDown && enabled) { + if (itemEnabled(_selectedItemIndex)) { + itemClicked(_selectedItemIndex); + } + } + return true; + } return super.onKeyEvent(event); //if (_selectedItemIndex != -1 && event.action == KeyAction.KeyUp && (event.keyCode == KeyCode.SPACE || event.keyCode == KeyCode.RETURN)) { // itemClicked(_selectedItemIndex);