Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3352 - Structure Editor - 'Duplicate Selected Component' put into a task to not lock-up the UI

dragonmacherf9a0d814ef6d
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java
index c42010b15a..1adb158953 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java
@@ -25,6 +25,7 @@ import ghidra.program.model.data.Composite.AlignmentType;
import ghidra.program.model.lang.InsufficientBytesException;
import ghidra.util.*;
import ghidra.util.exception.*;
+import ghidra.util.task.TaskMonitor;
public abstract class CompEditorModel extends CompositeEditorModel {
@@ -131,11 +132,13 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
}
- // **********************************************************************
- // * OVERRIDDEN METHODS FOR THE SELECTION
- // **********************************************************************
+//==================================================================================================
+// OVERRIDDEN METHODS FOR THE SELECTION
+//==================================================================================================
+
/**
- * Returns true if the GUI has the blank last line selected.
+ * Returns true if the GUI has the blank last line selected
+ * @return true if the GUI has the blank last line selected
*/
boolean isBlankLastLineSelected() {
return selection.contains(new FieldLocation(getNumComponents(), 0, 0, 0));
@@ -147,11 +150,12 @@ public abstract class CompEditorModel extends CompositeEditorModel {
*
* @param range the range of indices for the component's whose sizes should
* be added together.
+ * @return the number of bytes
*/
protected abstract int getNumBytesInRange(FieldRange range);
/**
- * Saves the current selection in the components viewing area.
+ * Saves the current selection in the components viewing area.
*
* @param rows the indexes for the selected rows.
*/
@@ -168,10 +172,10 @@ public abstract class CompEditorModel extends CompositeEditorModel {
else {
// restrict multi-selection to defined components only
int numComponents = getNumComponents();
- for (int i = 0; i < rows.length; i++) {
+ for (int row2 : rows) {
// Only add valid component rows (i.e. don't include blank last line)
- if (rows[i] < numComponents) {
- tmpSelection.addRange(rows[i], rows[i] + 1);
+ if (row2 < numComponents) {
+ tmpSelection.addRange(row2, row2 + 1);
}
}
}
@@ -244,9 +248,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return true;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeEditorModel#setDataType(int, ghidra.program.model.data.DataType, int)
- */
protected void setDataType(int rowIndex, DataType dt, int length) throws UsrException {
if (rowIndex < getNumComponents()) {
replace(rowIndex, dt, length);
@@ -277,9 +278,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return super.validateComponentDataType(rowIndex, dtString);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isAddAllowed(ghidra.program.model.data.DataType)
- */
@Override
public boolean isAddAllowed(DataType dataType) {
int rowIndex = getMinIndexSelected();
@@ -289,26 +287,16 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return isAddAllowed(rowIndex, dataType);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeEditorModel#isClearAllowed()
- */
@Override
public boolean isClearAllowed() {
return (getNumSelectedRows() > 0) && !isBlankLastLineSelected();
}
- /**
- * @param cycleGroup
- * @return
- */
@Override
public boolean isCycleAllowed(CycleGroup cycleGroup) {
return (getNumSelectedRows() == 1);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isInsertAllowed(ghidra.program.model.data.DataType)
- */
public boolean isInsertAllowed(DataType dataType) {
int rowIndex = getMinIndexSelected();
if (rowIndex == -1) {
@@ -329,9 +317,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return true;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isReplaceAllowed(ghidra.program.model.data.DataType)
- */
public boolean isReplaceAllowed(DataType dataType) {
if (getNumSelectedComponentRows() != 1) {
return false;
@@ -348,13 +333,17 @@ public abstract class CompEditorModel extends CompositeEditorModel {
* @param componentOrdinal the ordinal of the component to be deleted.
*/
void delete(int componentOrdinal) {
+ doDelete(componentOrdinal);
+ selection.removeRange(componentOrdinal, componentOrdinal + 1);
+ adjustSelection(componentOrdinal + 1, -1);
+ notifyCompositeChanged();
+ }
+
+ private void doDelete(int componentOrdinal) {
viewComposite.delete(componentOrdinal);
if (componentOrdinal < row) {
row--;
}
- selection.removeRange(componentOrdinal, componentOrdinal + 1);
- adjustSelection(componentOrdinal + 1, -1);
- notifyCompositeChanged();
}
/**
@@ -365,12 +354,24 @@ public abstract class CompEditorModel extends CompositeEditorModel {
* @param rows array with each row (component) index to delete.
*/
private void delete(int[] rows) {
+
+ int[] selectedRows = getSelectedRows();
Arrays.sort(rows);
for (int i = rows.length - 1; i >= 0; i--) {
int rowIndex = rows[i];
int componentOrdinal = convertRowToOrdinal(rowIndex);
- delete(componentOrdinal);
+ doDelete(componentOrdinal);
+ }
+
+ // Not sure if this is the right behavior. Assuming the deleted rows were selected,
+ // restore the selection to be the first row that was deleted so that the UI leaves the
+ // user's selection close to where it was.
+ if (selectedRows.length > 0) {
+ setSelection(new int[] { selectedRows[0] });
}
+
+ notifyCompositeChanged();
+
}
/**
@@ -396,22 +397,30 @@ public abstract class CompEditorModel extends CompositeEditorModel {
*
* @param startRowIndex index of the starting row for the components to delete.
* @param endRowIndex index of the ending row (inclusive) for the components to delete.
+ * @param monitor the task monitor
+ * @throws CancelledException if the work was cancelled
*/
- void deleteComponentRange(int startRowIndex, int endRowIndex) {
+ void deleteComponentRange(int startRowIndex, int endRowIndex, TaskMonitor monitor)
+ throws CancelledException {
if (isEditingField()) {
endFieldEditing();
}
+
final int entries = endRowIndex - startRowIndex + 1;
int[] ordinals = new int[entries];
- int ii = 0;
- for (int rowIndex = endRowIndex; rowIndex >= startRowIndex; rowIndex--, ++ii) {
+
+ monitor.initialize(entries);
+ int i = 0;
+ for (int rowIndex = endRowIndex; rowIndex >= startRowIndex; rowIndex--, i++) {
+ monitor.checkCanceled();
int componentOrdinal = convertRowToOrdinal(rowIndex);
- ordinals[ii] = componentOrdinal;
+ ordinals[i] = componentOrdinal;
if (componentOrdinal < row) {
row--;
}
selection.removeRange(componentOrdinal, componentOrdinal + 1);
adjustSelection(componentOrdinal + 1, -1);
+ monitor.incrementProgress(1);
}
viewComposite.delete(ordinals);
fixSelection();
@@ -420,11 +429,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
selectionChanged();
}
- /**
- * Delete the selected components.
- *
- * @throws UsrException if the data type isn't allowed to be deleted.
- */
@Override
public void deleteSelectedComponents() throws UsrException {
if (!isDeleteAllowed()) {
@@ -457,8 +461,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {
protected abstract DataTypeComponent insert(int rowIndex, DataType dataType, int length,
String name, String comment) throws InvalidDataTypeException;
- protected abstract void insert(int rowIndex, DataType dataType, int length, int numCopies)
- throws InvalidDataTypeException;
+ protected abstract void insert(int rowIndex, DataType dataType, int length, int numCopies,
+ TaskMonitor monitor) throws InvalidDataTypeException, CancelledException;
/**
* Add a DataType component into to an editable structure
@@ -468,23 +472,23 @@ public abstract class CompEditorModel extends CompositeEditorModel {
* @param dataType data type to be inserted into the structure
* @param dtLen the length of the data type
* @param multiple number of copies of the item to be added.
+ * @param monitor the task monitor
*
* @throws NoSuchElementException if there is no component with the specified index.
* @throws InvalidDataTypeException if the structure being edited is part
* of the data type being inserted.
+ * @throws CancelledException if the work was cancelled
*/
- protected void insertMultiple(int rowIndex, DataType dataType, int dtLen, int multiple)
- throws java.util.NoSuchElementException, InvalidDataTypeException {
+ protected void insertMultiple(int rowIndex, DataType dataType, int dtLen, int multiple,
+ TaskMonitor monitor)
+ throws NoSuchElementException, InvalidDataTypeException, CancelledException {
if (multiple < 1) {
return;
}
- insert(rowIndex, dataType, dtLen, multiple);
+ insert(rowIndex, dataType, dtLen, multiple, monitor);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#insert(ghidra.program.model.data.DataType)
- */
@Override
public DataTypeComponent insert(DataType dataType) throws UsrException {
if (hasSelection()) {
@@ -551,26 +555,27 @@ public abstract class CompEditorModel extends CompositeEditorModel {
* @param dataType data type to be inserted into the structure
* @param dtLen the length of the data type
* @param multiple number of copies of the item to be added.
+ * @param monitor the task monitor
*
* @throws NoSuchElementException if there is no component with the specified index.
* @throws InvalidDataTypeException if the structure being edited is part
* of the data type being inserted.
+ * @throws CancelledException if the work was cancelled
*/
- protected void insertComponentMultiple(int rowIndex, DataType dataType, int dtLen, int multiple)
- throws java.util.NoSuchElementException, InvalidDataTypeException {
+ protected void insertComponentMultiple(int rowIndex, DataType dataType, int dtLen, int multiple,
+ TaskMonitor monitor)
+ throws NoSuchElementException, InvalidDataTypeException, CancelledException {
if (isEditingField()) {
endFieldEditing();
}
+
checkIsAllowableDataType(dataType, true);
- insertMultiple(rowIndex, dataType, dtLen, multiple);
+ insertMultiple(rowIndex, dataType, dtLen, multiple, monitor);
fixSelection();
componentEdited();
selectionChanged();
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#add(ghidra.program.model.data.DataType)
- */
@Override
public DataTypeComponent add(DataType dataType) throws UsrException {
if (isContiguousSelection()) {
@@ -634,9 +639,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return dtc;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#replace(ghidra.program.model.data.DataType)
- */
public DataTypeComponent replace(DataType dataType) throws UsrException {
if (isContiguousComponentSelection()) {
return replace(getMinIndexSelected(), dataType);
@@ -693,31 +695,26 @@ public abstract class CompEditorModel extends CompositeEditorModel {
String name, String comment) throws InvalidDataTypeException;
/**
- * Replace the structure components from the start index to the end index
- * (inclusive) with as many of the specified data type as will fit.
- * Pad any left over bytes as undefineds.
+ * Replace the structure components from the start index to the end index
+ * (inclusive) with as many of the specified data type as will fit.
+ * Pad any left over bytes as undefined bytes.
*
* @param startRowIndex index of the first row (component) to replace.
* @param endRowIndex index of the last row (component) to replace.
* @param datatype the new data type
+ * @param length the length of the range
+ * @param monitor the task monitor
+ * @return true if the replacement worked
*
* @throws InvalidDataTypeException if the structure being edited is part
- * of the data type being inserted.
- * @throws InsufficientBytesException if ther aren't enough bytes in the
- * specified range.
+ * of the data type being inserted
+ * @throws InsufficientBytesException if there aren't enough bytes in the specified range
+ * @throws CancelledException the the work is cancelled
*/
protected abstract boolean replaceRange(int startRowIndex, int endRowIndex, DataType datatype,
- int length) throws InvalidDataTypeException, InsufficientBytesException;
+ int length, TaskMonitor monitor)
+ throws InvalidDataTypeException, InsufficientBytesException, CancelledException;
- /**
- * Replaces the component at the indicated index.
- * The existing fieldname and comment are retained.
- * The selection is adjusted and change notification occurs.
- * @param rowIndex
- * @param datatype
- * @return
- * @throws InvalidDataTypeException
- */
@Override
public DataTypeComponent replace(int rowIndex, DataType datatype, int length)
throws UsrException {
@@ -769,15 +766,14 @@ public abstract class CompEditorModel extends CompositeEditorModel {
/**
* Replaces the range of components between the start and end index (inclusive).
- * The existing fieldname and comment are retained for the component at startIndex.
+ * The existing field name and comment are retained for the component at startIndex.
* The selection is adjusted and change notification occurs.
- * @param startRowIndex
- * @param endRowIndex
- * @param datatype
- * @param length
- * @return
- * @throws InvalidDataTypeException
- * @throws InsufficientBytesException
+ * @param startRowIndex the start index
+ * @param endRowIndex the end index
+ * @param datatype the data type
+ * @param length the length of the range
+ * @return the newly create component
+ * @throws UsrException if there is an exception replacing
*/
protected DataTypeComponent replaceComponentRange(int startRowIndex, int endRowIndex,
DataType datatype, int length) throws UsrException {
@@ -797,14 +793,22 @@ public abstract class CompEditorModel extends CompositeEditorModel {
checkIsAllowableDataType(datatype, true);
- replaceRange(startRowIndex, endRowIndex, datatype, length);
+ //
+ // Note: if the range being replaced is large enough, then the UI could lock-up. If we
+ // find that is the case, then we can update this method to take in a task monitor
+ // and update the clients accordingly. For now, it does not seem worth the effort.
+ //
+ TaskMonitor monitor = TaskMonitor.DUMMY;
+
+ replaceRange(startRowIndex, endRowIndex, datatype, length, monitor);
DataTypeComponent dtc = getComponent(startRowIndex);
- // Set the fieldname and comment the same as before
+
+ // Set the field name and comment the same as before
try {
dtc.setFieldName(oldDtc.getFieldName());
}
- catch (DuplicateNameException exc) {
- Msg.showError(this, null, null, null);
+ catch (DuplicateNameException e) {
+ Msg.showError(this, null, "Unexcected Exception", "Exception applying field name", e);
}
dtc.setComment(oldDtc.getComment());
fixSelection();
@@ -814,13 +818,15 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
/**
- * Check to see if the specified data type fits in place of the data type
- * at the specified index of the data structure.<BR>
- * If the new data type is smaller, then it can replace the current one.<BR>
- * If the new data type is larger, then replace if we have enough
- * undefined bytes following the specified index.
+ * Check to see if the specified data type fits in place of the data type
+ * at the specified index of the data structure.<BR>
+ * If the new data type is smaller, then it can replace the current one.<BR>
+ * If the new data type is larger, then replace if we have enough
+ * undefined bytes following the specified index.
*
* @param rowIndex index of the row (component).
+ * @param datatype the type
+ * @return true if the replace is allowed
*/
boolean checkForReplace(int rowIndex, DataType datatype) {
DataTypeComponent dtc = getComponent(rowIndex);
@@ -927,9 +933,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return true;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#moveUp()
- */
@Override
public boolean moveUp() throws NoSuchElementException {
if (selection.getNumRanges() != 1) {
@@ -954,9 +957,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return moved;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#moveDown()
- */
@Override
public boolean moveDown() throws NoSuchElementException {
if (selection.getNumRanges() != 1) {
@@ -981,32 +981,19 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return moved;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#duplicateMultiple(int, int)
- */
@Override
- public void duplicateMultiple(int rowIndex, int multiple) throws UsrException {
+ public void duplicateMultiple(int rowIndex, int multiple, TaskMonitor monitor)
+ throws UsrException {
DataTypeComponent originalComp = getComponent(rowIndex);
DataType dt = originalComp.getDataType();
int dtLen = originalComp.getLength();
- try {
- insertComponentMultiple(rowIndex + 1, dt, dtLen, multiple);
- }
- catch (OutOfMemoryError memExc) {
- throw memExc; // rethrow the exception.
- }
+ insertComponentMultiple(rowIndex + 1, dt, dtLen, multiple, monitor);
componentEdited();
lastNumDuplicates = multiple;
}
- /**
- * Clear the components at the specified indices.
- *
- * @param rows ordered array of the selected row's indices.
- * @throws UsrException if clearing isn't allowed.
- */
@Override
public abstract void clearComponents(int[] rows) throws UsrException;
@@ -1051,6 +1038,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
* beginning at the specified row index.
*
* @param rowIndex the index of the row
+ * @return the number of bytes
*/
protected int getNumUndefinedBytesAt(int rowIndex) {
int numRowComponents = getNumComponents();
@@ -1099,7 +1087,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
* until the end of the composite. There must be at least one undefined data type to return true.
*
* @param rowIndex the index of the row to begin checking for undefined data types.
- * @return true if an undefined data type is at the indicated row index and all componnents
+ * @return true if an undefined data type is at the indicated row index and all components
* from there to the end of the composite are undefined data types.
*/
protected boolean onlyUndefinedsUntilEnd(int rowIndex) {
@@ -1128,6 +1116,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {
* Cause the component at the specified index to consume undefined bytes
* that follow it.
* Note: this method adjusts the selection.
+ *
+ * @param rowIndex the row index
* @return the number of Undefined bytes consumed.
*/
protected int consumeByComponent(int rowIndex) {
@@ -1222,14 +1212,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return numIndicesRemoved;
}
- /**
- * Returns the number of component rows in the editor. If unlocked, there
- * is a blank row at the end for inserting. Therefore this number can be
- * different than the actual number of components currently in the
- * structure being edited.
- *
- * @return the number of rows in the model
- */
@Override
public int getRowCount() {
int numRows = 0;
@@ -1242,13 +1224,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return numRows;
}
- /**
- * This updates one of the values for a component that is a field of
- * this data structure.
- * @param aValue the new value for the field
- * @param rowIndex the index of the row for the component
- * @param modelColumnIndex the model field index within the component
- */
@Override
public void setValueAt(Object aValue, int rowIndex, int modelColumnIndex) {
try {
@@ -1262,9 +1237,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#setComponentDataType(int, ghidra.program.model.data.DataType, int)
- */
@Override
public void setComponentDataTypeInstance(int rowIndex, DataTypeInstance dti)
throws UsrException {
@@ -1280,9 +1252,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeEditorModel#validateComponentName(int, java.lang.String)
- */
@Override
public void validateComponentName(int rowIndex, String name) throws UsrException {
if (nameExistsElsewhere(name, rowIndex)) {
@@ -1290,9 +1259,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#setComponentName(int, java.lang.String)
- */
@Override
public void setComponentName(int rowIndex, String name)
throws InvalidInputException, InvalidNameException, DuplicateNameException {
@@ -1310,9 +1276,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#setComponentComment(int, java.lang.String)
- */
@Override
public void setComponentComment(int rowIndex, String comment) throws InvalidInputException {
if (comment.equals("")) {
@@ -1344,13 +1307,13 @@ public abstract class CompEditorModel extends CompositeEditorModel {
(selection.getFieldRange(0).getEnd().getIndex().intValue() < getNumComponents()));
}
- // *************************************************************
- // End of methods for determining if a type of edit action is allowed.
- // *************************************************************
+//==================================================================================================
+// End of methods for determining if a type of edit action is allowed.
+//==================================================================================================
- // *************************************************************
- // Override CompositeViewerModel CategoryChangeListener methods
- // *************************************************************
+//==================================================================================================
+// Override CompositeViewerModel CategoryChangeListener methods
+//==================================================================================================
@Override
public void dataTypeChanged(DataTypeManager dtm, DataTypePath path) {
@@ -1516,7 +1479,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
}
- // *** HELPER METHODS for use with CategoryChangeListener methods. ***
/**
* Removes the indicated data type from any components to prevent a cycle
* being created by this component being updated. Structures will actually
@@ -1526,13 +1488,10 @@ public abstract class CompEditorModel extends CompositeEditorModel {
*/
abstract void removeDtFromComponents(Composite comp);
- // *************************************************************
- // End of Override CompositeViewerModel CategoryChangeListener methods
- // *************************************************************
+//==================================================================================================
+// End of Override CompositeViewerModel CategoryChangeListener methods
+//==================================================================================================
- /* (non-Javadoc)
- * @see javax.swing.table.AbstractTableModel#fireTableDataChanged()
- */
@Override
public void fireTableDataChanged() {
boolean tmpUpdatingSelection = updatingSelection;
@@ -1689,7 +1648,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
/**
- * Return the external (minimum) alignment type for the structure or union being viewed.
+ * Return the external (minimum) alignment type for the structure or union being viewed
+ * @return the alignment type
*/
public AlignmentType getMinimumAlignmentType() {
if (viewComposite.isDefaultAligned()) {
@@ -1702,7 +1662,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
/**
- * Return the external (minimum) alignment value for the structure or union being viewed.
+ * Return the external (minimum) alignment value for the structure or union being viewed.
+ * @return the alignment
*/
public int getMinimumAlignment() {
if (viewComposite != null) {
@@ -1711,7 +1672,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return 0;
}
- public void setAlignmentType(AlignmentType alignmentType) throws InvalidInputException {
+ public void setAlignmentType(AlignmentType alignmentType) {
if (alignmentType == AlignmentType.DEFAULT_ALIGNED) {
viewComposite.setToDefaultAlignment();
}
@@ -1730,7 +1691,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
public abstract void setAlignment(int alignmentValue) throws InvalidInputException;
- public void setPackingValue(int packingValue) throws InvalidInputException {
+ public void setPackingValue(int packingValue) {
int currentViewPackingValue = viewComposite.getPackingValue();
if (currentViewPackingValue == packingValue) {
return;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorPanel.java
index 56f7a3324e..da18ec59ea 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorPanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorPanel.java
@@ -36,7 +36,8 @@ import ghidra.program.model.data.Composite;
import ghidra.program.model.data.Composite.AlignmentType;
import ghidra.util.HelpLocation;
import ghidra.util.InvalidNameException;
-import ghidra.util.exception.*;
+import ghidra.util.exception.DuplicateNameException;
+import ghidra.util.exception.InvalidInputException;
import ghidra.util.layout.PairLayout;
import ghidra.util.layout.VerticalLayout;
@@ -92,8 +93,6 @@ public class CompEditorPanel extends CompositeEditorPanel {
* Constructor for a panel that has a blank line in unlocked mode and
* composite name and description that are editable.
*
- * @param program
- * the current program open in the tool.
* @param model
* the model for editing the composite data type
* @param provider
@@ -116,11 +115,6 @@ public class CompEditorPanel extends CompositeEditorPanel {
setCompositeSize(model.getLength());
}
- /*
- * (non-Javadoc)
- *
- * @see ghidra.app.plugin.compositeeditor.CompositeViewerModelListener#compositeInfoChanged()
- */
@Override
public void compositeInfoChanged() {
adjustCompositeInfo();
@@ -667,12 +661,7 @@ public class CompEditorPanel extends CompositeEditorPanel {
"Note: An individual data type's alignment may override this value.</HTML>";
noPackingButton.addActionListener(e -> {
- try {
- ((CompEditorModel) model).setPackingValue(Composite.NOT_PACKING);
- }
- catch (InvalidInputException e1) {
- throw new AssertException("Error setting packing value to NotPacking.");
- }
+ ((CompEditorModel) model).setPackingValue(Composite.NOT_PACKING);
});
noPackingButton.setToolTipText(packingToolTipText);
@@ -725,12 +714,7 @@ public class CompEditorPanel extends CompositeEditorPanel {
}
protected void chooseByValuePacking() {
- try {
- ((CompEditorModel) model).setPackingValue(1);
- }
- catch (InvalidInputException e1) {
- throw new AssertException("Error setting packing value to 1.");
- }
+ ((CompEditorModel) model).setPackingValue(1);
packingValueTextField.selectAll();
packingValueTextField.requestFocus();
}
@@ -745,14 +729,9 @@ public class CompEditorPanel extends CompositeEditorPanel {
if (!value.toLowerCase().equals(NO_PACKING_STRING)) {
packingAlignment = Integer.decode(value);
}
- try {
- ((CompEditorModel) model).setPackingValue(packingAlignment);
- adjustCompositeInfo();
- }
- catch (InvalidInputException e1) {
- refreshGUIPackingValue();
- setStatus(value + " is not a valid packing value.");
- }
+
+ ((CompEditorModel) model).setPackingValue(packingAlignment);
+ adjustCompositeInfo();
}
catch (NumberFormatException e1) {
refreshGUIPackingValue();
@@ -780,9 +759,7 @@ public class CompEditorPanel extends CompositeEditorPanel {
}
/**
- * Sets the currently displayed structure packing value (maximum component alignment).
- *
- * @param packingValue the new packing value.
+ * Sets the currently displayed structure packing value (maximum component alignment)
*/
public void refreshGUIPackingValue() {
int packingValue = ((CompEditorModel) model).getPackingValue();
@@ -1003,30 +980,15 @@ public class CompEditorPanel extends CompositeEditorPanel {
}
protected void chooseDefaultMinAlign() {
- try {
- ((CompEditorModel) model).setAlignmentType(AlignmentType.DEFAULT_ALIGNED);
- }
- catch (InvalidInputException e1) {
- throw new AssertException("Error setting minimum alignment type to default.");
- }
+ ((CompEditorModel) model).setAlignmentType(AlignmentType.DEFAULT_ALIGNED);
}
protected void chooseMachineMinAlign() {
- try {
- ((CompEditorModel) model).setAlignmentType(AlignmentType.MACHINE_ALIGNED);
- }
- catch (InvalidInputException e1) {
- throw new AssertException("Error setting minimum alignment type to machine.");
- }
+ ((CompEditorModel) model).setAlignmentType(AlignmentType.MACHINE_ALIGNED);
}
protected void chooseByValueMinAlign() {
- try {
- ((CompEditorModel) model).setAlignmentType(AlignmentType.ALIGNED_BY_VALUE);
- }
- catch (InvalidInputException e1) {
- throw new AssertException("Error setting minimum alignment type to ByValue.");
- }
+ ((CompEditorModel) model).setAlignmentType(AlignmentType.ALIGNED_BY_VALUE);
minAlignValueTextField.selectAll();
minAlignValueTextField.requestFocus();
}
@@ -1113,6 +1075,7 @@ public class CompEditorPanel extends CompositeEditorPanel {
/**
* Returns the currently displayed structure category name.
+ * @return the name
*/
public String getCategoryName() {
return categoryStatusTextField.getText();
@@ -1130,6 +1093,7 @@ public class CompEditorPanel extends CompositeEditorPanel {
/**
* Returns the currently displayed structure name in the edit area.
+ * @return the name
*/
public String getCompositeName() {
return nameTextField.getText().trim();
@@ -1154,6 +1118,7 @@ public class CompEditorPanel extends CompositeEditorPanel {
/**
* Returns the currently displayed structure description.
+ * @return the description
*/
public String getDescription() {
return descriptionTextField.getText().trim();
@@ -1170,16 +1135,17 @@ public class CompEditorPanel extends CompositeEditorPanel {
}
/**
- * Checks the GUI to determine if this composite is internally aligned.
+ * Checks the GUI to determine if this composite is internally aligned
+ * @return true if interanlly aligned
*/
public boolean isInternallyAlignedInGui() {
return internalAlignmentCheckBox.isSelected();
}
/**
- * Sets the currently displayed structure minimum alignment type.
+ * Sets the currently displayed structure minimum alignment type
*
- * @param minAlignment the new MinimumAlignment type.
+ * @param aligned true if aligned
*/
public void setInternallyAligned(boolean aligned) {
boolean alignedInGui = internalAlignmentCheckBox.isSelected();
@@ -1226,6 +1192,7 @@ public class CompEditorPanel extends CompositeEditorPanel {
/**
* Returns the currently displayed composite's size.
+ * @return the size
*/
public int getCompositeSize() {
return Integer.decode(sizeStatusTextField.getText());
@@ -1234,8 +1201,7 @@ public class CompEditorPanel extends CompositeEditorPanel {
/**
* Sets the currently displayed composite's size.
*
- * @param id
- * the new size
+ * @param size the new size
*/
public void setCompositeSize(int size) {
boolean sizeIsEditable = ((CompEditorModel) model).isSizeEditable();
@@ -1247,14 +1213,6 @@ public class CompEditorPanel extends CompositeEditorPanel {
sizeStatusTextField.setText(sizeStr);
}
- /**
- * Called from the DropTgtAdapter when the drag operation is going over a
- * drop site; indicate when the drop is ok by providing appropriate
- * feedback.
- *
- * @param ok
- * true means ok to drop
- */
@Override
public void dragUnderFeedback(boolean ok, DropTargetDragEvent e) {
synchronized (table) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DuplicateAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DuplicateAction.java
index d0669743a1..bf136bb86a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DuplicateAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DuplicateAction.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,58 +15,61 @@
*/
package ghidra.app.plugin.core.compositeeditor;
-import ghidra.util.exception.UsrException;
-
-import java.awt.Event;
+import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;
-import resources.ResourceManager;
import docking.ActionContext;
import docking.action.KeyBindingData;
-
+import ghidra.util.exception.UsrException;
+import ghidra.util.task.TaskMonitor;
+import resources.ResourceManager;
/**
- * Action for use in the composite data type editor.
- * This action has help associated with it.
+ * Action to duplicate the selected row
*/
public class DuplicateAction extends CompositeEditorTableAction {
- private final static ImageIcon duplicateDataIcon = ResourceManager.loadImage("images/DuplicateData.png");
- private final static String ACTION_NAME = "Duplicate Component";
- private final static String GROUP_NAME = COMPONENT_ACTION_GROUP;
- private final static String DESCRIPTION = "Duplicate the selected component";
- private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.ALT_MASK);
- private static String[] popupPath = new String[] { ACTION_NAME };
+ private final static ImageIcon duplicateDataIcon =
+ ResourceManager.loadImage("images/DuplicateData.png");
+ private final static String ACTION_NAME = "Duplicate Component";
+ private final static String GROUP_NAME = COMPONENT_ACTION_GROUP;
+ private final static String DESCRIPTION = "Duplicate the selected component";
+ private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_DOWN_MASK);
+ private static String[] popupPath = new String[] { ACTION_NAME };
- public DuplicateAction(CompositeEditorProvider provider) {
- super(provider, EDIT_ACTION_PREFIX + ACTION_NAME, GROUP_NAME, popupPath, null, duplicateDataIcon);
- setDescription(DESCRIPTION);
- setKeyBindingData( new KeyBindingData( keyStroke ) );
+ public DuplicateAction(CompositeEditorProvider provider) {
+ super(provider, EDIT_ACTION_PREFIX + ACTION_NAME, GROUP_NAME, popupPath, null,
+ duplicateDataIcon);
+ setDescription(DESCRIPTION);
+ setKeyBindingData(new KeyBindingData(keyStroke));
adjustEnablement();
- }
-
- @Override
- public void actionPerformed(ActionContext context) {
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
int[] indices = model.getSelectedComponentRows();
- if (indices.length == 1) {
- int max = model.getMaxDuplicates(indices[0]);
- if (max != 0) {
- try {
- model.duplicateMultiple(indices[0], 1);
- } catch (UsrException e1) {
- model.setStatus(e1.getMessage(), true);
- }
+ if (indices.length != 1) {
+ return;
+ }
+
+ int max = model.getMaxDuplicates(indices[0]);
+ if (max != 0) {
+ try {
+ // note: only duplicating one item; no need for a task
+ model.duplicateMultiple(indices[0], 1, TaskMonitor.DUMMY);
+ }
+ catch (UsrException e1) {
+ model.setStatus(e1.getMessage(), true);
}
}
requestTableFocus();
- }
-
- @Override
- public void adjustEnablement() {
- setEnabled(model.isDuplicateAllowed());
- }
-}
+ }
+ @Override
+ public void adjustEnablement() {
+ setEnabled(model.isDuplicateAllowed());
+ }
+}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DuplicateMultipleAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DuplicateMultipleAction.java
index 35598934fa..3cc591ccba 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DuplicateMultipleAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DuplicateMultipleAction.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,23 +15,24 @@
*/
package ghidra.app.plugin.core.compositeeditor;
-import ghidra.util.HelpLocation;
-import ghidra.util.exception.UsrException;
-
-import java.awt.Event;
+import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;
-import resources.ResourceManager;
import docking.ActionContext;
import docking.action.KeyBindingData;
import docking.widgets.dialogs.NumberInputDialog;
+import ghidra.util.HelpLocation;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.exception.UsrException;
+import ghidra.util.task.TaskLauncher;
+import ghidra.util.task.TaskMonitor;
+import resources.ResourceManager;
/**
- * Action for use in the composite data type editor.
- * This action has help associated with it.
+ * Action that allows the user to make multiple duplicates of the selected item
*/
public class DuplicateMultipleAction extends CompositeEditorTableAction {
@@ -41,7 +41,7 @@ public class DuplicateMultipleAction extends CompositeEditorTableAction {
private final static String ACTION_NAME = "Duplicate Multiple of Component";
private final static String GROUP_NAME = COMPONENT_ACTION_GROUP;
private final static String DESCRIPTION = "Duplicate multiple of the selected component";
- private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.ALT_MASK);
+ private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.ALT_DOWN_MASK);
private static String[] popupPath = new String[] { ACTION_NAME };
public DuplicateMultipleAction(CompositeEditorProvider provider) {
@@ -55,30 +55,46 @@ public class DuplicateMultipleAction extends CompositeEditorTableAction {
@Override
public void actionPerformed(ActionContext context) {
int[] indices = model.getSelectedComponentRows();
- if (indices.length == 1) {
- int min = 1;
- int max = model.getMaxDuplicates(indices[0]);
- if (max != 0) {
- int initial = model.getLastNumDuplicates();
- NumberInputDialog numberInputDialog =
- new NumberInputDialog("duplicates", ((initial > 0) ? initial : 1), min, max);
- String helpAnchor = provider.getHelpName() + "_" + "Duplicates_NumberInputDialog";
- HelpLocation helpLoc = new HelpLocation(provider.getHelpTopic(), helpAnchor);
- numberInputDialog.setHelpLocation(helpLoc);
- if (numberInputDialog.show()) {
- int numDuplicates = numberInputDialog.getValue();
- try {
- model.duplicateMultiple(indices[0], numDuplicates);
- }
- catch (UsrException e1) {
- model.setStatus(e1.getMessage(), true);
- }
- }
- }
+ if (indices.length != 1) {
+ return;
+ }
+
+ int row = indices[0];
+ int min = 1;
+ int max = model.getMaxDuplicates(row);
+ if (max == 0) {
+ return;
}
+
+ int initial = model.getLastNumDuplicates();
+ NumberInputDialog numberInputDialog =
+ new NumberInputDialog("duplicates", ((initial > 0) ? initial : 1), min, max);
+ String helpAnchor = provider.getHelpName() + "_" + "Duplicates_NumberInputDialog";
+ HelpLocation helpLoc = new HelpLocation(provider.getHelpTopic(), helpAnchor);
+ numberInputDialog.setHelpLocation(helpLoc);
+
+ if (numberInputDialog.show()) {
+ int count = numberInputDialog.getValue();
+ TaskLauncher.launchModal("Duplicating Component",
+ monitor -> doInsert(row, count, monitor));
+ }
+
requestTableFocus();
}
+ private void doInsert(int row, int count, TaskMonitor monitor) {
+ try {
+ model.duplicateMultiple(row, count, monitor);
+ }
+ catch (CancelledException e) {
+ // user cancelled
+ }
+ catch (UsrException e) {
+ model.setStatus(e.getMessage(), true);
+ }
+ model.fireTableDataChanged();
+ }
+
@Override
public void adjustEnablement() {
setEnabled(model.isDuplicateAllowed());
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorModel.java
index ec2ba18e70..d5f1db6bbb 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorModel.java
@@ -19,6 +19,7 @@ import ghidra.app.util.datatype.EmptyCompositeException;
import ghidra.program.model.data.*;
import ghidra.util.InvalidNameException;
import ghidra.util.exception.*;
+import ghidra.util.task.TaskMonitor;
public interface EditorModel {
@@ -340,9 +341,11 @@ public interface EditorModel {
* indicated component.
* @param rowIndex the index of the row whose component is to be duplicated.
* @param multiple the number of duplicates to create.
+ * @param monitor the task monitor
* @throws UsrException if component can't be duplicated the indicated number of times.
*/
- public void duplicateMultiple(int rowIndex, int multiple) throws UsrException;
+ public void duplicateMultiple(int rowIndex, int multiple, TaskMonitor monitor)
+ throws UsrException;
/**
*
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java
index d68cad92c4..ecdb9fe90d 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java
@@ -30,6 +30,7 @@ import ghidra.program.model.data.*;
import ghidra.program.model.lang.InsufficientBytesException;
import ghidra.util.Msg;
import ghidra.util.exception.*;
+import ghidra.util.task.TaskMonitor;
class StructureEditorModel extends CompEditorModel {
@@ -284,14 +285,6 @@ class StructureEditorModel extends CompEditorModel {
fireTableDataChanged();
}
- /**
- * returns whether or not a particular component row and field in this
- * structure is editable.
- * <P>Warning: There shouldn't be a selection when this is called.
- *
- * @param rowIndex the component index.
- * @param columnIndex the index for the field of the component.
- */
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (getNumSelectedRows() != 1) {
@@ -323,13 +316,6 @@ class StructureEditorModel extends CompEditorModel {
}
}
- /**
- * Clear the selected components.
- *
- * @return true if cleared.
- *
- * @throws UsrException if clearing isn't allowed.
- */
@Override
public void clearSelectedComponents() throws UsrException {
if (!isClearAllowed()) {
@@ -342,20 +328,11 @@ class StructureEditorModel extends CompEditorModel {
clearComponents(getSelectedComponentRows());
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#clearComponent(int)
- */
@Override
public void clearComponent(int ordinal) {
((Structure) viewComposite).clearComponent(ordinal);
}
- /**
- * Clear the components at the specified indices.
- *
- * @param indices array of selected component indices.
- * @return true if cleared.
- */
@Override
public void clearComponents(int[] indices) {
if (isEditingField()) {
@@ -424,36 +401,29 @@ class StructureEditorModel extends CompEditorModel {
return definedComponents[rowIndex].getOrdinal();
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#duplicateMultiple(int, int)
- */
@Override
- public void duplicateMultiple(int index, int multiple) throws UsrException {
+ public void duplicateMultiple(int index, int multiple, TaskMonitor monitor)
+ throws UsrException {
if (isEditingField()) {
endFieldEditing();
}
DataTypeComponent originalComp = getComponent(index);
if (originalComp == null || originalComp.isFlexibleArrayComponent()) {
- throw new IllegalArgumentException("invalid component index specified");
+ throw new IllegalArgumentException("Invalid component index specified");
}
DataType dt = originalComp.getDataType();
int dtLen = dt.getLength();
checkIsAllowableDataType(dt, true);
- try {
- int startIndex = index + 1;
- if (isShowingUndefinedBytes() && (dt != DataType.DEFAULT)) {
- int endIndex = startIndex + (dtLen * multiple) - 1;
- if (startIndex < getNumComponents()) {
- deleteComponentRange(startIndex, endIndex);
- }
+ int startIndex = index + 1;
+ if (isShowingUndefinedBytes() && (dt != DataType.DEFAULT)) {
+ int endIndex = startIndex + (dtLen * multiple) - 1;
+ if (startIndex < getNumComponents()) {
+ deleteComponentRange(startIndex, endIndex, monitor);
}
- insertComponentMultiple(startIndex, dt, originalComp.getLength(), multiple);
- }
- catch (OutOfMemoryError memExc) {
- throw memExc; // re-throw the exception.
}
+ insertComponentMultiple(startIndex, dt, originalComp.getLength(), multiple, monitor);
// Adjust the selection since we added some
componentEdited();
@@ -482,11 +452,14 @@ class StructureEditorModel extends CompEditorModel {
if (!isAligned() && comp.isBitFieldComponent()) {
// insert residual undefined bytes before inserting unaligned bitfield
int lenChange = len - getLength();
- insert(endIndex, DataType.DEFAULT, 1, lenChange);
+ insert(endIndex, DataType.DEFAULT, 1, lenChange, TaskMonitor.DUMMY);
}
insert(endIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),
comp.getComment());
}
+ catch (CancelledException e) {
+ // can't happen while using a dummy monitor
+ }
catch (InvalidDataTypeException e) {
return false;
}
@@ -515,11 +488,14 @@ class StructureEditorModel extends CompEditorModel {
if (!isAligned() && comp.isBitFieldComponent()) {
// insert residual undefined bytes before inserting unaligned bitfield
int lenChange = len - getLength();
- insert(startIndex, DataType.DEFAULT, 1, lenChange);
+ insert(startIndex, DataType.DEFAULT, 1, lenChange, TaskMonitor.DUMMY);
}
insert(startIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),
comp.getComment());
}
+ catch (CancelledException e) {
+ // can't happen while using a dummy monitor
+ }
catch (InvalidDataTypeException e) {
return false;
}
@@ -551,9 +527,6 @@ class StructureEditorModel extends CompEditorModel {
return comp;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#moveUp()
- */
@Override
public boolean moveUp() throws NoSuchElementException {
if (selection.getNumRanges() != 1) {
@@ -578,9 +551,6 @@ class StructureEditorModel extends CompEditorModel {
return moved;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#moveDown()
- */
@Override
public boolean moveDown() throws NoSuchElementException {
if (selection.getNumRanges() != 1) {
@@ -642,23 +612,11 @@ class StructureEditorModel extends CompEditorModel {
return allowed;
}
- /**
- * Returns whether or not clearing the component at the specified index
- * is allowed.
- *
- * @param currentIndex index of the component in the structure
- */
@Override
public boolean isClearAllowed() {
return hasComponentSelection() && isShowingUndefinedBytes();
}
- /**
- * Returns whether or not delete of the component at the selected index
- * is allowed.
- *
- * @param currentIndex index of the component in the structure
- */
@Override
public boolean isDeleteAllowed() {
if (!hasSelection()) {
@@ -690,24 +648,6 @@ class StructureEditorModel extends CompEditorModel {
super.deleteSelectedComponents();
}
- private boolean selectionContainsBitField() {
- int startIx = selection.getFieldRange(0).getStart().getIndex().intValue();
- int endIx = selection.getFieldRange(0).getEnd().getIndex().intValue();
- for (int rowIndex = startIx; rowIndex <= endIx; rowIndex++) {
- DataTypeComponent dtc = getComponent(rowIndex);
- if (dtc != null && dtc.isBitFieldComponent()) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Returns whether or not the component at the selected index
- * is allowed to be duplicated.
- *
- * @param currentIndex index of the component in the structure
- */
@Override
public boolean isDuplicateAllowed() {
@@ -747,9 +687,6 @@ class StructureEditorModel extends CompEditorModel {
return false;
}
- /**
- * Returns whether the selected component can be unpackaged.
- */
@Override
public boolean isUnpackageAllowed() {
// set actions based on number of items selected
@@ -877,9 +814,6 @@ class StructureEditorModel extends CompEditorModel {
return true;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.datamanager.editor.CompositeEditorModel#isReplaceAllowed(int, ghidra.program.model.data.DataType)
- */
@Override
public boolean isReplaceAllowed(int rowIndex, DataType dataType) {
@@ -1009,9 +943,6 @@ class StructureEditorModel extends CompEditorModel {
return numBytesInRange;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.datamanager.editor.CompositeEditorModel#insert(int, ghidra.program.model.data.DataType, int, java.lang.String, java.lang.String)
- */
@Override
protected DataTypeComponent insert(int rowIndex, DataType dataType, int length, String name,
String comment) throws InvalidDataTypeException {
@@ -1049,14 +980,21 @@ class StructureEditorModel extends CompEditorModel {
}
@Override
- protected void insert(int rowIndex, DataType dataType, int length, int numCopies)
- throws InvalidDataTypeException {
+ protected void insert(int rowIndex, DataType dataType, int length, int numCopies,
+ TaskMonitor monitor) throws InvalidDataTypeException, CancelledException {
+
checkIsAllowableDataType(dataType, true);
int componentOrdinal = convertRowToOrdinal(rowIndex);
+ monitor.initialize(numCopies);
try {
+
for (int i = 0; i < numCopies; i++) {
+ monitor.checkCanceled();
+ monitor.setMessage("Inserting " + (i + 1) + " of " + numCopies);
viewComposite.insert(componentOrdinal, dataType, length);
+ monitor.incrementProgress(1);
}
+
if (rowIndex <= row) {
row += numCopies;
}
@@ -1123,15 +1061,12 @@ class StructureEditorModel extends CompEditorModel {
}
}
- /**
- * @see ghidra.app.plugin.contrib.data.editor.CompositeEditorModel#replaceRange(int, int, ghidra.program.model.data.DataType, int)
- */
@Override
protected boolean replaceRange(int startRowIndex, int endRowIndex, DataType datatype,
- int length) throws InvalidDataTypeException, InsufficientBytesException {
+ int length, TaskMonitor monitor)
+ throws InvalidDataTypeException, InsufficientBytesException, CancelledException {
if (startRowIndex > endRowIndex) {
- // TODO throw exception.
return false;
}
@@ -1159,11 +1094,11 @@ class StructureEditorModel extends CompEditorModel {
boolean replacedSelected = (overlap.getNumRanges() > 0);
// Remove the selected components.
- deleteComponentRange(startRowIndex, endRowIndex);
+ deleteComponentRange(startRowIndex, endRowIndex, monitor);
int beginUndefs = startRowIndex + numComps;
// Create the new components.
- insertMultiple(startRowIndex, datatype, length, numComps);
+ insertMultiple(startRowIndex, datatype, length, numComps, monitor);
int indexAfterMultiple = startRowIndex + numComps;
if (replacedSelected) {
selection.addRange(startRowIndex, indexAfterMultiple);
@@ -1171,7 +1106,7 @@ class StructureEditorModel extends CompEditorModel {
}
DataTypeComponent comp = getComponent(startRowIndex);
- // Set the fieldname and comment the same as before
+ // Set the field name and comment the same as before
try {
comp.setFieldName(fieldName);
}
@@ -1185,7 +1120,7 @@ class StructureEditorModel extends CompEditorModel {
if (remainingLength > 0 && isShowingUndefinedBytes()) {
try {
insertComponentMultiple(beginUndefs, DataType.DEFAULT, DataType.DEFAULT.getLength(),
- remainingLength);
+ remainingLength, monitor);
if (replacedSelected) {
selection.addRange(indexAfterMultiple, indexAfterMultiple + remainingLength);
}
@@ -1201,9 +1136,6 @@ class StructureEditorModel extends CompEditorModel {
return true;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.datamanager.editor.CompositeEditorModel#replaceComponents()
- */
@Override
protected void replaceOriginalComponents() {
Structure dt = (Structure) getOriginalComposite();
@@ -1216,25 +1148,6 @@ class StructureEditorModel extends CompEditorModel {
}
}
-// /**
-// * @see ghidra.app.plugin.data.editor.CompositeEditorModel#dataTypeSizeChanged(ghidra.program.model.data.EditableComposite, ghidra.program.model.data.DataType)
-// */
-// public void dataTypeSizeChanged(Composite composite, DataType dt) {
-// if (isLocked()) {
-// composite.dataTypeSizeChanged(dt);
-// }
-// else {
-// DataTypeComponent[] dtc = ((Structure)composite).getDefinedComponents();
-// for(int i=0; i < dtc.length; i++) {
-// if ((dtc[i].getDataType() == dt) && (dt.getLength() > 0)) {
-// ((Structure)composite).delete(i);
-// ((Structure)composite).insert(i, dt, dt.getLength(),
-// dtc[i].getFieldName(), dtc[i].getComment());
-// }
-// }
-// }
-// }
-
/**
*
*/
@@ -1273,7 +1186,7 @@ class StructureEditorModel extends CompEditorModel {
notifyCompositeChanged();
}
- public void adjustAlignment(PluginTool tool, int minAlignment) throws InvalidInputException {
+ public void adjustAlignment(PluginTool tool, int minAlignment) {
int currentViewAlignment = viewComposite.getMinimumAlignment();
if (currentViewAlignment == minAlignment) {
return;
@@ -1282,25 +1195,6 @@ class StructureEditorModel extends CompEditorModel {
notifyCompositeChanged();
}
-// public boolean updateAndCheckChangeState() {
-// if (originalIsChanging) {
-// return false;
-// }
-// boolean compositeChanged = super.updateAndCheckChangeState();
-// if (compositeChanged) {
-// return true;
-// }
-// Structure oldStructure = (Structure)getOriginalComposite();
-// if (oldStructure == null) {
-// hadChanges = false;
-// return hadChanges;
-// }
-// Structure viewStructure = (Structure)viewComposite;
-// hadChanges = !(viewStructure.getPackingType() == oldStructure.getPackingType()
-// && viewStructure.getMinimumAlignment() == oldStructure.getMinimumAlignment());
-// return hadChanges;
-// }
-
@Override
public void setAlignment(int minAlignment) throws InvalidInputException {
int currentViewAlignment = viewComposite.getMinimumAlignment();
@@ -1419,7 +1313,7 @@ class StructureEditorModel extends CompEditorModel {
}
}
clearSelectedComponents();
- insertMultiple(minRow, DataType.DEFAULT, 1, adjustmentBytes);
+ insertMultiple(minRow, DataType.DEFAULT, 1, adjustmentBytes, TaskMonitor.DUMMY);
replace(minRow, addedDataType, addedDataType.getLength());
}
}
@@ -1479,11 +1373,11 @@ class StructureEditorModel extends CompEditorModel {
* with the data types for its component parts. For an array replace the array with the data type
* for each array element.
* If the component isn't a structure or union then returns false.
- * @return true if unpackage succeeded.
- *
+ * @param rowIndex the row
+ * @param monitor the task monitor
* @throws UsrException if the component can't be unpackaged.
*/
- public void unpackage(int rowIndex) throws UsrException {
+ public void unpackage(int rowIndex, TaskMonitor monitor) throws UsrException {
int componentOrdinal = convertRowToOrdinal(rowIndex);
DataTypeComponent currentComp = viewComposite.getComponent(componentOrdinal);
if (currentComp == null) {
@@ -1499,11 +1393,9 @@ class StructureEditorModel extends CompEditorModel {
Structure viewStruct = (Structure) viewComposite;
- // Get the fieldname and comment before removing.
+ // Get the field name and comment before removing.
String fieldName = currentComp.getFieldName();
String comment = currentComp.getComment();
- int currentCompLen = currentComp.getLength();
-
int numComps = 0;
// This component is an array so unpackage it.
if (currentDataType instanceof Array) {
@@ -1516,7 +1408,7 @@ class StructureEditorModel extends CompEditorModel {
// Add the array's elements
try {
DataType dt = array.getDataType();
- insertMultiple(rowIndex, dt, elementLen, numComps);
+ insertMultiple(rowIndex, dt, elementLen, numComps, monitor);
}
catch (InvalidDataTypeException ie) {
// Do nothing.
@@ -1534,34 +1426,28 @@ class StructureEditorModel extends CompEditorModel {
// Remove the structure.
int currentOffset = currentComp.getOffset();
deleteComponent(rowIndex);
- try {
- // Add the structure's elements
-
- for (int i = 0; i < numComps; i++) {
- DataTypeComponent dtc = struct.getComponent(i);
- DataType dt = dtc.getDataType();
- int compLength = dtc.getLength();
- if (!isAligned()) {
- if (dtc.isBitFieldComponent()) {
- BitFieldDataType bitfield = (BitFieldDataType) dt;
- viewStruct.insertBitFieldAt(currentOffset + dtc.getOffset(),
- compLength, bitfield.getBitOffset(), bitfield.getBaseDataType(),
- bitfield.getDeclaredBitSize(), dtc.getFieldName(),
- dtc.getComment());
- }
- else {
- viewStruct.insertAtOffset(currentOffset + dtc.getOffset(), dt,
- compLength, dtc.getFieldName(), dtc.getComment());
- }
+
+ // Add the structure's elements
+ for (int i = 0; i < numComps; i++) {
+ DataTypeComponent dtc = struct.getComponent(i);
+ DataType dt = dtc.getDataType();
+ int compLength = dtc.getLength();
+ if (!isAligned()) {
+ if (dtc.isBitFieldComponent()) {
+ BitFieldDataType bitfield = (BitFieldDataType) dt;
+ viewStruct.insertBitFieldAt(currentOffset + dtc.getOffset(), compLength,
+ bitfield.getBitOffset(), bitfield.getBaseDataType(),
+ bitfield.getDeclaredBitSize(), dtc.getFieldName(),
+ dtc.getComment());
}
else {
- insert(rowIndex + i, dt, compLength, dtc.getFieldName(),
- dtc.getComment());
+ viewStruct.insertAtOffset(currentOffset + dtc.getOffset(), dt,
+ compLength, dtc.getFieldName(), dtc.getComment());
}
}
- }
- catch (OutOfMemoryError memExc) {
- throw memExc; // re-throw the exception.
+ else {
+ insert(rowIndex + i, dt, compLength, dtc.getFieldName(), dtc.getComment());
+ }
}
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.java
index 14ce95fb45..93366c7c03 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.java
@@ -40,8 +40,8 @@ import docking.widgets.fieldpanel.support.FieldSelection;
import ghidra.program.model.data.*;
import ghidra.program.model.lang.InsufficientBytesException;
-import ghidra.util.exception.InvalidInputException;
-import ghidra.util.exception.UsrException;
+import ghidra.util.exception.*;
+import ghidra.util.task.TaskMonitor;
class UnionEditorModel extends CompEditorModel {
@@ -132,12 +132,12 @@ class UnionEditorModel extends CompEditorModel {
}
/**
- * Gets called to update/validate the current editable location in the table.
+ * Gets called to update/validate the current editable location in the table
+ *
* @param value the new cell value
- * @param rowIndex the row index in the component table.
- * @param mColumn the column index for the table cell in the
- * current model.
- * @return true if the field was updated or validated successfully.
+ * @param rowIndex the row index in the component table
+ * @param columnIndex the column index for the table cell in the current model
+ * @return true if the field was updated or validated successfully
*/
@Override
protected boolean fieldEdited(Object value, int rowIndex, int columnIndex) {
@@ -170,29 +170,21 @@ class UnionEditorModel extends CompEditorModel {
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#clearComponent(int)
- */
@Override
public void clearComponent(int rowIndex) {
// clearing not supported
}
/**
- * Clear the selected components.
- *
- * @return true if cleared.
+ * Clear the selected components
*
- * @throws UsrException if clearing isn't allowed.
+ * @throws UsrException if clearing isn't allowed
*/
@Override
public void clearSelectedComponents() throws UsrException {
throw new UsrException("Clearing is not allowed.");
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.datamanager.editor.CompositeEditorModel#createArray(int)
- */
@Override
protected void createArray(int numElements)
throws InvalidDataTypeException, DataTypeConflictException, UsrException {
@@ -202,16 +194,13 @@ class UnionEditorModel extends CompEditorModel {
super.createArray(numElements);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isLockable()
- */
public boolean isLockable() {
return false;
}
- // *************************************************************
- // Begin methods for determining if a type of edit action is allowed.
- // *************************************************************
+//==================================================================================================
+// Begin methods for determining if a type of edit action is allowed.
+//==================================================================================================
@Override
public boolean isBitFieldAllowed() {
@@ -233,10 +222,7 @@ class UnionEditorModel extends CompEditorModel {
}
/**
- * Returns whether or not clearing the component at the specified index
- * is allowed.
- *
- * @param currentIndex index of the component in the union
+ * Returns whether or not clearing the component at the specified index is allowed
*/
@Override
public boolean isClearAllowed() {
@@ -244,10 +230,7 @@ class UnionEditorModel extends CompEditorModel {
}
/**
- * Returns whether or not delete of the component at the selected index
- * is allowed.
- *
- * @param currentIndex index of the component in the union
+ * Returns whether or not delete of the component at the selected index is allowed
*/
@Override
public boolean isDeleteAllowed() {
@@ -255,10 +238,7 @@ class UnionEditorModel extends CompEditorModel {
}
/**
- * Returns whether or not the component at the selected index
- * is allowed to be duplicated.
- *
- * @param currentIndex index of the component in the union
+ * Returns whether or not the component at the selected index is allowed to be duplicated
*/
@Override
public boolean isDuplicateAllowed() {
@@ -307,9 +287,6 @@ class UnionEditorModel extends CompEditorModel {
return rowIndex <= viewComposite.getNumComponents();
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.datamanager.editor.CompositeEditorModel#isReplaceAllowed(int, ghidra.program.model.data.DataType)
- */
@Override
public boolean isReplaceAllowed(int currentIndex, DataType dataType) {
try {
@@ -324,9 +301,9 @@ class UnionEditorModel extends CompEditorModel {
return true;
}
- // *************************************************************
- // End of methods for determining if a type of edit action is allowed.
- // *************************************************************
+//==================================================================================================
+// End of methods for determining if a type of edit action is allowed.
+//==================================================================================================
/**
* Gets the maximum number of bytes available for a data type that is added at the indicated
@@ -345,7 +322,7 @@ class UnionEditorModel extends CompEditorModel {
* will replace the current data type at the indicated index.
* If there isn't a component with the indicated index, the max length
* will be determined by the lock mode.
- * Note: This method doesn't care whther there is a selection or not.
+ * Note: This method doesn't care whether there is a selection or not.
*
* @param currentIndex index of the component in the union.
* @return the maximum number of bytes that can be replaced
@@ -397,9 +374,6 @@ class UnionEditorModel extends CompEditorModel {
return super.insert(rowIndex, dt, dtLength);
}
- /**
- * @see ghidra.app.plugin.contrib.data.editor.CompositeEditorModel#insert(int, ghidra.program.model.data.DataType, int, java.lang.String, java.lang.String)
- */
@Override
public DataTypeComponent insert(int rowIndex, DataType dataType, int length, String name,
String comment) throws InvalidDataTypeException {
@@ -420,16 +394,17 @@ class UnionEditorModel extends CompEditorModel {
}
@Override
- public void insert(int rowIndex, DataType dataType, int length, int numCopies)
- throws InvalidDataTypeException {
- for (int ii = 0; ii < numCopies; ++ii) {
- insert(rowIndex + ii, dataType, length, null, null);
+ public void insert(int rowIndex, DataType dataType, int length, int numCopies,
+ TaskMonitor monitor) throws InvalidDataTypeException, CancelledException {
+
+ monitor.initialize(numCopies);
+ for (int i = 0; i < numCopies; i++) {
+ monitor.checkCanceled();
+ insert(rowIndex + i, dataType, length, null, null);
+ monitor.incrementProgress(1);
}
}
- /**
- * @see ghidra.app.plugin.core.compositeeditor.CompEditorModel#replace(int, ghidra.program.model.data.DataType, int, java.lang.String, java.lang.String)
- */
@Override
public DataTypeComponent replace(int rowIndex, DataType dataType, int length, String name,
String comment) throws InvalidDataTypeException {
@@ -451,12 +426,10 @@ class UnionEditorModel extends CompEditorModel {
}
}
- /**
- * @see ghidra.app.plugin.contrib.data.editor.CompositeEditorModel#replaceRange(int, int, ghidra.program.model.data.DataType, int)
- */
@Override
protected boolean replaceRange(int startRowIndex, int endRowIndex, DataType datatype,
- int length) throws InvalidDataTypeException, InsufficientBytesException {
+ int length, TaskMonitor monitor)
+ throws InvalidDataTypeException, InsufficientBytesException, CancelledException {
if (length <= 0) {
throw new InvalidDataTypeException(
@@ -484,9 +457,11 @@ class UnionEditorModel extends CompEditorModel {
FieldSelection overlap = new FieldSelection();
overlap.addRange(startRowIndex, endRowIndex + 1);
overlap.intersect(selection);
- boolean replacedSelected = (overlap.getNumRanges() > 0);
+
// Union just replaces entire selection range with single instance of new component.
- deleteComponentRange(startRowIndex, endRowIndex);
+ deleteComponentRange(startRowIndex, endRowIndex, monitor);
+
+ boolean replacedSelected = (overlap.getNumRanges() > 0);
insert(startRowIndex, datatype, length, null, null);
if (replacedSelected) {
selection.addRange(startRowIndex, startRowIndex + 1);
@@ -495,25 +470,16 @@ class UnionEditorModel extends CompEditorModel {
return true;
}
- /**
- * @see ghidra.app.plugin.contrib.data.editor.CompositeEditorModel#replaceComponents()
- */
@Override
public void replaceOriginalComponents() {
((Union) getOriginalComposite()).replaceWith(viewComposite);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.datamanager.editor.CompositeEditorModel#clearComponents(int[])
- */
@Override
public void clearComponents(int[] rows) throws UsrException {
throw new UsrException("Can't clear components in a union.");
}
- /**
- *
- */
@Override
void removeDtFromComponents(Composite comp) {
DataType newDt = viewDTM.getDataType(comp.getDataTypePath());
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnpackageAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnpackageAction.java
index e6da64b862..d3b42829e0 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnpackageAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnpackageAction.java
@@ -23,7 +23,10 @@ import javax.swing.KeyStroke;
import docking.ActionContext;
import docking.action.KeyBindingData;
import docking.widgets.OptionDialog;
+import ghidra.util.exception.CancelledException;
import ghidra.util.exception.UsrException;
+import ghidra.util.task.TaskLauncher;
+import ghidra.util.task.TaskMonitor;
import resources.ResourceManager;
/**
@@ -63,18 +66,26 @@ public class UnpackageAction extends CompositeEditorTableAction {
return;
}
}
+
+ TaskLauncher.launchModal("Unpackaging Component",
+ monitor -> doUnpackage(currentRowIndex, monitor));
+
+ requestTableFocus();
+ }
+
+ private void doUnpackage(int row, TaskMonitor monitor) {
try {
- ((StructureEditorModel) model).unpackage(currentRowIndex);
+ ((StructureEditorModel) model).unpackage(row, monitor);
+ }
+ catch (CancelledException e) {
+ // user cancelled
}
catch (UsrException e1) {
model.setStatus(e1.getMessage(), true);
}
- requestTableFocus();
+ model.fireTableDataChanged();
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.datamanager.editor.CompositeEditorAction#adjustEnablement()
- */
@Override
public void adjustEnablement() {
setEnabled(model.isUnpackageAllowed());
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/stackeditor/StackEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/stackeditor/StackEditorModel.java
index 82cc2f6a48..1cd7b7f990 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/stackeditor/StackEditorModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/stackeditor/StackEditorModel.java
@@ -45,6 +45,7 @@ import ghidra.program.model.symbol.SourceType;
import ghidra.program.model.symbol.SymbolUtilities;
import ghidra.util.*;
import ghidra.util.exception.*;
+import ghidra.util.task.TaskMonitor;
class StackEditorModel extends CompositeEditorModel {
@@ -59,7 +60,6 @@ class StackEditorModel extends CompositeEditorModel {
private static final int MAX_PARAM_SIZE = Integer.MAX_VALUE;
private StackFrame originalStack;
- private boolean hasCustomParameterStorage;
private DataTypeManager dtm;
private boolean stackChangedExternally;
@@ -86,7 +86,6 @@ class StackEditorModel extends CompositeEditorModel {
void load(Function function) {
originalStack = function.getStackFrame();
- hasCustomParameterStorage = function.hasCustomVariableStorage();
StackFrameDataType stackFrameDataType = new StackFrameDataType(originalStack, dtm);
stackFrameDataType.setCategoryPath(dtm.getRootCategory().getCategoryPath());
load(stackFrameDataType, false);
@@ -102,9 +101,6 @@ class StackEditorModel extends CompositeEditorModel {
return (StackFrameDataType) viewComposite;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeEditorModel#checkChanges()
- */
@Override
public boolean updateAndCheckChangeState() {
if (originalIsChanging) {
@@ -169,9 +165,6 @@ class StackEditorModel extends CompositeEditorModel {
return COMMENT;
}
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#getValueAt(int, int)
- */
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if ((viewComposite == null) || (rowIndex >= viewComposite.getNumComponents()) ||
@@ -266,12 +259,12 @@ class StackEditorModel extends CompositeEditorModel {
}
/**
- * Gets called to update/validate the current editable location in the table.
+ * Gets called to update/validate the current editable location in the table
+ *
* @param value the new cell value
- * @param rowIndex the row index in the component table.
- * @param mColumn the column index for the table cell in the
- * current model.
- * @return true if the field was updated or validated successfully.
+ * @param rowIndex the row index in the component table
+ * @param columnIndex the column index for the table cell in the current model
+ * @return true if the field was updated or validated successfully
*/
@Override
protected boolean fieldEdited(Object value, int rowIndex, int columnIndex) {
@@ -311,10 +304,6 @@ class StackEditorModel extends CompositeEditorModel {
}
}
- /**
- * @param index the component index
- * @param offset
- */
@Override
public void validateComponentOffset(int index, String offset) throws UsrException {
try {
@@ -376,12 +365,6 @@ class StackEditorModel extends CompositeEditorModel {
}
}
- /**
- *
- * @param rowIndex
- * @param value
- * @throws UsrException
- */
public void setComponentOffset(int rowIndex, String value) throws UsrException {
DataTypeComponent element = viewComposite.getComponent(rowIndex);
int offset = element.getOffset();
@@ -395,9 +378,6 @@ class StackEditorModel extends CompositeEditorModel {
notifyCompositeChanged();
}
- /* (non-Javadoc)
- * @see javax.swing.table.TableModel#isCellEditable(int, int)
- */
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
StackFrameDataType stackDt = (StackFrameDataType) viewComposite;
@@ -451,9 +431,6 @@ class StackEditorModel extends CompositeEditorModel {
((StackFrameDataType) viewComposite).clearComponent(ordinal);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#clearSelectedComponents()
- */
@Override
public void clearSelectedComponents() throws UsrException {
OffsetPairs offsetSelection = getRelOffsetSelection();
@@ -598,35 +575,22 @@ class StackEditorModel extends CompositeEditorModel {
return ((StackFrameDataType) viewComposite).getReturnAddressOffset();
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#getMaxAddLength(int)
- */
@Override
public int getMaxAddLength(int index) {
return getMaxReplaceLength(index);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#getMaxReplaceLength(int)
- */
@Override
public int getMaxReplaceLength(int currentIndex) {
int offset = viewComposite.getComponent(currentIndex).getOffset();
return ((StackFrameDataType) viewComposite).getMaxLength(offset);
}
- /**
- * @see ghidra.app.plugin.core.compositeeditor.EditorModel#getMaxDuplicates(int)
- */
@Override
public int getMaxDuplicates(int rowIndex) {
return 0;
}
- /**
- * @param dataType
- * @return
- */
@Override
public boolean isAddAllowed(DataType dataType) {
if (isSingleRowSelection()) {
@@ -796,9 +760,6 @@ class StackEditorModel extends CompositeEditorModel {
}
}
- /**
- * @param dataType
- */
private void replaceComponents(DataType oldDataType, DataType newDataType) {
StackFrameDataType stackDt = (StackFrameDataType) viewComposite;
DataTypeComponent[] comps = stackDt.getDefinedComponents();
@@ -826,9 +787,6 @@ class StackEditorModel extends CompositeEditorModel {
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#setComponentDataTypeInstance(int, ghidra.program.model.data.DataTypeInstance)
- */
@Override
public void setComponentDataTypeInstance(int index, DataTypeInstance dti) throws UsrException {
DataType dt = dti.getDataType();
@@ -914,16 +872,13 @@ class StackEditorModel extends CompositeEditorModel {
return replace(index, dt);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#add(int, ghidra.program.model.data.DataType, java.awt.Component)
- */
@Override
public DataTypeComponent add(int index, DataType dt, int dtLength) throws UsrException {
return replace(index, dt, dtLength);
}
private Variable getVariableContaining(int offset, List<Variable> sortedVariables) {
- Object key = new Integer(offset);
+ Object key = offset;
int index = Collections.binarySearch(sortedVariables, key, StackVariableComparator.get());
if (index >= 0) {
return sortedVariables.get(index);
@@ -1107,57 +1062,37 @@ class StackEditorModel extends CompositeEditorModel {
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#duplicateMultiple(int, int)
- */
@Override
- public void duplicateMultiple(int index, int multiple) throws UsrException {
+ public void duplicateMultiple(int index, int multiple, TaskMonitor monitor)
+ throws UsrException {
// do nothing
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#insert(ghidra.program.model.data.DataType)
- */
@Override
public DataTypeComponent insert(DataType dataType) throws UsrException {
return null;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#insert(int, ghidra.program.model.data.DataType)
- */
@Override
public DataTypeComponent insert(int index, DataType dataType) throws UsrException {
return null;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#insert(int, ghidra.program.model.data.DataType)
- */
@Override
public DataTypeComponent insert(int index, DataType dt, int dtLength) throws UsrException {
return null;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#moveUp()
- */
@Override
public boolean moveUp() {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#moveDown()
- */
@Override
public boolean moveDown() {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#replace(ghidra.program.model.data.DataType, java.awt.Component)
- */
public DataTypeComponent replace(DataType dataType) throws UsrException {
int rowIndex = getMinIndexSelected();
if (rowIndex < 0) {
@@ -1179,9 +1114,6 @@ class StackEditorModel extends CompositeEditorModel {
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#replace(int, ghidra.program.model.data.DataTypeInstance)
- */
@Override
public DataTypeComponent replace(int index, DataType dt, int dtLength) throws UsrException {
OffsetPairs offsetSelection = getRelOffsetSelection();
@@ -1197,9 +1129,6 @@ class StackEditorModel extends CompositeEditorModel {
return getComponent(index);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#getMaxElements()
- */
@Override
public int getMaxElements() {
if (getNumSelectedComponentRows() != 1) {
@@ -1270,15 +1199,16 @@ class StackEditorModel extends CompositeEditorModel {
if (dataTypeManager != originalDataTypeManager) {
return;
}
- DataTypePath originalDataTypePath = getOriginalDataTypePath();
- if (originalDataTypeManager == null || originalDataTypePath == null) {
+ DataTypePath originalPath = getOriginalDataTypePath();
+ if (originalDataTypeManager == null || originalPath == null) {
return;
}
- if (!oldPath.equals(originalDataTypePath)) {
+ if (!oldPath.equals(originalPath)) {
return;
}
- // Don't try to actually rename, since we shouldn't get name change on a fabricated stack data type.
+ // Don't try to actually rename, since we shouldn't get name change on a
+ // fabricated stack data type.
OffsetPairs offsetSelection = getRelOffsetSelection();
fireTableDataChanged();
componentDataChanged();
@@ -1299,36 +1229,24 @@ class StackEditorModel extends CompositeEditorModel {
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeViewerModel#getOriginalComposite()
- */
@Override
protected Composite getOriginalComposite() {
// This is to allow the stack editor panel to have access.
return super.getOriginalComposite();
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeViewerModel#getOriginalDataTypeManager()
- */
@Override
protected DataTypeManager getOriginalDataTypeManager() {
// This is to allow the stack editor panel to have access.
return super.getOriginalDataTypeManager();
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeViewerModel#fixupOriginalPath(ghidra.program.model.data.Composite)
- */
@Override
protected void fixupOriginalPath(Composite composite) {
// This is to allow the stack editor panel to have access.
super.fixupOriginalPath(composite);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeViewerModel#getCompositeID()
- */
@Override
protected long getCompositeID() {
// This is to allow the stack editor panel to have access.
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java
index a5c7460c24..b8a788b80b 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java
@@ -53,6 +53,7 @@ import ghidra.program.model.listing.Program;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
import ghidra.util.Msg;
+import utilities.util.reflection.ReflectionUtilities;
public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegrationTest {
protected String languageName;
@@ -333,7 +334,8 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
assertNotNull(action);
boolean isEnabled = runSwing(() -> action.isEnabled());
if (!isEnabled) {
- Msg.debug(this, "Calling actionPerformed() on a disabled action: " + action.getName());
+ Msg.debug(this, "Calling actionPerformed() on a disabled action: " + action.getName(),
+ ReflectionUtilities.createJavaFilteredThrowable());
}
runSwing(() -> action.actionPerformed(new ActionContext()), false);
waitForSwing();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java
index b2ddbda7f1..4c3b28b7d5 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java
@@ -252,6 +252,7 @@ public class StructureEditorLockedActions2Test extends AbstractStructureEditorLo
okInput(dialog, 2);
dialog = null;
waitUntilDialogProviderGone(NumberInputDialog.class, 2000);
+ waitForBusyTool(tool); // the 'Duplicate Multiple' action uses a task
assertEquals(num - 2, getModel().getNumComponents());
checkSelection(new int[] { 2 });
@@ -263,10 +264,6 @@ public class StructureEditorLockedActions2Test extends AbstractStructureEditorLo
assertEquals("comment 2", getComment(2));
}
- /**
- * Edit an existing aligned structure and create a structure from a selection. Use the default name.
- * @throws Exception
- */
@Test
public void testExistingAlignedDtEditInternalStructureOnSelectionDefaultName()
throws Exception {
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions3Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions3Test.java
index d0f4d20007..57128ade09 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions3Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions3Test.java
@@ -74,11 +74,12 @@ public class StructureEditorUnlockedActions3Test
DataType dt1 = getDataType(1);
invoke(duplicateMultipleAction);
- dialog = env.waitForDialogComponent(NumberInputDialog.class, 1000);
+ dialog = waitForDialogComponent(NumberInputDialog.class);
assertNotNull(dialog);
okInput(dialog, 2);
dialog = null;
waitUntilDialogProviderGone(NumberInputDialog.class, 2000);
+ waitForBusyTool(tool); // the 'Duplicate Multiple' action uses a task
num += 2;
assertEquals(num, model.getNumComponents());
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java
index 0d42d6713c..6a3438b8d5 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java
@@ -144,9 +144,7 @@ public class StructureEditorUnlockedActions4Test
// Can't duplicate blank line
listener.clearStatus();
setSelection(new int[] { model.getNumComponents() });
- invoke(duplicateAction);
- assertEquals(num, model.getNumComponents());
- assertEquals(len, model.getLength());
+ assertFalse(runSwing(() -> duplicateAction.isEnabled()));
}
@Test
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java
index 2df9cf8966..5b1d4d4a81 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java
@@ -589,9 +589,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
// Can't duplicate blank line
listener.clearStatus();
setSelection(new int[] { model.getNumComponents() });
- invoke(duplicateAction);
- assertEquals(num, model.getNumComponents());
- assertEquals(len, model.getLength());
+ assertFalse(runSwing(() -> duplicateAction.isEnabled()));
}
@Test