mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GT-3410 added field comment to bitfield editor
This commit is contained in:
parent
c4f31ba4bd
commit
e0986c4fe9
4 changed files with 28 additions and 11 deletions
Binary file not shown.
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 25 KiB |
|
@ -60,6 +60,7 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
|
||||
private DataTypeSelectionEditor dtChoiceEditor;
|
||||
private JTextField fieldNameTextField;
|
||||
private JTextField fieldCommentTextField;
|
||||
private SpinnerNumberModel allocSizeModel;
|
||||
private JSpinnerWithMouseWheel allocSizeInput;
|
||||
private SpinnerNumberModel bitOffsetModel;
|
||||
|
@ -156,6 +157,9 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
fieldNameTextField = new JTextField(20);
|
||||
fieldNameTextField.setFocusable(true);
|
||||
|
||||
fieldCommentTextField = new JTextField(20);
|
||||
fieldCommentTextField.setFocusable(true);
|
||||
|
||||
allocSizeModel = new SpinnerNumberModel(Long.valueOf(4), Long.valueOf(1), Long.valueOf(16),
|
||||
Long.valueOf(1));
|
||||
allocSizeInput = new JSpinnerWithMouseWheel(allocSizeModel);
|
||||
|
@ -189,8 +193,8 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
entryPanel.add(new JLabel("Bit Size:"));
|
||||
entryPanel.add(bitSizeInput);
|
||||
|
||||
entryPanel.add(new JPanel());
|
||||
entryPanel.add(new JPanel());
|
||||
entryPanel.add(new JLabel("Comment:"));
|
||||
entryPanel.add(fieldCommentTextField);
|
||||
|
||||
entryPanel.add(new JLabel("Bit Offset:"));
|
||||
entryPanel.add(bitOffsetInput);
|
||||
|
@ -389,7 +393,7 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
: initialBaseDataType.getLength();
|
||||
placementComponent.updateAllocation((int) allocationSize, allocationOffset);
|
||||
placementComponent.initAdd(1, bitOffset);
|
||||
initControls(null, initialBaseDataType, 1);
|
||||
initControls(null, null, initialBaseDataType, 1);
|
||||
enableControls(true);
|
||||
}
|
||||
|
||||
|
@ -403,6 +407,7 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
void initEdit(DataTypeComponent bitfieldDtc, int allocationOffset,
|
||||
boolean useExistingAllocationSize) {
|
||||
String initialFieldName = null;
|
||||
String initialComment = null;
|
||||
DataType initialBaseDataType = null;
|
||||
int allocationSize = -1;
|
||||
if (useExistingAllocationSize) {
|
||||
|
@ -413,6 +418,7 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
throw new IllegalArgumentException("unsupport data type component");
|
||||
}
|
||||
initialFieldName = bitfieldDtc.getFieldName();
|
||||
initialComment = bitfieldDtc.getComment();
|
||||
BitFieldDataType bitfieldDt = (BitFieldDataType) bitfieldDtc.getDataType();
|
||||
initialBaseDataType = bitfieldDt.getBaseDataType();
|
||||
if (allocationSize < 1) {
|
||||
|
@ -429,7 +435,8 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
placementComponent.updateAllocation(allocationSize, allocationOffset);
|
||||
placementComponent.init(bitfieldDtc);
|
||||
BitFieldAllocation bitFieldAllocation = placementComponent.getBitFieldAllocation(); // get updated instance
|
||||
initControls(initialFieldName, initialBaseDataType, bitFieldAllocation.getBitSize());
|
||||
initControls(initialFieldName, initialComment, initialBaseDataType,
|
||||
bitFieldAllocation.getBitSize());
|
||||
enableControls(bitfieldDtc != null);
|
||||
}
|
||||
|
||||
|
@ -437,13 +444,14 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
placementComponent.componentDeleted(ordinal);
|
||||
}
|
||||
|
||||
private void initControls(String initialFieldName, DataType initialBaseDataType,
|
||||
int initialBitSize) {
|
||||
private void initControls(String initialFieldName, String initialComment,
|
||||
DataType initialBaseDataType, int initialBitSize) {
|
||||
updating = true;
|
||||
try {
|
||||
baseDataType = initialBaseDataType;
|
||||
dtChoiceEditor.setCellEditorValue(initialBaseDataType);
|
||||
fieldNameTextField.setText(initialFieldName);
|
||||
fieldCommentTextField.setText(initialComment);
|
||||
|
||||
// Use current placementComponent to obtain initial values
|
||||
allocSizeModel.setValue((long) placementComponent.getAllocationByteSize());
|
||||
|
@ -513,7 +521,7 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
deleteConflicts = (option == OptionDialog.OPTION_ONE);
|
||||
}
|
||||
placementComponent.applyBitField(baseDataType, fieldNameTextField.getText().trim(),
|
||||
deleteConflicts, listener);
|
||||
fieldCommentTextField.getText().trim(), deleteConflicts, listener);
|
||||
enableControls(false);
|
||||
return true;
|
||||
}
|
||||
|
@ -522,6 +530,7 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
dtChoiceEditor.getBrowseButton().setEnabled(enable);
|
||||
dtChoiceEditor.getDropDownTextField().setEnabled(enable);
|
||||
fieldNameTextField.setEnabled(enable);
|
||||
fieldCommentTextField.setEnabled(enable);
|
||||
allocSizeInput.setEnabled(enable);
|
||||
bitSizeInput.setEnabled(enable);
|
||||
bitOffsetInput.setEnabled(enable);
|
||||
|
@ -529,6 +538,8 @@ public class BitFieldEditorPanel extends JPanel {
|
|||
// TODO: set placementComponent mode to NONE
|
||||
dtChoiceEditor.getDropDownTextField().setText("");
|
||||
fieldNameTextField.setText(null);
|
||||
fieldCommentTextField.setText(null);
|
||||
;
|
||||
bitOffsetModel.setValue(0L);
|
||||
bitSizeModel.setValue(1L);
|
||||
}
|
||||
|
|
|
@ -371,8 +371,8 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
|
|||
repaint();
|
||||
}
|
||||
|
||||
void applyBitField(DataType baseDataType, String fieldName, boolean deleteConflicts,
|
||||
CompositeChangeListener listener) {
|
||||
void applyBitField(DataType baseDataType, String fieldName, String fieldComment,
|
||||
boolean deleteConflicts, CompositeChangeListener listener) {
|
||||
if (composite == null) {
|
||||
throw new IllegalStateException("Composite not loaded");
|
||||
}
|
||||
|
@ -408,18 +408,21 @@ public class BitFieldPlacementComponent extends JPanel implements Scrollable {
|
|||
|
||||
try {
|
||||
String name = (fieldName != null && fieldName.length() != 0) ? fieldName : null;
|
||||
String comment =
|
||||
(fieldComment != null && fieldComment.length() != 0) ? fieldComment : null;
|
||||
DataTypeComponent dtc;
|
||||
if (composite instanceof Union) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Union modification not currently supported");
|
||||
// dtc = composite.insertBitField(ordinal, allocationByteSize,
|
||||
// bitFieldAllocation.bitOffset, baseDataType, bitFieldAllocation.bitSize, name,
|
||||
// null);
|
||||
// comment);
|
||||
}
|
||||
// else {
|
||||
Structure struct = (Structure) composite;
|
||||
dtc = struct.insertBitFieldAt(allocationByteOffset, allocationByteSize,
|
||||
bitFieldAllocation.bitOffset, baseDataType, bitFieldAllocation.bitSize, name, null);
|
||||
bitFieldAllocation.bitOffset, baseDataType, bitFieldAllocation.bitSize, name,
|
||||
comment);
|
||||
// }
|
||||
if (listener != null) {
|
||||
listener.componentChanged(dtc.getOrdinal());
|
||||
|
|
|
@ -81,6 +81,9 @@ abstract public class CompositeEditorTableAction extends DockingAction implement
|
|||
}
|
||||
|
||||
protected void requestTableFocus() {
|
||||
if (provider == null) {
|
||||
return; // must have been disposed
|
||||
}
|
||||
JTable table = ((CompositeEditorPanel) provider.getComponent()).getTable();
|
||||
if (table.isEditing()) {
|
||||
table.getEditorComponent().requestFocus();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue