Fixed help bug that prevented the correct help from being shown for

dialog launched from a dialog's toolbar
This commit is contained in:
dragonmacher 2023-09-28 17:56:41 -04:00
parent 1801dc1ee6
commit 105ae2d322

View File

@ -21,9 +21,10 @@ import java.beans.PropertyChangeEvent;
import docking.DockingWindowManager; import docking.DockingWindowManager;
import docking.EmptyBorderToggleButton; import docking.EmptyBorderToggleButton;
import docking.action.*; import docking.action.*;
import ghidra.util.Swing;
/** /**
* Toolbar buttons for Dialogs. * Toolbar buttons for Dialogs.
* *
* <p>This class exists because dialog actions are not added to the regular tool's toolbars. This * <p>This class exists because dialog actions are not added to the regular tool's toolbars. This
* means that we have to create the dialog's toolbars outside of the tool. Thus, this class * means that we have to create the dialog's toolbars outside of the tool. Thus, this class
@ -40,7 +41,7 @@ public class DialogToolbarButton extends EmptyBorderToggleButton {
addMouseListener(new MouseOverMouseListener()); addMouseListener(new MouseOverMouseListener());
action.addPropertyChangeListener(propertyChangeListener); action.addPropertyChangeListener(propertyChangeListener);
// make sure this button gets our specialized tooltip // make sure this button gets our specialized tooltip
DockingToolBarUtils.setToolTipText(this, dockingAction); DockingToolBarUtils.setToolTipText(this, dockingAction);
} }
@ -52,11 +53,18 @@ public class DialogToolbarButton extends EmptyBorderToggleButton {
@Override @Override
protected void doActionPerformed(ActionEvent e) { protected void doActionPerformed(ActionEvent e) {
// The help is pointing to the toolbar button that triggered this call. Reset the help so
// that it is correct for any widgets triggered by the actionPeformed call below.
DockingWindowManager.clearMouseOverHelp();
if (dockingAction instanceof ToggleDockingActionIf) { if (dockingAction instanceof ToggleDockingActionIf) {
ToggleDockingActionIf toggleAction = (ToggleDockingActionIf) dockingAction; ToggleDockingActionIf toggleAction = (ToggleDockingActionIf) dockingAction;
toggleAction.setSelected(!toggleAction.isSelected()); toggleAction.setSelected(!toggleAction.isSelected());
} }
dockingAction.actionPerformed(contextProvider.getActionContext(null));
// Give the Swing thread a chance to repaint
Swing.runLater(() -> dockingAction.actionPerformed(contextProvider.getActionContext(null)));
} }
@Override @Override
@ -84,7 +92,7 @@ public class DialogToolbarButton extends EmptyBorderToggleButton {
@Override @Override
// overridden to account for the fact that "special" DockableActions can be either // overridden to account for the fact that "special" DockableActions can be either
// toggle buttons or regular non-toggle buttons, which dictates whether this // toggle buttons or regular non-toggle buttons, which dictates whether this
// button is selected (non-toggle buttons are not selectable). // button is selected (non-toggle buttons are not selectable).
protected boolean isButtonSelected() { protected boolean isButtonSelected() {
if (dockingAction instanceof ToggleDockingAction) { if (dockingAction instanceof ToggleDockingAction) {
@ -101,7 +109,7 @@ public class DialogToolbarButton extends EmptyBorderToggleButton {
// overridden to reflect the potentiality that our action is a toggle action // overridden to reflect the potentiality that our action is a toggle action
public void setSelected(boolean b) { public void setSelected(boolean b) {
if (dockingAction instanceof ToggleDockingActionIf) { if (dockingAction instanceof ToggleDockingActionIf) {
// only change the state if the action is a toggle action; doing otherwise would // only change the state if the action is a toggle action; doing otherwise would
// break the DockableAction // break the DockableAction
((ToggleDockingActionIf) dockingAction).setSelected(b); ((ToggleDockingActionIf) dockingAction).setSelected(b);
} }