Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2011-09-05 11:19:09 +0000
committercletavernie2011-09-05 11:19:09 +0000
commit61a9f06c5d519115b407b154d581455930633148 (patch)
tree179de9f6b81acb0d30871657f2cfc9a14f608c40
parent2bbc86530a96c55503cec9cc55d5582ca6c11fb0 (diff)
downloadorg.eclipse.papyrus-61a9f06c5d519115b407b154d581455930633148.tar.gz
org.eclipse.papyrus-61a9f06c5d519115b407b154d581455930633148.tar.xz
org.eclipse.papyrus-61a9f06c5d519115b407b154d581455930633148.zip
356566: [Widgets] Add support for Ctrl+Enter in multi-line text editors
https://bugs.eclipse.org/bugs/show_bug.cgi?id=356566
-rw-r--r--plugins/core/org.eclipse.papyrus.widgets/src/org/eclipse/papyrus/widgets/editors/StringEditor.java21
1 files changed, 15 insertions, 6 deletions
diff --git a/plugins/core/org.eclipse.papyrus.widgets/src/org/eclipse/papyrus/widgets/editors/StringEditor.java b/plugins/core/org.eclipse.papyrus.widgets/src/org/eclipse/papyrus/widgets/editors/StringEditor.java
index f5cffd9c42f..9b8967bed67 100644
--- a/plugins/core/org.eclipse.papyrus.widgets/src/org/eclipse/papyrus/widgets/editors/StringEditor.java
+++ b/plugins/core/org.eclipse.papyrus.widgets/src/org/eclipse/papyrus/widgets/editors/StringEditor.java
@@ -25,6 +25,7 @@ import org.eclipse.swt.widgets.Text;
* as a Text.
* This editor's content is validated when the focus is lost,
* or, if the editor is single-line, when the Carriage Return is pressed.
+ * For a multi-line editor, ctrl+enter will also validate the editor's content.
*
* @see SWT#MULTI
*
@@ -78,10 +79,7 @@ public class StringEditor extends AbstractValueEditor implements KeyListener {
super.label.setLayoutData(getLabelLayoutData());
}
- //We listen on Carriage Return only if the editor isn't multiline
- if((style & SWT.MULTI) == 0) {
- text.addKeyListener(this);
- }
+ text.addKeyListener(this);
setWidgetObservable(WidgetProperties.text(SWT.FocusOut).observe(text), true);
@@ -110,14 +108,25 @@ public class StringEditor extends AbstractValueEditor implements KeyListener {
* Validates this editor when one of the following events occur :
* - CR released
* - Keypad CR released
+ * - Ctrl + [CR | Keypad CR] released
*
* @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
*
* @param e
*/
public void keyReleased(KeyEvent e) {
- if((e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) && e.stateMask == SWT.NONE) {
- notifyChange();
+ //We listen on Carriage Return or Ctrl+ Carriage return, depending on
+ //whether the editor is single- or multi-line
+ if(e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
+ if((text.getStyle() & SWT.MULTI) == 0) { //Single-line : Enter
+ if(e.stateMask == SWT.NONE) {
+ notifyChange();
+ }
+ } else { //Multi-line : Ctrl+Enter
+ if(e.stateMask == SWT.CTRL) {
+ notifyChange();
+ }
+ }
}
}

Back to the top