Skip to content

Commit 7c67a10

Browse files
committed
GP-5580 Corrected Union editor issue with shift up/down and create
array. Removed obsolete method within editor model.
1 parent 2c5669d commit 7c67a10

File tree

3 files changed

+28
-92
lines changed

3 files changed

+28
-92
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -936,16 +936,18 @@ private boolean shiftComponentsUp(int startRowIndex, int endRowIndex) {
936936
endRowIndex <= 0 || endRowIndex >= numComps) {
937937
return false;
938938
}
939-
DataTypeComponent comp = getComponent(startRowIndex - 1);
940-
deleteComponent(startRowIndex - 1);
941-
try {
942-
insert(endRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),
943-
comp.getComment());
944-
}
945-
catch (InvalidDataTypeException e) {
946-
return false;
947-
}
948-
return true;
939+
return viewDTM.withTransaction("Shift Up", () -> {
940+
DataTypeComponent comp = getComponent(startRowIndex - 1);
941+
deleteComponent(startRowIndex - 1);
942+
try {
943+
insert(endRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),
944+
comp.getComment());
945+
}
946+
catch (InvalidDataTypeException e) {
947+
return false;
948+
}
949+
return true;
950+
});
949951
}
950952

951953
/**
@@ -962,16 +964,18 @@ private boolean shiftComponentsDown(int startRowIndex, int endRowIndex) {
962964
endRowIndex < 0 || endRowIndex >= numComps - 1) {
963965
return false;
964966
}
965-
DataTypeComponent comp = getComponent(endRowIndex + 1);
966-
deleteComponent(endRowIndex + 1);
967-
try {
968-
insert(startRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),
969-
comp.getComment());
970-
}
971-
catch (InvalidDataTypeException e) {
972-
return false;
973-
}
974-
return true;
967+
return viewDTM.withTransaction("Shift Down", () -> {
968+
DataTypeComponent comp = getComponent(endRowIndex + 1);
969+
deleteComponent(endRowIndex + 1);
970+
try {
971+
insert(startRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),
972+
comp.getComment());
973+
}
974+
catch (InvalidDataTypeException e) {
975+
return false;
976+
}
977+
return true;
978+
});
975979
}
976980

977981
@Override
@@ -1066,6 +1070,7 @@ protected void createArray(int numElements) throws InvalidDataTypeException, Usr
10661070
replace(rowIndex, array, array.getLength()); // Can throw UsrException.
10671071
}
10681072
});
1073+
componentEdited();
10691074
}
10701075

10711076
/**
@@ -1629,15 +1634,6 @@ public void dataTypeReplaced(DataTypeManager dtm, DataTypePath oldPath, DataType
16291634
}
16301635
}
16311636

1632-
/**
1633-
* Removes the indicated data type from any components to prevent a cycle
1634-
* being created by this component being updated. Structures will actually
1635-
* clear any components containing the indicated data type.
1636-
* Unions will delete their components that contain the data type.
1637-
* @param comp the composite data type that contains the data type being edited.
1638-
*/
1639-
abstract void removeDtFromComponents(Composite comp);
1640-
16411637
//==================================================================================================
16421638
// End of Override CompositeViewerModel CategoryChangeListener methods
16431639
//==================================================================================================

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,33 +1062,6 @@ protected void replaceOriginalComponents() {
10621062
}
10631063
}
10641064

1065-
@Override
1066-
void removeDtFromComponents(Composite comp) {
1067-
DataType newDt = viewDTM.getDataType(comp.getDataTypePath());
1068-
if (newDt == null) {
1069-
return;
1070-
}
1071-
boolean clearedComponents = viewDTM.withTransaction("Remove Components", () -> {
1072-
boolean cleared = false;
1073-
int num = getNumComponents();
1074-
for (int i = num - 1; i >= 0; i--) {
1075-
DataTypeComponent dtc = getComponent(i);
1076-
DataType dt = dtc.getDataType();
1077-
if (dt instanceof Composite) {
1078-
Composite dtcComp = (Composite) dt;
1079-
if (dtcComp.isPartOf(newDt)) {
1080-
clearComponents(new int[] { i });
1081-
cleared = true;
1082-
}
1083-
}
1084-
}
1085-
return cleared;
1086-
});
1087-
if (clearedComponents) {
1088-
setStatus("Components containing " + comp.getDisplayName() + " were cleared.", true);
1089-
}
1090-
}
1091-
10921065
@Override
10931066
public boolean isShowingUndefinedBytes() {
10941067
return !viewComposite.isPackingEnabled();

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.java

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -540,54 +540,21 @@ public void clearComponents(int[] rows) {
540540
throw new UnsupportedOperationException("Can't clear components in a union.");
541541
}
542542

543-
@Override
544-
void removeDtFromComponents(Composite comp) {
545-
DataTypePath path = comp.getDataTypePath();
546-
DataType newDt = viewDTM.getDataType(path);
547-
if (newDt == null) {
548-
return;
549-
}
550-
viewDTM.withTransaction("Remove use of " + path, () -> {
551-
int num = getNumComponents();
552-
for (int i = num - 1; i >= 0; i--) {
553-
DataTypeComponent dtc = getComponent(i);
554-
DataType dt = dtc.getDataType();
555-
if (dt instanceof Composite) {
556-
Composite dtcComp = (Composite) dt;
557-
if (dtcComp.isPartOf(newDt)) {
558-
deleteComponent(i);
559-
String msg =
560-
"Components containing " + comp.getDisplayName() + " were removed.";
561-
setStatus(msg, true);
562-
}
563-
}
564-
}
565-
});
566-
}
567-
568-
/**
569-
* ?????
570-
*
571-
* @param rowIndex the index of the row
572-
*/
573543
@Override
574544
protected boolean isAtEnd(int rowIndex) {
545+
// Not applicable to union
575546
return false;
576547
}
577548

578-
/**
579-
* Cause the component at the specified index to consume undefined bytes
580-
* that follow it.
581-
* Note: this method adjusts the selection.
582-
* @return the number of Undefined bytes consumed.
583-
*/
584549
@Override
585550
protected int consumeByComponent(int rowIndex) {
551+
// Not applicable to union
586552
return 0;
587553
}
588554

589555
@Override
590556
public boolean isShowingUndefinedBytes() {
557+
// Not applicable to union
591558
return false;
592559
}
593560

0 commit comments

Comments
 (0)