diff options
| author | Stéphane Bégaudeau | 2016-09-19 11:42:44 +0000 |
|---|---|---|
| committer | Stéphane Bégaudeau | 2016-09-21 09:03:20 +0000 |
| commit | 4362682bdb9fd3db5d9065eb2bb81a10c59af8bd (patch) | |
| tree | d1e629d5ead472770a22baa5e3c2f4b74550f2bc | |
| parent | 7ee72dbb8e181856ebce4ad02272068473d29cbd (diff) | |
| download | org.eclipse.eef-4362682bdb9fd3db5d9065eb2bb81a10c59af8bd.tar.gz org.eclipse.eef-4362682bdb9fd3db5d9065eb2bb81a10c59af8bd.tar.xz org.eclipse.eef-4362682bdb9fd3db5d9065eb2bb81a10c59af8bd.zip | |
[501709] Pressing enter should trigger the update of a mono-line text
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=501709
Change-Id: Ie9a55edaba4af3a047c6810e14afd621daf16df9
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
3 files changed, 33 insertions, 0 deletions
diff --git a/doc/org.eclipse.eef.documentation/pages/releasenotes.html b/doc/org.eclipse.eef.documentation/pages/releasenotes.html index eb2bd4993..312ca9826 100644 --- a/doc/org.eclipse.eef.documentation/pages/releasenotes.html +++ b/doc/org.eclipse.eef.documentation/pages/releasenotes.html @@ -34,6 +34,8 @@ <code>java.lang.Object#toString()</code> operation. </li> <li><span class="label label-success">Added</span> A new widget named List has been added, it has the same behavior as the multiple reference widget of the previous release.</li> + <li><span class="label label-info">Modified</span> The edit operation of a text field can now be triggered by the loss of focus on the text field.</li> + <li><span class="label label-info">Modified</span> The edit operation of a mono-line text field can now be triggered by pressing enter.</li> </ul> <h4 id="DeveloperVisibleChanges">Developer-Visible Changes</h4> <ul> diff --git a/doc/org.eclipse.eef.documentation/pages/releasenotes.textile b/doc/org.eclipse.eef.documentation/pages/releasenotes.textile index 5fef0fad9..4689b18e1 100644 --- a/doc/org.eclipse.eef.documentation/pages/releasenotes.textile +++ b/doc/org.eclipse.eef.documentation/pages/releasenotes.textile @@ -17,6 +17,8 @@ h4. Specifier-Visible Changes * <span class="label label-success">Added</span> Widget actions are now available on labels and hyperlinks. * <span class="label label-success">Added</span> Labels and hyperlinks now have a displayExpression. If unused, the result of the valueExpression will be converted to a string using the @java.lang.Object#toString()@ operation. * <span class="label label-success">Added</span> A new widget named List has been added, it has the same behavior as the multiple reference widget of the previous release. +* <span class="label label-info">Modified</span> The edit operation of a text field can now be triggered by the loss of focus on the text field. +* <span class="label label-info">Modified</span> The edit operation of a mono-line text field can now be triggered by pressing enter. h4. Developer-Visible Changes diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java index 9c04b82cd..3b8188cef 100644 --- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java +++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java @@ -32,6 +32,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; @@ -73,6 +75,11 @@ public class EEFTextLifecycleManager extends AbstractEEFWidgetLifecycleManager { private FocusListener focusListener; /** + * The key listener on the text field (unused for a multi-line text field). + */ + private KeyListener keyListener; + + /** * The widget factory. */ private EEFWidgetFactory widgetFactory; @@ -194,6 +201,24 @@ public class EEFTextLifecycleManager extends AbstractEEFWidgetLifecycleManager { }; this.text.addFocusListener(this.focusListener); + if (this.description.getLineCount() <= 1) { + this.keyListener = new KeyListener() { + @Override + public void keyReleased(KeyEvent e) { + if (e.character == '\r' || e.character == '\n') { + controller.updateValue(text.getText()); + EEFTextLifecycleManager.this.setStyle(); + } + } + + @Override + public void keyPressed(KeyEvent e) { + // do nothing + } + }; + this.text.addKeyListener(this.keyListener); + } + this.controller.onNewValue(new IConsumer<Object>() { @Override public void apply(Object value) { @@ -248,6 +273,10 @@ public class EEFTextLifecycleManager extends AbstractEEFWidgetLifecycleManager { this.text.removeFocusListener(this.focusListener); } this.controller.removeNewValueConsumer(); + + if (this.description.getLineCount() <= 1) { + this.text.removeKeyListener(this.keyListener); + } } /** |
