From e78cd9a63b5b8fa1236c38b0e44b229b201e2771 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 14 Sep 2017 13:56:43 +0300 Subject: [PATCH] add LineEdit enterKey signal --- src/dlangui/dialogs/filedlg.d | 19 +++++++++++-------- src/dlangui/dialogs/inputbox.d | 13 ++++--------- src/dlangui/widgets/editors.d | 16 ++++++++++++++++ views/DLANGUI_VERSION | 2 +- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/dlangui/dialogs/filedlg.d b/src/dlangui/dialogs/filedlg.d index c776e56b..4e3e72f1 100644 --- a/src/dlangui/dialogs/filedlg.d +++ b/src/dlangui/dialogs/filedlg.d @@ -1078,7 +1078,7 @@ class FilePathPanel : FrameLayout { _segments = new FilePathPanelButtons(ID_SEGMENTS); _edPath = new EditLine(ID_EDITOR); _edPath.layoutWidth = FILL_PARENT; - _edPath.editorAction = &onEditorAction; + _edPath.enterKey = &onEnterKey; _edPath.focusChange = &onEditorFocusChanged; _segments.click = &onSegmentsClickOutside; _segments.onPathSelectionListener = &onPathSelected; @@ -1106,13 +1106,11 @@ class FilePathPanel : FrameLayout { _edPath.setFocus(); return true; } - protected bool onEditorAction(const Action action) { - if (action.id == EditorActions.InsertNewLine) { - string fn = buildNormalizedPath(toUTF8(_edPath.text)); - if (exists(fn) && isDir(fn)) - return onPathSelected(fn); - } - return false; + protected bool onEnterKey(EditWidgetBase editor) { + string fn = buildNormalizedPath(toUTF8(_edPath.text)); + if (exists(fn) && isDir(fn)) + onPathSelected(fn); + return true; } @property void path(string value) { @@ -1144,6 +1142,11 @@ class FileNameEditLine : HorizontalLayout { return _edFileName.editorAction; } + /// handle Enter key press inside line editor + @property ref Signal!EnterKeyHandler enterKey() { + return _edFileName.enterKey; + } + this(string ID = null) { super(ID); _caption = UIString.fromId("TITLE_OPEN_FILE"c).value; diff --git a/src/dlangui/dialogs/inputbox.d b/src/dlangui/dialogs/inputbox.d index aeee2780..50ab0f41 100644 --- a/src/dlangui/dialogs/inputbox.d +++ b/src/dlangui/dialogs/inputbox.d @@ -37,7 +37,10 @@ class InputBox : Dialog { _editor = new EditLine("inputbox_editor"); _editor.layoutWidth = FILL_PARENT; _editor.text = _text; - _editor.editorAction.connect(&onEditorAction); + _editor.enterKey = delegate (EditWidgetBase editor) { + close(_buttonActions[_defaultButtonIndex]); + return true; + }; _editor.contentChange = delegate(EditableContent content) { _text = content.text; }; @@ -46,14 +49,6 @@ class InputBox : Dialog { addChild(createButtonsPanel(_actions, _defaultButtonIndex, 0)); } - protected bool onEditorAction(const Action action) { - if (action.id == EditorActions.InsertNewLine) { - close(_buttonActions[_defaultButtonIndex]); - return true; - } - return false; - } - /// called after window with dialog is shown override void onShow() { super.onShow(); diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index a62bc48d..cd57c575 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -1942,10 +1942,16 @@ interface EditorActionHandler { bool onEditorAction(const Action action); } +interface EnterKeyHandler { + bool onEnterKey(EditWidgetBase editor); +} + /// single line editor class EditLine : EditWidgetBase { Signal!EditorActionHandler editorAction; + /// handle Enter key press inside line editor + Signal!EnterKeyHandler enterKey; /// empty parameter list constructor - for usage by factory this() { @@ -2094,6 +2100,16 @@ class EditLine : EditWidgetBase { /// handle keys override bool onKeyEvent(KeyEvent event) { + if (enterKey.assigned) { + if (event.keyCode == KeyCode.RETURN && event.modifiers == 0) { + if (event.action == KeyAction.KeyDown) + return true; + if (event.action == KeyAction.KeyUp) { + if (enterKey(this)) + return true; + } + } + } return super.onKeyEvent(event); } diff --git a/views/DLANGUI_VERSION b/views/DLANGUI_VERSION index 0680d6cd..c49ac811 100644 --- a/views/DLANGUI_VERSION +++ b/views/DLANGUI_VERSION @@ -1 +1 @@ -v0.9.132 \ No newline at end of file +v0.9.133 \ No newline at end of file