mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
GP-5175 - Turned a local action into a global action (the action that
closes the window when only one provider remains)
This commit is contained in:
parent
293f5bdb0a
commit
64cdd130b3
3 changed files with 50 additions and 46 deletions
|
@ -75,15 +75,12 @@ class DockableToolBarManager {
|
|||
ToolBarCloseAction closeAction = new ToolBarCloseAction(owner);
|
||||
closeButtonManager = new ToolBarItemManager(closeAction, winMgr);
|
||||
|
||||
CloseLastProviderAction closeLastProviderAction = new CloseLastProviderAction(owner);
|
||||
|
||||
ToolBarMenuAction dropDownAction = new ToolBarMenuAction(owner);
|
||||
menuButtonManager = new ToolBarItemManager(dropDownAction, winMgr);
|
||||
|
||||
// we need to add this action to the tool in order to use key bindings
|
||||
Tool tool = winMgr.getTool();
|
||||
tool.addLocalAction(provider, closeAction);
|
||||
tool.addLocalAction(provider, closeLastProviderAction);
|
||||
tool.addLocalAction(provider, dropDownAction);
|
||||
}
|
||||
|
||||
|
@ -219,45 +216,6 @@ class DockableToolBarManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An action to close the provider on Escape if the provider is the last in the window. This
|
||||
* allows users to close transient providers (like search results) easily.
|
||||
*/
|
||||
private class CloseLastProviderAction extends DockingAction {
|
||||
|
||||
CloseLastProviderAction(String owner) {
|
||||
super("Close Window for Last Provider", owner, KeyBindingType.SHARED);
|
||||
setKeyBindingData(new KeyBindingData("ESCAPE"));
|
||||
setDescription("Close the window if this provider is the last provider in the window");
|
||||
markHelpUnnecessary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionContext context) {
|
||||
ComponentPlaceholder placeholder = dockableComponent.getComponentWindowingPlaceholder();
|
||||
if (placeholder != null) {
|
||||
placeholder.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledForContext(ActionContext context) {
|
||||
DockingWindowManager dwm = DockingWindowManager.getActiveInstance();
|
||||
if (dwm == null) {
|
||||
return false; // this can happen sometimes in test environments
|
||||
}
|
||||
ComponentProvider provider = context.getComponentProvider();
|
||||
if (provider == null) {
|
||||
// Some context providers do not specify the provider when creating a contexts
|
||||
provider = dwm.getActiveComponentProvider();
|
||||
}
|
||||
if (provider != dockableComponent.getComponentProvider()) {
|
||||
return false; // not my provider
|
||||
}
|
||||
return dwm.isLastProviderInDetachedWindow(provider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions added to toolbar for displaying the drop-down menu.
|
||||
*/
|
||||
|
|
|
@ -29,8 +29,8 @@ import javax.swing.*;
|
|||
import org.apache.commons.collections4.map.LazyMap;
|
||||
import org.jdom.Element;
|
||||
|
||||
import docking.action.ActionContextProvider;
|
||||
import docking.action.DockingActionIf;
|
||||
import docking.action.*;
|
||||
import docking.action.builder.ActionBuilder;
|
||||
import docking.actions.*;
|
||||
import docking.widgets.PasswordDialog;
|
||||
import generic.util.WindowUtilities;
|
||||
|
@ -2326,6 +2326,51 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
|
|||
dockableComponent.showContextMenu(popupContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the framework during startup to register actions that are shared throughout the
|
||||
* tool. See {@link SharedActionRegistry}.
|
||||
* @param tool the tool
|
||||
* @param toolActions the class to which the actions should be added
|
||||
* @param owner the shared action owner
|
||||
*/
|
||||
public static void createSharedActions(Tool tool, ToolActions toolActions, String owner) {
|
||||
|
||||
// An action to close the provider on Escape if the provider is the last in the window. This
|
||||
// allows users to close transient providers (like search results) easily.
|
||||
DockingAction closeAction = new ActionBuilder("Close Window for Last Provider", owner)
|
||||
.sharedKeyBinding()
|
||||
.keyBinding("ESCAPE")
|
||||
.enabledWhen(c -> {
|
||||
ComponentProvider provider = getComponentProviderForContext(c);
|
||||
if (provider == null) {
|
||||
return false;
|
||||
}
|
||||
Tool t = provider.getTool();
|
||||
DockingWindowManager dwm = t.getWindowManager();
|
||||
return dwm.isLastProviderInDetachedWindow(provider);
|
||||
})
|
||||
.onAction(c -> {
|
||||
ComponentProvider provider = getComponentProviderForContext(c);
|
||||
provider.closeComponent();
|
||||
})
|
||||
.build();
|
||||
toolActions.addGlobalAction(closeAction);
|
||||
}
|
||||
|
||||
private static ComponentProvider getComponentProviderForContext(ActionContext context) {
|
||||
ComponentProvider provider = context.getComponentProvider();
|
||||
if (provider != null) {
|
||||
return provider;
|
||||
}
|
||||
|
||||
// Some context providers do not specify the provider when creating a contexts
|
||||
DockingWindowManager dwm = DockingWindowManager.getActiveInstance();
|
||||
if (dwm == null) {
|
||||
return null; // this can happen sometimes in test environments
|
||||
}
|
||||
return dwm.getActiveComponentProvider();
|
||||
}
|
||||
|
||||
public void contextChanged(ComponentProvider provider) {
|
||||
// if provider is specified, update its local menu and tool bar actions
|
||||
if (provider != null) {
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
*/
|
||||
package docking.actions;
|
||||
|
||||
import docking.DialogComponentProvider;
|
||||
import docking.Tool;
|
||||
import docking.*;
|
||||
import docking.action.DockingActionIf;
|
||||
import docking.tool.ToolConstants;
|
||||
import docking.widgets.table.GTable;
|
||||
|
@ -41,5 +40,7 @@ public class SharedActionRegistry {
|
|||
GTree.createSharedActions(tool, toolActions, ToolConstants.SHARED_OWNER);
|
||||
|
||||
DialogComponentProvider.createSharedActions(tool, toolActions, ToolConstants.SHARED_OWNER);
|
||||
|
||||
DockingWindowManager.createSharedActions(tool, toolActions, ToolConstants.SHARED_OWNER);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue