From 4bd4dde6be76c9e515b0a3af76181230e5175104 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Fri, 12 Mar 2021 16:26:21 -0500 Subject: [PATCH 1/2] GP-775 - fixed Program Tree UI freeze when clicking with really large items on clipboard --- .../programtree/ProgramTreeActionManager.java | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreeActionManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreeActionManager.java index 0b1cbca5e5..9fc43dcb7c 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreeActionManager.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreeActionManager.java @@ -267,8 +267,8 @@ class ProgramTreeActionManager implements ClipboardOwner { }; goToViewAction.setEnabled(false); - goToViewAction.setPopupMenuData( - new MenuData(new String[] { "Go To in View" }, null, "aview")); + goToViewAction + .setPopupMenuData(new MenuData(new String[] { "Go To in View" }, null, "aview")); list.add(goToViewAction); @@ -282,8 +282,8 @@ class ProgramTreeActionManager implements ClipboardOwner { }; removeViewAction.setEnabled(false); - removeViewAction.setPopupMenuData( - new MenuData(new String[] { "Remove from View" }, null, "aview")); + removeViewAction + .setPopupMenuData(new MenuData(new String[] { "Remove from View" }, null, "aview")); list.add(removeViewAction); @@ -297,8 +297,8 @@ class ProgramTreeActionManager implements ClipboardOwner { }; replaceViewAction.setEnabled(false); - replaceViewAction.setPopupMenuData( - new MenuData(new String[] { "Replace View" }, null, "aview")); + replaceViewAction + .setPopupMenuData(new MenuData(new String[] { "Replace View" }, null, "aview")); list.add(replaceViewAction); @@ -446,8 +446,8 @@ class ProgramTreeActionManager implements ClipboardOwner { collapseAction.setEnabled(false); // ACTIONS - auto generated - collapseAction.setPopupMenuData( - new MenuData(new String[] { "Collapse All" }, null, "expand")); + collapseAction + .setPopupMenuData(new MenuData(new String[] { "Collapse All" }, null, "expand")); list.add(collapseAction); @@ -577,8 +577,7 @@ class ProgramTreeActionManager implements ClipboardOwner { return; } - for (int i = 0; i < list.size(); i++) { - ProgramNode node = list.get(i); + for (ProgramNode node : list) { if (tree.getModel().getRoot() != node.getRoot()) { break; } @@ -979,8 +978,7 @@ class ProgramTreeActionManager implements ClipboardOwner { ArrayList list = tree.getSortedSelection(); CompoundCmd compCmd = new CompoundCmd("Merge with Parent"); String treeName = tree.getTreeName(); - for (int i = 0; i < list.size(); i++) { - ProgramNode node = list.get(i); + for (ProgramNode node : list) { tree.removeSelectionPath(node.getTreePath()); ProgramNode parentNode = (ProgramNode) node.getParent(); if (node.isModule() && parentNode != null) { @@ -1036,7 +1034,7 @@ class ProgramTreeActionManager implements ClipboardOwner { ProgramNode node = (ProgramNode) tree.getLastSelectedPathComponent(); // if the node has not been yet visited, then when the group is added via the - // command below, the new child node in the parent will not be found + // command below, the new child node in the parent will not be found node.visit(); String name = tree.getNewFolderName(); @@ -1242,14 +1240,15 @@ class ProgramTreeActionManager implements ClipboardOwner { @SuppressWarnings("unchecked") // the cast is safe, since we checked the flavor private boolean isPasteOk(ProgramNode destNode) { - Transferable t = null; + boolean isCutOperation = false; + Clipboard systemClipboard = GClipboard.getSystemClipboard(); + if (!systemClipboard.isDataFlavorAvailable(TreeTransferable.localTreeNodeFlavor)) { + return false; + } try { - t = GClipboard.getSystemClipboard().getContents(this); - if (t == null) { - return false; - } + // we will put items on the 'tempClipboard' when the cut action is executed Transferable temp = tempClipboard.getContents(this); isCutOperation = (temp != null); } @@ -1258,26 +1257,16 @@ class ProgramTreeActionManager implements ClipboardOwner { return false; } - if (!t.isDataFlavorSupported(TreeTransferable.localTreeNodeFlavor)) { - return false; - } - try { - if (!t.isDataFlavorSupported(TreeTransferable.localTreeNodeFlavor)) { - return false; - } List list = - (List) t.getTransferData(TreeTransferable.localTreeNodeFlavor); - + (List) systemClipboard.getData(TreeTransferable.localTreeNodeFlavor); if (list == null) { // SCR 7990--something bad has happened to the copy buffer return false; } boolean pasteEnabled = false; - for (int i = 0; i < list.size(); i++) { - ProgramNode pasteNode = list.get(i); - + for (ProgramNode pasteNode : list) { boolean pasteAllowed = pasteMgr.isPasteAllowed(destNode, pasteNode, isCutOperation); if (isCutOperation && !pasteAllowed) { // for cut operation all nodes must be able to be pasted at destNode From 81297343212b9a6167a39fedc80702f20cd25bde Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Mon, 15 Mar 2021 19:40:16 -0400 Subject: [PATCH 2/2] GP-775 - review fixes --- .../core/programtree/ProgramTreeActionManager.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreeActionManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreeActionManager.java index 9fc43dcb7c..a437dab6d0 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreeActionManager.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreeActionManager.java @@ -641,11 +641,12 @@ class ProgramTreeActionManager implements ClipboardOwner { try { Clipboard systemClipboard = GClipboard.getSystemClipboard(); - Transferable t = systemClipboard.getContents(this); - if (t == null) { + if (!systemClipboard.isDataFlavorAvailable(TreeTransferable.localTreeNodeFlavor)) { return; } - if (!t.isDataFlavorSupported(TreeTransferable.localTreeNodeFlavor)) { + + Object data = systemClipboard.getData(TreeTransferable.localTreeNodeFlavor); + if (data == null) { return; } @@ -658,9 +659,8 @@ class ProgramTreeActionManager implements ClipboardOwner { } private void doClearSystemClipboard(Clipboard systemClipboard) { - // for some reason setting the contents to null for the - // system clipboard causes a NullPointerException, so just - // set it with an empty transferable. + // for some reason setting the contents to null for the system clipboard causes a + // NullPointerException, so just set it with an empty transferable. TreeTransferable dummyContents = new TreeTransferable(new ProgramNode[0]); systemClipboard.setContents(dummyContents, (clipboard, contents) -> { // a dummy implementation that will not prevent this plugin from being