GP-4857 - Fix for Structure Editors not always taking focus

This commit is contained in:
dragonmacher 2024-08-19 16:21:24 -04:00
parent 90f712fc00
commit d1ee4119e7
4 changed files with 34 additions and 37 deletions

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -26,7 +26,8 @@ import org.jdom.Element;
import docking.actions.KeyBindingUtils;
import docking.widgets.OptionDialog;
import docking.widgets.tabbedpane.DockingTabRenderer;
import ghidra.util.*;
import ghidra.util.HelpLocation;
import ghidra.util.Msg;
import ghidra.util.exception.AssertException;
import help.HelpService;
import utilities.util.reflection.ReflectionUtilities;
@ -108,12 +109,9 @@ class ComponentNode extends Node {
return;
}
ComponentPlaceholder placeholder = getPlaceHolderForComponent(component);
if (placeholder == null) {
return;
if (placeholder != null) {
placeholder.requestFocusWhenReady();
}
Swing.runLater(() -> {
placeholder.requestFocus();
});
}
private boolean containsPlaceholder(ComponentPlaceholder placeholder) {

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,9 +15,10 @@
*/
package docking;
import java.awt.Frame;
import java.awt.Window;
import java.util.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.*;
@ -25,8 +26,8 @@ import org.apache.commons.lang3.StringUtils;
import docking.action.DockingAction;
import docking.action.DockingActionIf;
import generic.timer.ExpiringSwingTimer;
import ghidra.util.Msg;
import ghidra.util.Swing;
import ghidra.util.exception.AssertException;
import utilities.util.reflection.ReflectionUtilities;
@ -275,7 +276,7 @@ public class ComponentPlaceholder {
/**
* Requests focus for the component associated with this placeholder.
*/
void requestFocus() {
void requestFocusWhenReady() {
DockableComponent tmp = comp;// put in temp variable in case another thread deletes it
if (tmp == null) {
return;
@ -285,14 +286,22 @@ public class ComponentPlaceholder {
activateWindow();
// make sure the tab has time to become active before trying to request focus
tmp.requestFocus();
Swing.runLater(() -> {
tmp.requestFocus();
contextChanged();
ExpiringSwingTimer.runWhen(this::isShowing, 750, () -> {
doRequestFocus(tmp);
});
}
private void doRequestFocus(DockableComponent dockableComponent) {
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Window activeWindow = kfm.getActiveWindow();
if (activeWindow == null) {
return; // our application isn't focused--don't do anything
}
dockableComponent.requestFocus();
contextChanged();
}
// makes sure that the given window is not in an iconified state
private void activateWindow() {
DetachedWindowNode windowNode = getDetachedWindowNode();

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -1383,19 +1383,9 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
}
private void updateFocus(ComponentPlaceholder placeholder) {
if (placeholder == null) {
return;
if (placeholder != null) {
placeholder.requestFocusWhenReady();
}
Swing.runLater(() -> {
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Window activeWindow = kfm.getActiveWindow();
if (activeWindow == null) {
// our application isn't focused--don't do anything
return;
}
placeholder.requestFocus();
});
}
void restoreFocusOwner(String focusOwner, String focusName) {

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -234,7 +234,7 @@ class RootNode extends WindowNode {
}
detachedWindows.add(windowNode);
info.getNode().add(info);
info.requestFocus();
info.requestFocusWhenReady();
notifyWindowAdded(windowNode);
}