[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[albireo-dev] Avoiding double selections
|
Committing FocusHandler code to handle this problem (Win32 only):
http://wiki.eclipse.org/Albireo_Focus_Management_Test_Cases#Single_text_selection
A straightforward fix, for once.
### Eclipse Workspace Patch 1.0
#P org.eclipse.albireo.core
Index: src/org/eclipse/albireo/internal/FocusHandler.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.albireo/org.eclipse.albireo.core/src/org/eclipse/albireo/internal/FocusHandler.java,v
retrieving revision 1.7
diff -u -r1.7 FocusHandler.java
--- src/org/eclipse/albireo/internal/FocusHandler.java 21 Feb 2008 19:58:31 -0000 1.7
+++ src/org/eclipse/albireo/internal/FocusHandler.java 21 Feb 2008 20:29:31 -0000
@@ -13,6 +13,9 @@
import java.lang.reflect.Method;
import java.util.Set;
+import javax.swing.text.Caret;
+import javax.swing.text.JTextComponent;
+
import org.eclipse.albireo.core.SwingControl;
import org.eclipse.albireo.core.ThreadingHandler;
import org.eclipse.swt.SWT;
@@ -79,6 +82,24 @@
swingControl.removeFocusListener(swtFocusListener);
}
+ // ================
+ // On a normal change of focus, Swing will turn off any selection
+ // in a text field to help indicate focus is lost. This won't happen
+ // automatically when transferring to SWT, so turn off the selection
+ // manually.
+ protected void hideTextSelection() {
+ assert EventQueue.isDispatchThread();
+
+ Component focusOwner = frame.getMostRecentFocusOwner();
+ if (focusOwner instanceof JTextComponent) {
+ Caret caret = ((JTextComponent)focusOwner).getCaret();
+ if (caret != null) {
+ caret.setSelectionVisible(false);
+ }
+ }
+ }
+
+
// =====
// Embedded frames in win32 do not support traverse out. For seamless embedding, we
// check for the need to traverse out here and generate the necessary SWT traversal(s).
@@ -360,6 +381,7 @@
public void windowLostFocus(WindowEvent e) {
if (Platform.isWin32()) {
+ hideTextSelection();
processTypeAheadKeys();
}
}