add LineEdit enterKey signal

This commit is contained in:
Vadim Lopatin 2017-09-14 13:56:43 +03:00
parent 364a02da9d
commit e78cd9a63b
4 changed files with 32 additions and 18 deletions

View File

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

View File

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

View File

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

View File

@ -1 +1 @@
v0.9.132
v0.9.133