GP-2943 changed Structure/Union editor to show hex values by default.

This commit is contained in:
ghidragon
2023-03-03 12:43:46 -05:00
parent 2e2bc48c4f
commit 2e317cd87f
3 changed files with 25 additions and 23 deletions

View File

@@ -1198,25 +1198,25 @@
</OL> </OL>
</BLOCKQUOTE> </BLOCKQUOTE>
<H2><A name="Structure_Editor_Show_Numbers_In_Hex"></A> Showing Numbers in Hexadecimal</H2> <H2><A name="Structure_Editor_Show_Numbers_In_Hex"></A> Toggling Hex/Decimal Display</H2>
<BLOCKQUOTE> <BLOCKQUOTE>
<P>The Component Table contains numeric fields such as the component's offset and length. The <P>The Component Table contains numeric fields such as the component's offset and length. The
structure information area also shows the overall size and alignment of the structure. By structure information area also shows the overall size and alignment of the structure. By
default numbers are initially shown in decimal in the Structure Editor. There is a <A href= default, numbers are initially shown as hex values in the Structure Editor. There is
"#StructureEditorToolOptions">tool option</A>, <B>Show Numbers In Hex</B>, that lets you a <A href="#StructureEditorToolOptions">tool option</A>, <B>Show Numbers In Hex</B>, that lets
override the default and set whether these numbers should be displayed in hexadecimal when an you override the default and set whether these numbers should be displayed as decimal or hex
editor is initially displayed.</P> values when an editor is initially displayed.</P>
<P>There is also a toolbar menu item in the editor that allows you to immediately change <P>The hex/decimal mode can quickly be toggled using the key binding <B>Shift H</B>
whether the numbers are displayed in hexadecimal or decimal. Changing this only affects the or the toolbar menu item in the editor. Changing this only affects the
current editor where it is changed.</P> current editor where it is changed.</P>
<P><IMG src="help/shared/note.png" alt=""> The Union Editor does not display offsets since <P><IMG src="help/shared/note.png" alt=""> The Union Editor does not display offsets since
they are always zero.</P> they are always zero.</P>
<P>To switch between decimal and hexadecimal display of numeric values in the current <P>To switch between decimal and hex display of numeric values in the current
editor:</P> editor, press <B>Shift H</B> or use the menu action as follows:</P>
<OL> <OL>
<LI>Right mouse click on the table.</LI> <LI>Right mouse click on the table.</LI>

View File

@@ -19,6 +19,7 @@ import javax.swing.JMenuItem;
import docking.ActionContext; import docking.ActionContext;
import docking.DockingCheckBoxMenuItem; import docking.DockingCheckBoxMenuItem;
import docking.action.KeyBindingData;
import docking.action.ToggleDockingActionIf; import docking.action.ToggleDockingActionIf;
import docking.menu.DockingCheckboxMenuItemUI; import docking.menu.DockingCheckboxMenuItemUI;
@@ -39,6 +40,7 @@ public class HexNumbersAction extends CompositeEditorTableAction implements Togg
setDescription(DESCRIPTION); setDescription(DESCRIPTION);
setEnabled(true); setEnabled(true);
setSelected(model.isShowingNumbersInHex()); setSelected(model.isShowingNumbersInHex());
setKeyBindingData(new KeyBindingData("Shift-H"));
} }
@Override @Override

View File

@@ -21,19 +21,19 @@ import ghidra.framework.options.*;
import ghidra.framework.plugintool.Plugin; import ghidra.framework.plugintool.Plugin;
import ghidra.util.HelpLocation; import ghidra.util.HelpLocation;
public class EditorOptionManager implements OptionsChangeListener, StructureEditorOptionManager, public class EditorOptionManager
UnionEditorOptionManager { implements OptionsChangeListener, StructureEditorOptionManager, UnionEditorOptionManager {
private final static String STRUCTURE_EDITOR_NAME = "Structure Editor"; private final static String STRUCTURE_EDITOR_NAME = "Structure Editor";
private final static String UNION_EDITOR_NAME = "Union Editor"; private final static String UNION_EDITOR_NAME = "Union Editor";
private final static String HEX_STRUCT_NUMBERS_OPTION_NAME = STRUCTURE_EDITOR_NAME + private final static String HEX_STRUCT_NUMBERS_OPTION_NAME =
Options.DELIMITER + "Show Numbers In Hex"; STRUCTURE_EDITOR_NAME + Options.DELIMITER + "Show Numbers In Hex";
private final static String HEX_UNION_NUMBERS_OPTION_NAME = UNION_EDITOR_NAME + private final static String HEX_UNION_NUMBERS_OPTION_NAME =
Options.DELIMITER + "Show Numbers In Hex"; UNION_EDITOR_NAME + Options.DELIMITER + "Show Numbers In Hex";
private Plugin plugin; private Plugin plugin;
private boolean showStructureNumbersInHex = false; private boolean showStructureNumbersInHex = true;
private boolean showUnionNumbersInHex = false; private boolean showUnionNumbersInHex = true;
private String HELP_TOPIC = "DataTypeEditors"; private String HELP_TOPIC = "DataTypeEditors";
public EditorOptionManager(Plugin plugin) { public EditorOptionManager(Plugin plugin) {
@@ -50,14 +50,14 @@ public class EditorOptionManager implements OptionsChangeListener, StructureEdit
options.getOptions(UNION_EDITOR_NAME).setOptionsHelpLocation(help); options.getOptions(UNION_EDITOR_NAME).setOptionsHelpLocation(help);
options.registerOption(HEX_STRUCT_NUMBERS_OPTION_NAME, showStructureNumbersInHex, help, options.registerOption(HEX_STRUCT_NUMBERS_OPTION_NAME, showStructureNumbersInHex, help,
"Toggle for whether numeric values in the Structure Editor " "Toggle for whether numeric values in the Structure Editor " +
+ "should be displayed in hexadecimal or decimal " "should be displayed in hexadecimal or decimal " +
+ "when you initially begin editing a structure."); "when you initially begin editing a structure.");
options.registerOption(HEX_UNION_NUMBERS_OPTION_NAME, showUnionNumbersInHex, help, options.registerOption(HEX_UNION_NUMBERS_OPTION_NAME, showUnionNumbersInHex, help,
"Toggle for whether numeric values in the Union Editor " "Toggle for whether numeric values in the Union Editor " +
+ "should be displayed in hexadecimal or decimal " "should be displayed in hexadecimal or decimal " +
+ "when you initially begin editing a union."); "when you initially begin editing a union.");
setOptions(options); setOptions(options);
options.addOptionsChangeListener(this); options.addOptionsChangeListener(this);