diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/assembler/AssembleDockingAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/assembler/AssembleDockingAction.java index 62bf00ac59..21287276c3 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/assembler/AssembleDockingAction.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/assembler/AssembleDockingAction.java @@ -37,7 +37,6 @@ import ghidra.app.plugin.assembler.Assembler; import ghidra.app.plugin.assembler.Assemblers; import ghidra.app.plugin.core.assembler.AssemblyDualTextField.*; import ghidra.app.plugin.core.codebrowser.CodeViewerProvider; -import ghidra.app.util.PluginConstants; import ghidra.app.util.viewer.field.ListingField; import ghidra.app.util.viewer.listingpanel.ListingModelAdapter; import ghidra.app.util.viewer.listingpanel.ListingPanel; @@ -78,7 +77,7 @@ public class AssembleDockingAction extends DockingAction { private Language lang; private Assembler assembler; private final MyListener listener = new MyListener(); - private PluginTool tool; + //private PluginTool tool; // Callback to keep the autocompleter positioned under the fields private FieldPanelOverLayoutListener autoCompleteMover = (FieldPanelOverLayoutEvent ev) -> { @@ -159,23 +158,7 @@ public class AssembleDockingAction extends DockingAction { */ public AssembleDockingAction(PluginTool tool, String name, String owner) { this(name, owner); - this.tool = tool; - } - - @Override - public void dispose() { - super.dispose(); - input.dispose(); - } - - protected void onFirstInvocation() { - ComponentProvider prov = tool.getComponentProvider(PluginConstants.CODE_BROWSER); - cv = (CodeViewerProvider) prov; - listpane = cv.getListingPanel(); - codepane = listpane.getFieldPanel(); - - fieldLayoutManager = new FieldPanelOverLayoutManager(codepane); - codepane.setLayout(fieldLayoutManager); + //this.tool = tool; // If I lose focus, cancel the assembly input.addFocusListener(new FocusListener() { @@ -189,14 +172,37 @@ public class AssembleDockingAction extends DockingAction { cancel(); } }); + input.getMnemonicField().setBorder(BorderFactory.createLineBorder(Color.RED, 2)); input.getOperandsField().setBorder(BorderFactory.createLineBorder(Color.RED, 2)); input.getAssemblyField().setBorder(BorderFactory.createLineBorder(Color.RED, 2)); input.getAutocompleter().addAutocompletionListener(listener); input.addKeyListener(listener); + } - fieldLayoutManager.addLayoutListener(autoCompleteMover); + @Override + public void dispose() { + super.dispose(); + input.dispose(); + } + + protected void prepareLayout(ActionContext context) { + ComponentProvider prov = context.getComponentProvider(); + if (cv != prov) { + if (cv != null) { + codepane.setLayout(null); + fieldLayoutManager.removeLayoutListener(autoCompleteMover); + } + + cv = (CodeViewerProvider) prov; + listpane = cv.getListingPanel(); + codepane = listpane.getFieldPanel(); + + fieldLayoutManager = new FieldPanelOverLayoutManager(codepane); + codepane.setLayout(fieldLayoutManager); + fieldLayoutManager.addLayoutListener(autoCompleteMover); + } } /** @@ -265,11 +271,13 @@ public class AssembleDockingAction extends DockingAction { @Override public void actionPerformed(ActionContext context) { - if (cv == null) { - onFirstInvocation(); + if (!(context instanceof ListingActionContext)) { + return; } + prepareLayout(context); + ListingActionContext lac = (ListingActionContext) context; - ProgramLocation cur = cv.getLocation(); + ProgramLocation cur = lac.getLocation(); prog = cur.getProgram(); addr = cur.getAddress(); @@ -356,6 +364,7 @@ public class AssembleDockingAction extends DockingAction { @Override public boolean isAddToPopup(ActionContext context) { + // currently only works on a listing if (!(context instanceof ListingActionContext)) { return false;