Skip to content

Commit

Permalink
Impl #73 - [TextCellEditor] Add option to replace the KeyListener
Browse files Browse the repository at this point in the history
  • Loading branch information
fipro78 committed Apr 29, 2024
1 parent 3cc71ab commit ccc22ed
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2022 Original authors and others.
* Copyright (c) 2012, 2024 Original authors and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -32,6 +32,7 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
Expand Down Expand Up @@ -355,7 +356,21 @@ protected Text createEditorControl(final Composite parent, int style) {

// add a key listener that will commit or close the editor for special
// key strokes and executes conversion/validation on input to the editor
textControl.addKeyListener(new KeyAdapter() {
textControl.addKeyListener(getTextKeyListener());

return textControl;
}

/**
*
* @return The {@link KeyListener} that is added to the {@link Text} control
* to commit or close the editor for special key strokes and
* executes conversion/validation on input to the editor.
*
* @since 2.4
*/
protected KeyListener getTextKeyListener() {
return new KeyAdapter() {

@Override
public void keyPressed(KeyEvent event) {
Expand Down Expand Up @@ -384,7 +399,7 @@ public void keyPressed(KeyEvent event) {
}

if (TextCellEditor.this.editMode == EditModeEnum.DIALOG) {
parent.forceFocus();
TextCellEditor.this.parent.forceFocus();
}
} else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
close();
Expand Down Expand Up @@ -431,9 +446,7 @@ public void keyReleased(KeyEvent e) {
// an exception
}
}
});

return textControl;
};
}

@Override
Expand Down

0 comments on commit ccc22ed

Please sign in to comment.