Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/GP-1631_ghidravore_datatype_maan…
Browse files Browse the repository at this point in the history
…ger_service_get_selected_datatypes--SQUASHED'
  • Loading branch information
ghidra1 committed Jan 6, 2022
2 parents f3c65d1 + 883419c commit 56a8346
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ public void setDataTypeSelected(DataType dataType) {
throw new UnsupportedOperationException();
}

@Override
public List<DataType> getSelectedDatatypes() {
throw new UnsupportedOperationException();
}

@Override
public void setRecentlyUsed(DataType dt) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,14 @@ public void setDataTypeSelected(DataType dataType) {
}
}

@Override
public List<DataType> getSelectedDatatypes() {
if (provider.isVisible()) {
return provider.getSelectedDataTypes();
}
return Collections.emptyList();
}

@Override
public void setRecentlyUsed(DataType dt) {
dataTypeManagerHandler.setRecentlyUsedDataType(dt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,25 @@ public void setDataTypeSelected(DataType dataType) {
contextChanged();
}

/**
* Returns a list of all the data types selected in the data types tree
* @return a list of all the data types selected in the data types tree
*/
public List<DataType> getSelectedDataTypes() {
List<DataType> selectedDataTypes = new ArrayList<>();
DataTypeArchiveGTree gTree = getGTree();
for (TreePath path : gTree.getSelectionPaths()) {
Object node = path.getLastPathComponent();
if (node instanceof DataTypeNode) {
DataType dataType = ((DataTypeNode) node).getDataType();
if (dataType != null) {
selectedDataTypes.add(dataType);
}
}
}
return selectedDataTypes;
}

// this is a callback from the action--we need this to prevent callbacks, as the other
// version of this method will try to get the method, which will lazily created it, which
// will trigger a callback...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ public Archive openArchive(File file, boolean acquireWriteLock)
*/
public void setDataTypeSelected(DataType dataType);

/**
* Returns the list of data types that are currently selected in the data types tree
* @return the list of data types that are currently selected in the data types tree
*/
public List<DataType> getSelectedDatatypes();

/**
* Shows the user a dialog that allows them to choose a data type from a tree of all available
* data types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import ghidra.app.plugin.core.datamgr.tree.*;
import ghidra.app.plugin.core.function.AbstractEditFunctionSignatureDialog;
import ghidra.app.plugin.core.programtree.ProgramTreePlugin;
import ghidra.app.services.DataTypeManagerService;
import ghidra.app.services.ProgramManager;
import ghidra.app.util.datatype.DataTypeSelectionEditor;
import ghidra.framework.options.ToolOptions;
Expand Down Expand Up @@ -900,9 +901,40 @@ public void testAction_FindStructureBySize_Ranage() {
assertMatchingStructures(resultsProvider, "Structure_0x10", "Structure_0x20");
}

@Test
public void testGetSelectedDatatypesFromService() {
DataTypeManagerService dataTypeManagerService =
tool.getService(DataTypeManagerService.class);

assertEquals(0, dataTypeManagerService.getSelectedDatatypes().size());

CategoryPath path = new CategoryPath("/MISC");
DataType dt1 = program.getDataTypeManager().getDataType(path, "ArrayStruct");
DataType dt2 = program.getDataTypeManager().getDataType(path, "ArrayUnion");

selectDataTypes(dt1, dt2);

List<DataType> selectedDatatypes = dataTypeManagerService.getSelectedDatatypes();
assertEquals(2, selectedDatatypes.size());
assertTrue(selectedDatatypes.contains(dt1));
assertTrue(selectedDatatypes.contains(dt2));
}

//==================================================================================================
// Private methods
//==================================================================================================
private void selectDataTypes(DataType dt1, DataType dt2) {
String catName1 = dt1.getCategoryPath().getName(); // assumes path is only 1 level
CategoryNode cat1 = (CategoryNode) programNode.getChild(catName1);
DataTypeNode node1 = cat1.getNode(dt1);

String catName2 = dt2.getCategoryPath().getName(); // assumes path is only 1 level
CategoryNode cat2 = (CategoryNode) programNode.getChild(catName2);
DataTypeNode node2 = cat2.getNode(dt2);

tree.setSelectedNodes(node1, node2);
waitForTree(tree);
}

private void createStructureWithOffset_0x4() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public void setDataTypeSelected(DataType dataType) {
throw new UnsupportedOperationException();
}

@Override
public List<DataType> getSelectedDatatypes() {
throw new UnsupportedOperationException();
}

@Override
public DataType getDataType(TreePath selectedPath) {
throw new UnsupportedOperationException();
Expand Down

0 comments on commit 56a8346

Please sign in to comment.