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,16 +936,18 @@ public abstract class CompEditorModel extends CompositeEditorModel {
endRowIndex <= 0 || endRowIndex >= numComps) { endRowIndex <= 0 || endRowIndex >= numComps) {
return false; return false;
} }
DataTypeComponent comp = getComponent(startRowIndex - 1); return viewDTM.withTransaction("Shift Up", () -> {
deleteComponent(startRowIndex - 1); DataTypeComponent comp = getComponent(startRowIndex - 1);
try { deleteComponent(startRowIndex - 1);
insert(endRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(), try {
comp.getComment()); insert(endRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),
} comp.getComment());
catch (InvalidDataTypeException e) { }
return false; catch (InvalidDataTypeException e) {
} return false;
return true; }
return true;
});
} }
/** /**
@ -962,16 +964,18 @@ public abstract class CompEditorModel extends CompositeEditorModel {
endRowIndex < 0 || endRowIndex >= numComps - 1) { endRowIndex < 0 || endRowIndex >= numComps - 1) {
return false; return false;
} }
DataTypeComponent comp = getComponent(endRowIndex + 1); return viewDTM.withTransaction("Shift Down", () -> {
deleteComponent(endRowIndex + 1); DataTypeComponent comp = getComponent(endRowIndex + 1);
try { deleteComponent(endRowIndex + 1);
insert(startRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(), try {
comp.getComment()); insert(startRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),
} comp.getComment());
catch (InvalidDataTypeException e) { }
return false; catch (InvalidDataTypeException e) {
} return false;
return true; }
return true;
});
} }
@Override @Override
@ -1066,6 +1070,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {
replace(rowIndex, array, array.getLength()); // Can throw UsrException. 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 // 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 @Override
public boolean isShowingUndefinedBytes() { public boolean isShowingUndefinedBytes() {
return !viewComposite.isPackingEnabled(); return !viewComposite.isPackingEnabled();

View file

@ -540,54 +540,21 @@ class UnionEditorModel extends CompEditorModel {
throw new UnsupportedOperationException("Can't clear components in a union."); 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 @Override
protected boolean isAtEnd(int rowIndex) { protected boolean isAtEnd(int rowIndex) {
// Not applicable to union
return false; 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 @Override
protected int consumeByComponent(int rowIndex) { protected int consumeByComponent(int rowIndex) {
// Not applicable to union
return 0; return 0;
} }
@Override @Override
public boolean isShowingUndefinedBytes() { public boolean isShowingUndefinedBytes() {
// Not applicable to union
return false; return false;
} }