GP-5580 Corrected Union editor issue with shift up/down and create

array.  Removed obsolete method within editor model.
This commit is contained in:
ghidra1 2025-04-09 19:14:13 -04:00
parent 2c5669dbd0
commit 7c67a103cd
3 changed files with 28 additions and 92 deletions

View file

@ -936,6 +936,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
endRowIndex <= 0 || endRowIndex >= numComps) {
return false;
}
return viewDTM.withTransaction("Shift Up", () -> {
DataTypeComponent comp = getComponent(startRowIndex - 1);
deleteComponent(startRowIndex - 1);
try {
@ -946,6 +947,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return false;
}
return true;
});
}
/**
@ -962,6 +964,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
endRowIndex < 0 || endRowIndex >= numComps - 1) {
return false;
}
return viewDTM.withTransaction("Shift Down", () -> {
DataTypeComponent comp = getComponent(endRowIndex + 1);
deleteComponent(endRowIndex + 1);
try {
@ -972,6 +975,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
return false;
}
return true;
});
}
@Override
@ -1066,6 +1070,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
replace(rowIndex, array, array.getLength()); // Can throw UsrException.
}
});
componentEdited();
}
/**
@ -1629,15 +1634,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
}
/**
* Removes the indicated data type from any components to prevent a cycle
* being created by this component being updated. Structures will actually
* clear any components containing the indicated data type.
* Unions will delete their components that contain the data type.
* @param comp the composite data type that contains the data type being edited.
*/
abstract void removeDtFromComponents(Composite comp);
//==================================================================================================
// End of Override CompositeViewerModel CategoryChangeListener methods
//==================================================================================================

View file

@ -1062,33 +1062,6 @@ class StructureEditorModel extends CompEditorModel {
}
}
@Override
void removeDtFromComponents(Composite comp) {
DataType newDt = viewDTM.getDataType(comp.getDataTypePath());
if (newDt == null) {
return;
}
boolean clearedComponents = viewDTM.withTransaction("Remove Components", () -> {
boolean cleared = false;
int num = getNumComponents();
for (int i = num - 1; i >= 0; i--) {
DataTypeComponent dtc = getComponent(i);
DataType dt = dtc.getDataType();
if (dt instanceof Composite) {
Composite dtcComp = (Composite) dt;
if (dtcComp.isPartOf(newDt)) {
clearComponents(new int[] { i });
cleared = true;
}
}
}
return cleared;
});
if (clearedComponents) {
setStatus("Components containing " + comp.getDisplayName() + " were cleared.", true);
}
}
@Override
public boolean isShowingUndefinedBytes() {
return !viewComposite.isPackingEnabled();

View file

@ -540,54 +540,21 @@ class UnionEditorModel extends CompEditorModel {
throw new UnsupportedOperationException("Can't clear components in a union.");
}
@Override
void removeDtFromComponents(Composite comp) {
DataTypePath path = comp.getDataTypePath();
DataType newDt = viewDTM.getDataType(path);
if (newDt == null) {
return;
}
viewDTM.withTransaction("Remove use of " + path, () -> {
int num = getNumComponents();
for (int i = num - 1; i >= 0; i--) {
DataTypeComponent dtc = getComponent(i);
DataType dt = dtc.getDataType();
if (dt instanceof Composite) {
Composite dtcComp = (Composite) dt;
if (dtcComp.isPartOf(newDt)) {
deleteComponent(i);
String msg =
"Components containing " + comp.getDisplayName() + " were removed.";
setStatus(msg, true);
}
}
}
});
}
/**
* ?????
*
* @param rowIndex the index of the row
*/
@Override
protected boolean isAtEnd(int rowIndex) {
// Not applicable to union
return false;
}
/**
* Cause the component at the specified index to consume undefined bytes
* that follow it.
* Note: this method adjusts the selection.
* @return the number of Undefined bytes consumed.
*/
@Override
protected int consumeByComponent(int rowIndex) {
// Not applicable to union
return 0;
}
@Override
public boolean isShowingUndefinedBytes() {
// Not applicable to union
return false;
}