Merge remote-tracking branch 'origin/GP-1-dragonmacher-action-context-bug'

This commit is contained in:
Ryan Kurtz
2026-09-23 07:50:02 -04:00
2 changed files with 51 additions and 42 deletions

View File

@@ -18,8 +18,7 @@ package ghidra.framework.main.projectdata.actions;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.net.URL;
import org.apache.commons.collections4.CollectionUtils;
import java.util.List;
import docking.action.MenuData;
import docking.dnd.GClipboard;
@@ -39,32 +38,35 @@ public class ProjectDataCopyGhidraURLAction extends ProjectDataCopyCutBaseAction
@Override
protected void actionPerformed(FrontEndProjectTreeContext context) {
Clipboard clipboard = GClipboard.getSystemClipboard();
List<DomainFile> files = context.getSelectedFiles();
DomainFile df = files.getFirst();
LinkFileInfo linkInfo = df.getLinkInfo();
if (linkInfo != null && linkInfo.isFolderLink()) {
return; // folder-link not supported
}
URL url = df.getSharedProjectURL(null);
if (url == null) {
url = df.getLocalProjectURL(null);
}
if (url == null) {
Msg.showError(ProjectDataCopyGhidraURLAction.class, null,
"Copy GhidraURL Failed",
"Failed to create file URL for: " + df.getPathname());
return;
}
try {
if(CollectionUtils.isNotEmpty(context.getSelectedFiles())) {
DomainFile df = context.getSelectedFiles().getFirst();
LinkFileInfo linkInfo = df.getLinkInfo();
if (linkInfo != null && linkInfo.isFolderLink()) {
return; // folder-link not supported
}
URL url = df.getSharedProjectURL(null);
if(url == null) {
url = df.getLocalProjectURL(null);
}
if (url != null) {
clipboard.setContents(new StringSelection(url.toString()), null);
}
else {
Msg.showError(ProjectDataCopyGhidraURLAction.class, null,
"Copy GhidraURL Failed",
"Failed to create file URL for: " + df.getPathname());
}
}
Clipboard clipboard = GClipboard.getSystemClipboard();
String urlString = url.toString();
clipboard.setContents(new StringSelection(urlString), null);
}
catch (IllegalStateException ise) {
// this can happen when other applications are accessing the system clipboard
Msg.showError(ProjectDataCopyGhidraURLAction.class, null, "Unable to Access Clipboard",
Msg.showError(ProjectDataCopyGhidraURLAction.class, null,
"Unable to Access Clipboard",
"Unable to perform cut/copy operation on the system clipboard. The " +
"clipboard may just be busy at this time. Please try again.");
}
@@ -72,10 +74,13 @@ public class ProjectDataCopyGhidraURLAction extends ProjectDataCopyCutBaseAction
@Override
protected boolean isEnabledForContext(FrontEndProjectTreeContext context) {
if (context.hasExactlyOneFileOrFolder() && context.getFileCount() != 1) {
List<DomainFile> files = context.getSelectedFiles();
if (files.size() != 1) {
return false;
}
DomainFile df = context.getSelectedFiles().getFirst();
DomainFile df = files.getFirst();
LinkFileInfo linkInfo = df.getLinkInfo();
if (linkInfo != null && linkInfo.isFolderLink()) {
return false;

View File

@@ -97,32 +97,36 @@ public class ProjectDataPasteLinkAction extends ProjectTreeAction {
if (!context.isInActiveProject() || !context.hasExactlyOneFileOrFolder()) {
return false;
}
GTreeNode node = (GTreeNode) context.getContextObject();
DomainFolder destFolder = DataTree.getRealInternalFolderForNode(node);
if (!ProjectDataPasteAction.checkNodeForPaste(destFolder)) {
return false;
}
Project activeProject = AppInfo.getActiveProject();
DataTreeNode copyNode = getFolderOrFileCopyNode();
if (copyNode != null) {
if (relative && copyNode.getProjectData() != activeProject.getProjectData()) {
if (copyNode == null) {
return false;
}
if (relative && copyNode.getProjectData() != activeProject.getProjectData()) {
return false;
}
if (copyNode instanceof DomainFileNode fileNode) {
// Only enable action if a LinkHandler exists for the file
DomainFile domainFile = fileNode.getDomainFile();
try {
ContentHandler<?> contentHandler =
DomainObjectAdapter.getContentHandler(domainFile.getContentType());
return contentHandler.getLinkHandler() != null;
}
catch (IOException e) {
return false;
}
if (copyNode instanceof DomainFileNode fileNode) {
// Only enable action if a LinkHandler exists for the file
DomainFile domainFile = fileNode.getDomainFile();
try {
ContentHandler<?> contentHandler =
DomainObjectAdapter.getContentHandler(domainFile.getContentType());
return contentHandler.getLinkHandler() != null;
}
catch (IOException e) {
return false;
}
}
return true;
}
return false;
return true;
}
private DataTreeNode getFolderOrFileCopyNode() {