Merge remote-tracking branch 'origin/GP-775-dragonmacher-program-tree-ui-slowdown'

This commit is contained in:
ghidra1
2021-03-17 18:53:49 -04:00

View File

@@ -267,8 +267,8 @@ class ProgramTreeActionManager implements ClipboardOwner {
}; };
goToViewAction.setEnabled(false); goToViewAction.setEnabled(false);
goToViewAction.setPopupMenuData( goToViewAction
new MenuData(new String[] { "Go To in View" }, null, "aview")); .setPopupMenuData(new MenuData(new String[] { "Go To in View" }, null, "aview"));
list.add(goToViewAction); list.add(goToViewAction);
@@ -282,8 +282,8 @@ class ProgramTreeActionManager implements ClipboardOwner {
}; };
removeViewAction.setEnabled(false); removeViewAction.setEnabled(false);
removeViewAction.setPopupMenuData( removeViewAction
new MenuData(new String[] { "Remove from View" }, null, "aview")); .setPopupMenuData(new MenuData(new String[] { "Remove from View" }, null, "aview"));
list.add(removeViewAction); list.add(removeViewAction);
@@ -297,8 +297,8 @@ class ProgramTreeActionManager implements ClipboardOwner {
}; };
replaceViewAction.setEnabled(false); replaceViewAction.setEnabled(false);
replaceViewAction.setPopupMenuData( replaceViewAction
new MenuData(new String[] { "Replace View" }, null, "aview")); .setPopupMenuData(new MenuData(new String[] { "Replace View" }, null, "aview"));
list.add(replaceViewAction); list.add(replaceViewAction);
@@ -446,8 +446,8 @@ class ProgramTreeActionManager implements ClipboardOwner {
collapseAction.setEnabled(false); collapseAction.setEnabled(false);
// ACTIONS - auto generated // ACTIONS - auto generated
collapseAction.setPopupMenuData( collapseAction
new MenuData(new String[] { "Collapse All" }, null, "expand")); .setPopupMenuData(new MenuData(new String[] { "Collapse All" }, null, "expand"));
list.add(collapseAction); list.add(collapseAction);
@@ -577,8 +577,7 @@ class ProgramTreeActionManager implements ClipboardOwner {
return; return;
} }
for (int i = 0; i < list.size(); i++) { for (ProgramNode node : list) {
ProgramNode node = list.get(i);
if (tree.getModel().getRoot() != node.getRoot()) { if (tree.getModel().getRoot() != node.getRoot()) {
break; break;
} }
@@ -642,11 +641,12 @@ class ProgramTreeActionManager implements ClipboardOwner {
try { try {
Clipboard systemClipboard = GClipboard.getSystemClipboard(); Clipboard systemClipboard = GClipboard.getSystemClipboard();
Transferable t = systemClipboard.getContents(this); if (!systemClipboard.isDataFlavorAvailable(TreeTransferable.localTreeNodeFlavor)) {
if (t == null) {
return; return;
} }
if (!t.isDataFlavorSupported(TreeTransferable.localTreeNodeFlavor)) {
Object data = systemClipboard.getData(TreeTransferable.localTreeNodeFlavor);
if (data == null) {
return; return;
} }
@@ -659,9 +659,8 @@ class ProgramTreeActionManager implements ClipboardOwner {
} }
private void doClearSystemClipboard(Clipboard systemClipboard) { private void doClearSystemClipboard(Clipboard systemClipboard) {
// for some reason setting the contents to null for the // for some reason setting the contents to null for the system clipboard causes a
// system clipboard causes a NullPointerException, so just // NullPointerException, so just set it with an empty transferable.
// set it with an empty transferable.
TreeTransferable dummyContents = new TreeTransferable(new ProgramNode[0]); TreeTransferable dummyContents = new TreeTransferable(new ProgramNode[0]);
systemClipboard.setContents(dummyContents, (clipboard, contents) -> { systemClipboard.setContents(dummyContents, (clipboard, contents) -> {
// a dummy implementation that will not prevent this plugin from being // a dummy implementation that will not prevent this plugin from being
@@ -979,8 +978,7 @@ class ProgramTreeActionManager implements ClipboardOwner {
ArrayList<ProgramNode> list = tree.getSortedSelection(); ArrayList<ProgramNode> list = tree.getSortedSelection();
CompoundCmd compCmd = new CompoundCmd("Merge with Parent"); CompoundCmd compCmd = new CompoundCmd("Merge with Parent");
String treeName = tree.getTreeName(); String treeName = tree.getTreeName();
for (int i = 0; i < list.size(); i++) { for (ProgramNode node : list) {
ProgramNode node = list.get(i);
tree.removeSelectionPath(node.getTreePath()); tree.removeSelectionPath(node.getTreePath());
ProgramNode parentNode = (ProgramNode) node.getParent(); ProgramNode parentNode = (ProgramNode) node.getParent();
if (node.isModule() && parentNode != null) { if (node.isModule() && parentNode != null) {
@@ -1036,7 +1034,7 @@ class ProgramTreeActionManager implements ClipboardOwner {
ProgramNode node = (ProgramNode) tree.getLastSelectedPathComponent(); ProgramNode node = (ProgramNode) tree.getLastSelectedPathComponent();
// if the node has not been yet visited, then when the group is added via the // 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(); node.visit();
String name = tree.getNewFolderName(); String name = tree.getNewFolderName();
@@ -1242,14 +1240,15 @@ class ProgramTreeActionManager implements ClipboardOwner {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// the cast is safe, since we checked the flavor // the cast is safe, since we checked the flavor
private boolean isPasteOk(ProgramNode destNode) { private boolean isPasteOk(ProgramNode destNode) {
Transferable t = null;
boolean isCutOperation = false; boolean isCutOperation = false;
Clipboard systemClipboard = GClipboard.getSystemClipboard();
if (!systemClipboard.isDataFlavorAvailable(TreeTransferable.localTreeNodeFlavor)) {
return false;
}
try { try {
t = GClipboard.getSystemClipboard().getContents(this); // we will put items on the 'tempClipboard' when the cut action is executed
if (t == null) {
return false;
}
Transferable temp = tempClipboard.getContents(this); Transferable temp = tempClipboard.getContents(this);
isCutOperation = (temp != null); isCutOperation = (temp != null);
} }
@@ -1258,26 +1257,16 @@ class ProgramTreeActionManager implements ClipboardOwner {
return false; return false;
} }
if (!t.isDataFlavorSupported(TreeTransferable.localTreeNodeFlavor)) {
return false;
}
try { try {
if (!t.isDataFlavorSupported(TreeTransferable.localTreeNodeFlavor)) {
return false;
}
List<ProgramNode> list = List<ProgramNode> list =
(List<ProgramNode>) t.getTransferData(TreeTransferable.localTreeNodeFlavor); (List<ProgramNode>) systemClipboard.getData(TreeTransferable.localTreeNodeFlavor);
if (list == null) { if (list == null) {
// SCR 7990--something bad has happened to the copy buffer // SCR 7990--something bad has happened to the copy buffer
return false; return false;
} }
boolean pasteEnabled = false; boolean pasteEnabled = false;
for (int i = 0; i < list.size(); i++) { for (ProgramNode pasteNode : list) {
ProgramNode pasteNode = list.get(i);
boolean pasteAllowed = pasteMgr.isPasteAllowed(destNode, pasteNode, isCutOperation); boolean pasteAllowed = pasteMgr.isPasteAllowed(destNode, pasteNode, isCutOperation);
if (isCutOperation && !pasteAllowed) { if (isCutOperation && !pasteAllowed) {
// for cut operation all nodes must be able to be pasted at destNode // for cut operation all nodes must be able to be pasted at destNode