changeset 1231:aa28336a1e58

Fixed RT-22054: TextInputControl default editing actions badly handled when TextInputControl is not editable
author leifs
date Tue, 05 Jun 2012 10:42:59 -0700
parents aa001f13bd63
children 46dadf1d60fc
files javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextInputControlSkin.java
diffstat 2 files changed, 39 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java	Mon Jun 04 17:40:59 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java	Tue Jun 05 10:42:59 2012 -0700
@@ -119,17 +119,31 @@
 
     @Override public void callAction(String name) {
         TextInputControl textInputControl = getControl();
+        boolean done = false;
+
+        setCaretAnimating(false);
+
         if (textInputControl.isEditable()) {
-            setCaretAnimating(false);
             setEditing(true);
-            final IndexRange selection = textInputControl.getSelection();
-            final int start = selection.getStart();
-            final int end = selection.getEnd();
-
+            done = true;
             if ("InputCharacter".equals(name)) defaultKeyTyped(lastEvent);
             else if ("Cut".equals(name)) cut();
-            else if ("Copy".equals(name)) textInputControl.copy();
             else if ("Paste".equals(name)) paste();
+            else if ("DeletePreviousChar".equals(name)) deletePreviousChar();
+            else if ("DeleteNextChar".equals(name)) deleteNextChar();
+            else if ("DeletePreviousWord".equals(name)) deletePreviousWord();
+            else if ("DeleteNextWord".equals(name)) deleteNextWord();
+            else if ("DeleteSelection".equals(name)) deleteSelection();
+            else if ("Undo".equals(name)) undoManager.undo();
+            else if ("Redo".equals(name)) undoManager.redo();
+            else {
+                done = false;
+            }
+            setEditing(false);
+        }
+        if (!done) {
+            done = true;
+            if ("Copy".equals(name)) textInputControl.copy();
             else if ("SelectBackward".equals(name)) textInputControl.selectBackward();
             else if ("SelectForward".equals(name)) textInputControl.selectForward();
             else if ("PreviousWord".equals(name)) previousWord();
@@ -140,11 +154,6 @@
             else if ("SelectAll".equals(name)) textInputControl.selectAll();
             else if ("Home".equals(name)) textInputControl.home();
             else if ("End".equals(name)) textInputControl.end();
-            else if ("DeletePreviousChar".equals(name)) deletePreviousChar();
-            else if ("DeleteNextChar".equals(name)) deleteNextChar();
-            else if ("DeletePreviousWord".equals(name)) deletePreviousWord();
-            else if ("DeleteNextWord".equals(name)) deleteNextWord();
-            else if ("DeleteSelection".equals(name)) deleteSelection();
             else if ("Forward".equals(name)) textInputControl.forward();
             else if ("Backward".equals(name)) textInputControl.backward();
             else if ("Fire".equals(name)) fire(lastEvent);
@@ -153,25 +162,16 @@
             else if ("SelectEnd".equals(name)) selectEnd();
             else if ("SelectHomeExtend".equals(name)) selectHomeExtend();
             else if ("SelectEndExtend".equals(name)) selectEndExtend();
-            else if ("Undo".equals(name)) undoManager.undo();
-            else if ("Redo".equals(name)) undoManager.redo();
             else if ("ToParent".equals(name)) forwardToParent(lastEvent);
             /*DEBUG*/else if ("UseVK".equals(name) && isEmbedded()) {
                 ((com.sun.javafx.scene.control.skin.TextInputControlSkin)textInputControl.getSkin()).toggleUseVK();
             } else {
-                setEditing(false);
-                super.callAction(name);
+                done = false;
             }
-            setEditing(false);
-            setCaretAnimating(true);
-        } else if ("Copy".equals(name)) {
-            // If the key event is for the "copy" action then we go ahead
-            // and execute it, but for all other key events which occur
-            // when not editable, we don't allow.
-            textInputControl.copy();
-        } else if (name.startsWith("Traverse")) {
-            // Call super.callAction() for any focus traversal actions even if
-            // it's not editable
+        }
+        setCaretAnimating(true);
+
+        if (!done) {
             super.callAction(name);
         }
         // Note, I don't have to worry about "Consume" here.
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextInputControlSkin.java	Mon Jun 04 17:40:59 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TextInputControlSkin.java	Tue Jun 05 10:42:59 2012 -0700
@@ -604,20 +604,25 @@
     final MenuItem deleteMI = new ContextMenuItem("DeleteSelection");
     final MenuItem selectWordMI = new ContextMenuItem("SelectWord");
     final MenuItem selectAllMI = new ContextMenuItem("SelectAll");
+    final MenuItem separatorMI = new SeparatorMenuItem();
 
     public void populateContextMenu(ContextMenu contextMenu) {
-        boolean hasText = (getSkinnable().getLength() > 0);
-        boolean hasSelection = (getSkinnable().getSelection().getLength() > 0);
+        TextInputControl textInputControl = getSkinnable();
+        boolean editable = textInputControl.isEditable();
+        boolean hasText = (textInputControl.getLength() > 0);
+        boolean hasSelection = (textInputControl.getSelection().getLength() > 0);
         boolean maskText = (maskText("A") != "A");
         ObservableList<MenuItem> items = contextMenu.getItems();
 
         if (PlatformUtil.isEmbedded()) {
             items.clear();
             if (!maskText && hasSelection) {
-                items.add(cutMI);
+                if (editable) {
+                    items.add(cutMI);
+                }
                 items.add(copyMI);
             }
-            if (Clipboard.getSystemClipboard().hasString()) {
+            if (editable && Clipboard.getSystemClipboard().hasString()) {
                 items.add(pasteMI);
             }
             if (hasText) {
@@ -629,9 +634,11 @@
             selectWordMI.getProperties().put("refreshMenu", Boolean.TRUE);
             selectAllMI.getProperties().put("refreshMenu", Boolean.TRUE);
         } else {
-            if (items.size() == 0) {
-                items.addAll(undoMI, redoMI, cutMI, copyMI, pasteMI, deleteMI,
-                             new SeparatorMenuItem(), selectAllMI);
+            if (editable) {
+                items.setAll(undoMI, redoMI, cutMI, copyMI, pasteMI, deleteMI,
+                             separatorMI, selectAllMI);
+            } else {
+                items.setAll(copyMI, separatorMI, selectAllMI);
             }
             undoMI.setDisable(!getBehavior().canUndo());
             redoMI.setDisable(!getBehavior().canRedo());