You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ge...@apache.org on 2022/10/10 05:17:42 UTC

[netbeans] branch master updated: Fix: Editor with Keyboard focus is not active TopComponent

This is an automated email from the ASF dual-hosted git repository.

geertjan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 486b048fff Fix: Editor with Keyboard focus is not active TopComponent
     new 2c27f5a31b Merge pull request #4603 from errael/KeyboardFocusCanActivateTopComponent
486b048fff is described below

commit 486b048fff2ae89e4f9bd8da8bcb80064c2bd382
Author: Ernie Rael <er...@raelity.com>
AuthorDate: Thu Sep 8 11:58:51 2022 -0700

    Fix: Editor with Keyboard focus is not active TopComponent
---
 .../core/windows/view/ui/TabbedHandler.java        | 39 ++++++++++++++++++----
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/platform/core.windows/src/org/netbeans/core/windows/view/ui/TabbedHandler.java b/platform/core.windows/src/org/netbeans/core/windows/view/ui/TabbedHandler.java
index bc1b284874..fbac948061 100644
--- a/platform/core.windows/src/org/netbeans/core/windows/view/ui/TabbedHandler.java
+++ b/platform/core.windows/src/org/netbeans/core/windows/view/ui/TabbedHandler.java
@@ -36,13 +36,17 @@ import org.openide.util.Utilities;
 import javax.swing.*;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
+
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.AWTEventListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
 import org.netbeans.core.windows.ModeImpl;
 import org.netbeans.core.windows.Switches;
 import org.netbeans.core.windows.view.ui.slides.SlideBar;
@@ -82,6 +86,8 @@ public final class TabbedHandler implements ChangeListener, ActionListener {
                 activationManager = new ActivationManager();
                 Toolkit.getDefaultToolkit().addAWTEventListener(
                     activationManager, AWTEvent.MOUSE_EVENT_MASK);
+                KeyboardFocusManager.getCurrentKeyboardFocusManager()
+                    .addPropertyChangeListener("focusOwner", activationManager);
             }
         }
         tabbed = tbd;
@@ -464,11 +470,33 @@ public final class TabbedHandler implements ChangeListener, ActionListener {
 
     /** Well, we can't totally get rid of AWT event listeners - this is what
      * keeps track of the activated mode. */
-    private static class ActivationManager implements AWTEventListener {
+    private static class ActivationManager implements AWTEventListener, PropertyChangeListener {
         @Override
         public void eventDispatched(AWTEvent e) {
             if(e.getID() == MouseEvent.MOUSE_PRESSED) {
-                handleActivation((MouseEvent) e);
+                handleActivation(e.getSource());
+            }
+        }
+
+        /**
+         * Keyboard focus change event handler. Handle situation where
+         * active TopComponent was in a different window and window
+         * changed without a mouse event.
+         * See
+         *     Editor with Keyboard focus is not active TopComponent
+         *     https://github.com/apache/netbeans/issues/4437
+         */
+        @Override
+        public void propertyChange(PropertyChangeEvent e) {
+            Frame mainWindowNB = WindowManagerImpl.getInstance().getMainWindow();
+            Window activeWindowKB = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
+            TopComponent currentTC = TopComponent.getRegistry().getActivated();
+            // Only do something if focus to the main window and
+            // active TC is not in the main window. Note that focus changes
+            // to detached windows handled in DefaultSeparateContainer.
+            if(mainWindowNB == activeWindowKB
+                    && mainWindowNB != SwingUtilities.getRoot(currentTC)) {
+                handleActivation(e.getNewValue());
             }
         }
 
@@ -490,12 +518,11 @@ public final class TabbedHandler implements ChangeListener, ActionListener {
          * components.  This behavior is compatible with all window managers I can
          * imagine.
          */
-        private void handleActivation(MouseEvent evt) {
-            Object obj = evt.getSource();
-            if (!(obj instanceof Component)) {
+        private void handleActivation(Object evtObject) {
+            if (!(evtObject instanceof Component)) {
                 return;
             }
-            Component comp = (Component) obj;
+            Component comp = (Component) evtObject;
             
             while (comp != null && !(comp instanceof ModeComponent)) {
                 if (comp instanceof JComponent) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists