Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5317 - GTree - Added an action to allow users to copy the selected paths and preserve the indentation. Moved some help to the Docking module.

dragonmacherb04e6e58b626
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeProvider.java
index 7ca3d922f5..7bf4f44851 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeProvider.java
@@ -873,16 +873,25 @@ public class CallTreeProvider extends ComponentProviderAdapter {
private GTree createTree() {
GTree tree = new GTree(new EmptyRootNode()) {
+
@Override
- protected boolean supportsPopupActions() {
- // The base tree adds collapse/ expand actions, which we already provide, so signal
- // that we do not want those actions.
- return false;
+ protected boolean isAddToPopup(DockingAction action) {
+
+ String name = action.getName();
+ switch (name) {
+ case "Tree Expand All":
+ case "Tree Expand Node":
+ case "Tree Collapse Node":
+ // case "Tree Collapse All": // this action seems ok
+ return false;
+ default:
+ return true;
+ }
+
}
};
tree.setPaintHandlesForLeafNodes(false);
tree.setDoubleClickExpansionEnabled(false); // reserve double-click for navigation
-// tree.setFilterVisible(false);
return tree;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/DataTypeArchiveGTree.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/DataTypeArchiveGTree.java
index 154ff3f00d..6e22637997 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/DataTypeArchiveGTree.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/tree/DataTypeArchiveGTree.java
@@ -24,6 +24,7 @@ import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.tree.TreePath;
+import docking.action.DockingAction;
import docking.widgets.tree.*;
import docking.widgets.tree.internal.DefaultGTreeDataTransformer;
import docking.widgets.tree.support.GTreeRenderer;
@@ -122,10 +123,18 @@ public class DataTypeArchiveGTree extends GTree {
}
@Override
- protected boolean supportsPopupActions() {
- // The base tree adds collapse/ expand actions, which we already provide, so signal that we
- // do not want those actions.
- return false;
+ protected boolean isAddToPopup(DockingAction action) {
+
+ String name = action.getName();
+ switch (name) {
+ case "Tree Expand All":
+ case "Tree Expand Node":
+ case "Tree Collapse Node":
+ // case "Tree Collapse All": // this action seems ok
+ return false;
+ default:
+ return true;
+ }
}
@Override
diff --git a/Ghidra/Framework/Docking/certification.manifest b/Ghidra/Framework/Docking/certification.manifest
index 4917069e29..8c19f29bc6 100644
--- a/Ghidra/Framework/Docking/certification.manifest
+++ b/Ghidra/Framework/Docking/certification.manifest
@@ -15,6 +15,11 @@ src/main/help/help/TOC_Source.xml||GHIDRA||||END|
src/main/help/help/topics/KeyboardNavigation/KeyboardNavigation.html||GHIDRA||||END|
src/main/help/help/topics/KeyboardNavigation/images/ActionsDialog.png||GHIDRA||||END|
src/main/help/help/topics/Misc/Welcome_to_Help.htm||GHIDRA||||END|
+src/main/help/help/topics/Search/Regular_Expressions.htm||GHIDRA||||END|
+src/main/help/help/topics/Tables/GhidraTableHeaders.html||GHIDRA||||END|
+src/main/help/help/topics/Tables/images/BytesSettingsDialog.png||GHIDRA||||END|
+src/main/help/help/topics/Tables/images/MultipleColumnSortDialog.png||GHIDRA||||END|
+src/main/help/help/topics/Tables/images/SelectColumnsDialog.png||GHIDRA||||END|
src/main/help/help/topics/Theming/ThemingDeveloperDocs.html||GHIDRA||||END|
src/main/help/help/topics/Theming/ThemingInternals.html||GHIDRA||||END|
src/main/help/help/topics/Theming/ThemingOverview.html||GHIDRA||||END|
@@ -24,11 +29,17 @@ src/main/help/help/topics/Theming/images/FontEditor.png||GHIDRA||||END|
src/main/help/help/topics/Theming/images/IconEditor.png||GHIDRA||||END|
src/main/help/help/topics/Theming/images/ThemeChooserDialog.png||GHIDRA||||END|
src/main/help/help/topics/Theming/images/ThemeEditorDialog.png||GHIDRA||||END|
+src/main/help/help/topics/Trees/GhidraTreeFilter.html||GHIDRA||||END|
+src/main/help/help/topics/Trees/images/Filter.png||GHIDRA||||END|
+src/main/help/help/topics/Trees/images/FilterClearButton.png||GHIDRA||||END|
+src/main/help/help/topics/Trees/images/FilterOptions.png||GHIDRA||||END|
+src/main/help/help/topics/Trees/images/TableColumnFilter.png||GHIDRA||||END|
+src/main/help/help/topics/Trees/images/TableColumnFilterAfterFilterApplied.png||GHIDRA||||END|
+src/main/help/help/topics/Trees/images/TableColumnFilterDialog.png||GHIDRA||||END|
src/main/java/docking/dnd/package.html||GHIDRA||reviewed||END|
src/main/java/docking/options/editor/package.html||GHIDRA||reviewed||END|
src/main/java/docking/widgets/fieldpanel/package.html||GHIDRA||reviewed||END|
src/main/java/docking/widgets/filechooser/package.html||GHIDRA||reviewed||END|
-src/main/java/docking/wizard/package.html||GHIDRA||reviewed||END|
src/main/resources/images/Minus.png||GHIDRA||||END|
src/main/resources/images/Plus.png||GHIDRA||reviewed||END|
src/main/resources/images/StackFrameElement.png||GHIDRA||reviewed||END|
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Search/Regular_Expressions.htm b/Ghidra/Framework/Docking/src/main/help/help/topics/Search/Regular_Expressions.htm
similarity index 96%
rename from Ghidra/Features/Base/src/main/help/help/topics/Search/Regular_Expressions.htm
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Search/Regular_Expressions.htm
index d3f0a4e88c..b7d1270e3b 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/Search/Regular_Expressions.htm
+++ b/Ghidra/Framework/Docking/src/main/help/help/topics/Search/Regular_Expressions.htm
@@ -14,26 +14,11 @@
<BODY>
<H1><A name="Memory_Regular_Expressions"></A>Regular Expressions</H1>
- <P>Memory searches in Ghidra can use regular expressions for powerful and flexible searches.
- This feature uses Java's built-in regular expressions grammar, so the syntax is exactly the
- same as a regular expression for any standard Java application. Because of restrictions on how
- regular expressions are processed, regular expression searches can only be performed in the
- forward direction. Unlike standard string searches, case sensitivity and unicode options do not
- apply. The <I>Search Memory</I> window below shows a sample regular expression entered in the
- <I>Value</I> field.</P>
-
-
+ <P>Many searches and filters in Ghidra can use regular expressions..
+ Ghidra uses Java's built-in regular expressions grammar, so the syntax is exactly the
+ same as a regular expression for any standard Java application.
<BLOCKQUOTE>
- <BLOCKQUOTE>
- <TABLE border="0" width="80%">
- <TBODY>
- <TR>
- <TD align="left"><IMG border="0" src="images/SearchMemoryRegex.png" alt=""></TD>
- </TR>
- </TBODY>
- </TABLE>
- </BLOCKQUOTE>
<H3>Examples</H3>
<BLOCKQUOTE>
@@ -819,14 +804,8 @@
</TABLE>
</BLOCKQUOTE>
- <P class="relatedtopic">&nbsp;</P>
-
- <P class="relatedtopic">Related Topics</P>
-
- <UL>
- <LI>
- <P class="relatedtopic"><A href="Search_Memory.htm">Search Memory</A></P>
- </LI>
- </UL><BR>
+ <BR>
+ <BR>
+ <BR>
</BODY>
</HTML>
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Tables/GhidraTableHeaders.html b/Ghidra/Framework/Docking/src/main/help/help/topics/Tables/GhidraTableHeaders.html
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Tables/GhidraTableHeaders.html
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Tables/GhidraTableHeaders.html
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Tables/images/BytesSettingsDialog.png b/Ghidra/Framework/Docking/src/main/help/help/topics/Tables/images/BytesSettingsDialog.png
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Tables/images/BytesSettingsDialog.png
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Tables/images/BytesSettingsDialog.png
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Tables/images/MultipleColumnSortDialog.png b/Ghidra/Framework/Docking/src/main/help/help/topics/Tables/images/MultipleColumnSortDialog.png
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Tables/images/MultipleColumnSortDialog.png
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Tables/images/MultipleColumnSortDialog.png
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Tables/images/SelectColumnsDialog.png b/Ghidra/Framework/Docking/src/main/help/help/topics/Tables/images/SelectColumnsDialog.png
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Tables/images/SelectColumnsDialog.png
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Tables/images/SelectColumnsDialog.png
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Trees/GhidraTreeFilter.html b/Ghidra/Framework/Docking/src/main/help/help/topics/Trees/GhidraTreeFilter.html
similarity index 97%
rename from Ghidra/Features/Base/src/main/help/help/topics/Trees/GhidraTreeFilter.html
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Trees/GhidraTreeFilter.html
index 992314ece6..9e84cf16ab 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/Trees/GhidraTreeFilter.html
+++ b/Ghidra/Framework/Docking/src/main/help/help/topics/Trees/GhidraTreeFilter.html
@@ -51,8 +51,9 @@
</BLOCKQUOTE><BR>
<BR>
-
- <H2><A name="Activate_Filter"></A>Activate Filter</H2>
+ <H2>Filter Actions</H2>
+ <BLOCKQUOTE>
+ <H3><A name="Activate_Filter"></A>Activate Filter</H3>
<BLOCKQUOTE>
<P>
The <B>Activate Filter</B> action will transfer focus to the filter field when you are
@@ -62,7 +63,7 @@
</BLOCKQUOTE>
- <H2><A name="Toggle_Filter"></A>Toggle Filter</H2>
+ <H3><A name="Toggle_Filter"></A>Toggle Filter</H3>
<BLOCKQUOTE>
<P>
The <B>Toggle Filter</B> action will hide and show the filter field of the tree or table.
@@ -70,11 +71,8 @@
</P>
</BLOCKQUOTE>
-
-
-
- <H2>Clear Filter</H2>
+ <H3>Clear Filter</H3>
<BLOCKQUOTE>
<!--
@@ -100,7 +98,11 @@
</CENTER>
</BLOCKQUOTE><BR>
<BR>
-
+ </BLOCKQUOTE>
+
+
+
+
<H2>The Filter Options Dialog<A name="Filter_Options" id="Filter_Options"></A></H2>
@@ -542,12 +544,21 @@
</BLOCKQUOTE>
</BLOCKQUOTE>
+
+
+ <H2>Miscellaneous Actions</H2>
+ <BLOCKQUOTE>
+ <H3><A name="Copy_Formatted"></A>Copy Formatted</H3>
+ <P>This action will copy the names of each node in the tree selection. Unlike the default copy
+ operation, this action will preserve the node's indentation.
+ </P>
+ </BLOCKQUOTE>
<!-- extra space at the bottom of the page (for readability) -->
- <br>
- <br>
- <br>
- <br>
+ <BR>
+ <BR>
+ <BR>
+ <BR>
<P class="relatedtopic">Related Topics</P>
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Trees/images/Filter.png b/Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/Filter.png
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Trees/images/Filter.png
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/Filter.png
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Trees/images/FilterClearButton.png b/Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/FilterClearButton.png
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Trees/images/FilterClearButton.png
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/FilterClearButton.png
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Trees/images/FilterOptions.png b/Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/FilterOptions.png
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Trees/images/FilterOptions.png
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/FilterOptions.png
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Trees/images/TableColumnFilter.png b/Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/TableColumnFilter.png
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Trees/images/TableColumnFilter.png
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/TableColumnFilter.png
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Trees/images/TableColumnFilterAfterFilterApplied.png b/Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/TableColumnFilterAfterFilterApplied.png
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Trees/images/TableColumnFilterAfterFilterApplied.png
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/TableColumnFilterAfterFilterApplied.png
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Trees/images/TableColumnFilterDialog.png b/Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/TableColumnFilterDialog.png
similarity index 100%
rename from Ghidra/Features/Base/src/main/help/help/topics/Trees/images/TableColumnFilterDialog.png
rename to Ghidra/Framework/Docking/src/main/help/help/topics/Trees/images/TableColumnFilterDialog.png
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java
index f02f630aec..5352568f78 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/GTree.java
@@ -1458,12 +1458,16 @@ public class GTree extends JPanel implements BusyListener {
}
/**
- * A method that subclasses can override to signal that they wish not to have this tree's
- * built-in popup actions. Subclasses will almost never need to override this method.
- *
- * @return true if popup actions are supported
+ * A method that subclasses can override to decide if the given action should appear in the
+ * popup menu. Most subclasses will not need to override this method. An example for
+ * overriding this method is one of the subclasses that have their own version of one of the
+ * built-in actions, such as Expand All. Some clients have a custom expand action. In that
+ * case, the client wants their action in the menu and not the built-in version.
+ *
+ * @param action the action
+ * @return true to have the action appear in the popup; the default is true
*/
- protected boolean supportsPopupActions() {
+ protected boolean isAddToPopup(DockingAction action) {
return true;
}
@@ -1485,6 +1489,7 @@ public class GTree extends JPanel implements BusyListener {
private boolean paintLeafHandles = true;
private int scrollableUnitIncrementOverride = -1;
private boolean allowRootCollapse = true;
+ private boolean isCopyFormatted;
public AutoScrollTree(TreeModel model) {
super(model);
@@ -1493,13 +1498,32 @@ public class GTree extends JPanel implements BusyListener {
setRowHeight(-1);// variable size rows
setSelectionModel(new GTreeSelectionModel());
- setInvokesStopCellEditing(true);// clicking outside the cell editor will trigger a save, not a cancel
+
+ // clicking outside the cell editor will trigger a save, not a cancel
+ setInvokesStopCellEditing(true);
updateDefaultKeyBindings();
ToolTipManager.sharedInstance().registerComponent(this);
}
+ @Override
+ public String convertValueToText(Object value, boolean selected, boolean expanded,
+ boolean leaf, int row, boolean hasFocus) {
+
+ String spacing = "";
+ if (isCopyFormatted) {
+ GTreeNode node = (GTreeNode) value;
+ TreePath path = node.getTreePath();
+ int n = path.getPathCount();
+ int tabs = (n - 1) * 4; // no spacing for the first column
+ spacing = StringUtils.repeat(' ', tabs);
+ }
+
+ String text = super.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
+ return spacing + text;
+ }
+
private void updateDefaultKeyBindings() {
// Remove the edit keybinding, as the GTree triggers editing via a task, since it
@@ -1667,7 +1691,7 @@ public class GTree extends JPanel implements BusyListener {
}
GTree gTree = getTree(context);
- return gTree.supportsPopupActions();
+ return gTree.isAddToPopup(this);
}
@Override
@@ -1734,7 +1758,6 @@ public class GTree extends JPanel implements BusyListener {
)
);
collapseAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK));
- collapseAction.setHelpLocation(new HelpLocation("Trees", "Collapse"));
//@formatter:on
GTreeAction expandAction = new GTreeAction("Tree Expand Node", owner) {
@@ -1768,7 +1791,6 @@ public class GTree extends JPanel implements BusyListener {
)
);
expandAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK));
- expandAction.setHelpLocation(new HelpLocation("Trees", "Expand"));
//@formatter:on
GTreeAction collapseTreeAction = new GTreeAction("Tree Collapse All", owner) {
@@ -1787,7 +1809,6 @@ public class GTree extends JPanel implements BusyListener {
Integer.toString(subGroupIndex++)
)
);
- collapseTreeAction.setHelpLocation(new HelpLocation("Trees", "Collapse_Tree"));
//@formatter:on
GTreeAction expandTreeAction = new GTreeAction("Tree Expand All", owner) {
@@ -1805,7 +1826,32 @@ public class GTree extends JPanel implements BusyListener {
Integer.toString(subGroupIndex++)
)
);
- expandTreeAction.setHelpLocation(new HelpLocation("Trees", "Expand_Tree"));
+ //@formatter:on
+
+ GTreeAction copyFormattedAction = new GTreeAction("Tree Copy Formatted", owner) {
+ @Override
+ public void actionPerformed(ActionContext context) {
+
+ GTree gTree = (GTree) context.getSourceComponent();
+ gTree.tree.isCopyFormatted = true;
+ try {
+ Action builtinCopyAction = TransferHandler.getCopyAction();
+ builtinCopyAction.actionPerformed(new ActionEvent(gTree.tree, 0, "copy"));
+ }
+ finally {
+ gTree.tree.isCopyFormatted = false;
+ }
+ }
+ };
+ //@formatter:off
+ copyFormattedAction.setPopupMenuData(new MenuData(
+ new String[] { "Copy Formatted" },
+ null,
+ actionMenuGroup, NO_MNEMONIC,
+ Integer.toString(subGroupIndex++)
+ )
+ );
+ copyFormattedAction.setHelpLocation(new HelpLocation("Trees", "Copy_Special"));
//@formatter:on
GTreeAction activateFilterAction = new GTreeAction("Table/Tree Activate Filter", owner) {
@@ -1851,6 +1897,7 @@ public class GTree extends JPanel implements BusyListener {
toolActions.addGlobalAction(expandAction);
toolActions.addGlobalAction(collapseTreeAction);
toolActions.addGlobalAction(expandTreeAction);
+ toolActions.addGlobalAction(copyFormattedAction);
toolActions.addGlobalAction(activateFilterAction);
toolActions.addGlobalAction(toggleFilterAction);
}
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTree.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTree.java
index 5a1593bf9a..1bfe373361 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTree.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTree.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,6 +22,7 @@ import javax.swing.ToolTipManager;
import javax.swing.tree.TreePath;
import docking.DockingUtils;
+import docking.action.DockingAction;
import docking.actions.KeyBindingUtils;
import docking.widgets.tree.GTree;
import docking.widgets.tree.GTreeNode;
@@ -64,10 +65,18 @@ public class DataTree extends GTree {
}
@Override
- protected boolean supportsPopupActions() {
- // The base tree adds collapse/ expand actions, which we already provide, so signal that we
- // do not want those actions.
- return false;
+ protected boolean isAddToPopup(DockingAction action) {
+
+ String name = action.getName();
+ switch (name) {
+ case "Tree Expand All":
+ case "Tree Expand Node":
+ case "Tree Collapse Node":
+ // case "Tree Collapse All": // this action seems ok
+ return false;
+ default:
+ return true;
+ }
}
void setProjectActive(boolean isActive) {