mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
Merge remote-tracking branch 'origin/GP-5930_ghidragon_pcode_field_toggle_action--SQUASHED'
This commit is contained in:
commit
799200c528
4 changed files with 66 additions and 20 deletions
|
@ -191,6 +191,13 @@
|
||||||
<P>Reset the formats for all categories to their default settings by right clicking on the
|
<P>Reset the formats for all categories to their default settings by right clicking on the
|
||||||
Browser Field Formatter and select <B>Reset All Formats</B> on the popup.</P>
|
Browser Field Formatter and select <B>Reset All Formats</B> on the popup.</P>
|
||||||
</BLOCKQUOTE>
|
</BLOCKQUOTE>
|
||||||
|
|
||||||
|
<H3><A name="Toggle_Field"></A>Quick Toggle Actions</H3>
|
||||||
|
<BLOCKQUOTE>
|
||||||
|
<P>Some fields have quick toggle actions that allow the field to be easily toggled on or
|
||||||
|
off. Currently, the only field with a quick toggle action is the PCode field and it has a
|
||||||
|
default keybinding is <CTRL SHIFT 1>.<P>
|
||||||
|
</BLOCKQUOTE>
|
||||||
</BLOCKQUOTE>
|
</BLOCKQUOTE>
|
||||||
|
|
||||||
<H2>Custom Formats</H2>
|
<H2>Custom Formats</H2>
|
||||||
|
|
|
@ -437,10 +437,7 @@ public abstract class AbstractCodeBrowserPlugin<P extends CodeViewerProvider> ex
|
||||||
else if (optionName.equals(MOUSE_WHEEL_HORIZONTAL_SCROLLING_OPTIONS_NAME)) {
|
else if (optionName.equals(MOUSE_WHEEL_HORIZONTAL_SCROLLING_OPTIONS_NAME)) {
|
||||||
fieldPanel.setHorizontalScrollingEnabled((Boolean) newValue);
|
fieldPanel.setHorizontalScrollingEnabled((Boolean) newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedProvider.fieldOptionChanged(optionName, newValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,8 +20,7 @@ import java.awt.Point;
|
||||||
import java.awt.datatransfer.DataFlavor;
|
import java.awt.datatransfer.DataFlavor;
|
||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.awt.dnd.*;
|
import java.awt.dnd.*;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.*;
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
@ -31,6 +30,7 @@ import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
import docking.*;
|
import docking.*;
|
||||||
import docking.action.*;
|
import docking.action.*;
|
||||||
|
import docking.action.builder.ActionBuilder;
|
||||||
import docking.actions.PopupActionProvider;
|
import docking.actions.PopupActionProvider;
|
||||||
import docking.dnd.*;
|
import docking.dnd.*;
|
||||||
import docking.widgets.EventTrigger;
|
import docking.widgets.EventTrigger;
|
||||||
|
@ -62,8 +62,7 @@ import ghidra.program.model.address.*;
|
||||||
import ghidra.program.model.listing.*;
|
import ghidra.program.model.listing.*;
|
||||||
import ghidra.program.model.mem.Memory;
|
import ghidra.program.model.mem.Memory;
|
||||||
import ghidra.program.util.*;
|
import ghidra.program.util.*;
|
||||||
import ghidra.util.HelpLocation;
|
import ghidra.util.*;
|
||||||
import ghidra.util.Swing;
|
|
||||||
|
|
||||||
public class CodeViewerProvider extends NavigatableComponentProviderAdapter
|
public class CodeViewerProvider extends NavigatableComponentProviderAdapter
|
||||||
implements ProgramLocationListener, ProgramSelectionListener, Draggable, Droppable,
|
implements ProgramLocationListener, ProgramSelectionListener, Draggable, Droppable,
|
||||||
|
@ -471,21 +470,37 @@ public class CodeViewerProvider extends NavigatableComponentProviderAdapter
|
||||||
action = new GotoNextFunctionAction(tool, plugin.getName());
|
action = new GotoNextFunctionAction(tool, plugin.getName());
|
||||||
tool.addAction(action);
|
tool.addAction(action);
|
||||||
|
|
||||||
|
buildQuickTogleFieldActions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fieldOptionChanged(String fieldName, Object newValue) {
|
private void buildQuickTogleFieldActions() {
|
||||||
//TODO if (name.startsWith(OPERAND_OPTIONS_PREFIX) && (newValue instanceof Boolean)) {
|
List<String> quickToggleFieldNames = formatMgr.getQuickToggleFieldNames();
|
||||||
// for (int i = 0; i < toggleOperandMarkupActions.length; i++) {
|
int count = 0;
|
||||||
// ToggleOperandMarkupAction action = toggleOperandMarkupActions[i];
|
for (String fieldName : quickToggleFieldNames) {
|
||||||
// if (name.equals(action.getOptionName())) {
|
DockingAction toggleAction = new ActionBuilder("Toggle " + fieldName, plugin.getName())
|
||||||
// boolean newState = ((Boolean)newValue).booleanValue();
|
.popupMenuPath("Toggle Field", fieldName)
|
||||||
// if (action.isSelected() != newState) {
|
.popupMenuGroup("Field", "" + count)
|
||||||
// action.setSelected(newState);
|
.helpLocation(new HelpLocation("CodeBrowserPlugin", "Toggle_Field"))
|
||||||
// }
|
// only show this action when over the listing field header
|
||||||
// break;
|
.popupWhen(c -> c.getContextObject() instanceof FieldHeaderLocation)
|
||||||
// }
|
.onAction(c -> formatMgr.toggleField(fieldName))
|
||||||
// }
|
.buildAndInstallLocal(this);
|
||||||
// }
|
|
||||||
|
// automatically assign keybindings to the first 5 toggle fields.
|
||||||
|
if (count < 5) {
|
||||||
|
char c = (char) ('1' + count);
|
||||||
|
toggleAction.setKeyBindingData(
|
||||||
|
new KeyBindingData(c, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Msg.debug(this,
|
||||||
|
"Excessive Field Toggle actions . No keybinding assigned for field: " +
|
||||||
|
fieldName);
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
tool.setMenuGroup(new String[] { "Toggle Field" }, "Disassembly");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListingPanel getListingPanel() {
|
public ListingPanel getListingPanel() {
|
||||||
|
|
|
@ -32,6 +32,7 @@ import ghidra.program.model.data.Array;
|
||||||
import ghidra.program.model.data.DataType;
|
import ghidra.program.model.data.DataType;
|
||||||
import ghidra.program.model.listing.*;
|
import ghidra.program.model.listing.*;
|
||||||
import ghidra.program.model.scalar.Scalar;
|
import ghidra.program.model.scalar.Scalar;
|
||||||
|
import ghidra.util.Msg;
|
||||||
import ghidra.util.classfinder.*;
|
import ghidra.util.classfinder.*;
|
||||||
import ghidra.util.datastruct.WeakDataStructureFactory;
|
import ghidra.util.datastruct.WeakDataStructureFactory;
|
||||||
import ghidra.util.datastruct.WeakSet;
|
import ghidra.util.datastruct.WeakSet;
|
||||||
|
@ -252,6 +253,25 @@ public class FormatManager implements OptionsChangeListener {
|
||||||
return models[FieldFormatModel.OPEN_DATA];
|
return models[FieldFormatModel.OPEN_DATA];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle the enablement for the field with the given name.
|
||||||
|
* @param name the of the field to toggle
|
||||||
|
*/
|
||||||
|
public void toggleField(String name) {
|
||||||
|
for (FieldFormatModel model : models) {
|
||||||
|
for (int i = 0; i < model.getNumRows(); i++) {
|
||||||
|
FieldFactory[] rowFactories = model.getFactorys(i);
|
||||||
|
for (FieldFactory fieldFactory : rowFactories) {
|
||||||
|
if (fieldFactory.getFieldName().equals(name)) {
|
||||||
|
fieldFactory.setEnabled(!fieldFactory.isEnabled());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Msg.showError(this, null, "Toggle Field Failed!", "No field named \"" + name + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isPrimitiveArrayElement(Data data) {
|
private boolean isPrimitiveArrayElement(Data data) {
|
||||||
Data parent = data.getParent();
|
Data parent = data.getParent();
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
|
@ -331,6 +351,13 @@ public class FormatManager implements OptionsChangeListener {
|
||||||
return maxRowCount;
|
return maxRowCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@return a list of field names that should have quick toggle actions.}
|
||||||
|
*/
|
||||||
|
public List<String> getQuickToggleFieldNames() {
|
||||||
|
return List.of("PCode");
|
||||||
|
}
|
||||||
|
|
||||||
private Element getDefaultModel(int modelID) {
|
private Element getDefaultModel(int modelID) {
|
||||||
switch (modelID) {
|
switch (modelID) {
|
||||||
case FieldFormatModel.DIVIDER:
|
case FieldFormatModel.DIVIDER:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue