From 7712224ff1e60cd4446f2dd227ac9b35d07ed998 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Fri, 15 Nov 2024 20:52:34 -0500 Subject: [PATCH] Fixed focus issue that caused new dialogs to sometimes have focus taken away --- .../src/main/java/docking/DockingWindowManager.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Ghidra/Framework/Docking/src/main/java/docking/DockingWindowManager.java b/Ghidra/Framework/Docking/src/main/java/docking/DockingWindowManager.java index da9522a005..d144ddfd91 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/DockingWindowManager.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/DockingWindowManager.java @@ -1385,6 +1385,7 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder } private synchronized ComponentPlaceholder maybeGetPlaceholderToFocus() { + if (nextFocusedPlaceholder != null) { ComponentPlaceholder temp = nextFocusedPlaceholder; setNextFocusPlaceholder(null); @@ -1392,8 +1393,12 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder } KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + Component permanentFocusOwner = kfm.getPermanentFocusOwner(); Component focusOwner = kfm.getFocusOwner(); - if (focusOwner == null) { + + // A null focus owner and a null permanent focus owner imply that Java did not know who + // should get focus. Make sure one of our widgets gets focus. + if (focusOwner == null && permanentFocusOwner == null) { return findNextFocusedComponent(); } return null; @@ -1463,6 +1468,7 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder } private ComponentPlaceholder findNextFocusedComponent() { + Iterator iterator = lastFocusedPlaceholders.iterator(); while (iterator.hasNext()) { ComponentPlaceholder placeholder = iterator.next(); @@ -1471,7 +1477,6 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder } iterator.remove(); } - return getActivePlaceholder(defaultProvider); }