mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GT-2705 - File Import - review fixes; updated transient project dialogs
to not have copy/paste actions etc
This commit is contained in:
parent
84c16c2b27
commit
f3ef6956c9
20 changed files with 201 additions and 134 deletions
|
@ -30,6 +30,7 @@ public class ProjectDataActionContext extends ActionContext implements DomainFil
|
|||
private Component comp;
|
||||
private boolean isActiveProject;
|
||||
private ProjectData projectData;
|
||||
private boolean isTransient;
|
||||
|
||||
public ProjectDataActionContext(ComponentProvider provider, ProjectData projectData,
|
||||
Object contextObject, List<DomainFolder> selectedFolders,
|
||||
|
@ -112,4 +113,20 @@ public class ProjectDataActionContext extends ActionContext implements DomainFil
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transient data is that which will appear in a temporary project dialog
|
||||
* @param isTransient true if transient
|
||||
*/
|
||||
public void setTransient(boolean isTransient) {
|
||||
this.isTransient = isTransient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transient data is that which will appear in a temporary project dialog
|
||||
* @return true if transient
|
||||
*/
|
||||
public boolean isTransient() {
|
||||
return isTransient;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -26,20 +25,42 @@ public abstract class ProjectDataContextAction extends DockingAction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final boolean isEnabledForContext(ActionContext actionContext) {
|
||||
public boolean isEnabledForContext(ActionContext actionContext) {
|
||||
if (!(actionContext instanceof ProjectDataActionContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ProjectDataActionContext context = (ProjectDataActionContext) actionContext;
|
||||
if (ignoreTransientProject(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isEnabledForContext(context);
|
||||
}
|
||||
|
||||
protected boolean ignoreTransientProject(ProjectDataActionContext context) {
|
||||
if (supportsTransientProjectData()) {
|
||||
return false;
|
||||
}
|
||||
return context.isTransient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Signals that this action can work on normal project data, as well as transient data.
|
||||
* Transient data is that which will appear in a temporary project dialog.
|
||||
*
|
||||
* @return true if this action works on transient project data
|
||||
*/
|
||||
protected boolean supportsTransientProjectData() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isEnabledForContext(ProjectDataActionContext context) {
|
||||
return context.hasOneOrMoreFilesAndFolders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void actionPerformed(ActionContext context) {
|
||||
public void actionPerformed(ActionContext context) {
|
||||
actionPerformed((ProjectDataActionContext) context);
|
||||
}
|
||||
|
||||
|
@ -59,7 +80,7 @@ public abstract class ProjectDataContextAction extends DockingAction {
|
|||
|
||||
@Override
|
||||
public boolean isAddToPopup(ActionContext context) {
|
||||
if (!(context instanceof ProjectDataActionContext)) {
|
||||
if (!isEnabledForContext(context)) {
|
||||
return false;
|
||||
}
|
||||
return isAddToPopup((ProjectDataActionContext) context);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -30,10 +29,32 @@ public abstract class ProjectDataContextToggleAction extends ToggleDockingAction
|
|||
if (!(actionContext instanceof ProjectDataActionContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ProjectDataActionContext context = (ProjectDataActionContext) actionContext;
|
||||
if (ignoreTransientProject(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isEnabledForContext(context);
|
||||
}
|
||||
|
||||
protected boolean ignoreTransientProject(ProjectDataActionContext context) {
|
||||
if (supportsTransientProjectData()) {
|
||||
return false;
|
||||
}
|
||||
return context.isTransient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Signals that this action can work on normal project data, as well as transient data.
|
||||
* Transient data is that which will appear in a temporary project dialog.
|
||||
*
|
||||
* @return true if this action works on transient project data
|
||||
*/
|
||||
protected boolean supportsTransientProjectData() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isEnabledForContext(ProjectDataActionContext context) {
|
||||
return context.hasOneOrMoreFilesAndFolders();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,9 +15,9 @@
|
|||
*/
|
||||
package ghidra.framework.main.datatable;
|
||||
|
||||
import ghidra.framework.main.datatree.ProjectDataTreeActionContext;
|
||||
import docking.ActionContext;
|
||||
import docking.action.DockingAction;
|
||||
import ghidra.framework.main.datatree.ProjectDataTreeActionContext;
|
||||
|
||||
public abstract class ProjectDataTreeContextAction extends DockingAction {
|
||||
|
||||
|
@ -31,10 +30,32 @@ public abstract class ProjectDataTreeContextAction extends DockingAction {
|
|||
if (!(actionContext instanceof ProjectDataTreeActionContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ProjectDataTreeActionContext context = (ProjectDataTreeActionContext) actionContext;
|
||||
if (ignoreTransientProject(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isEnabledForContext(context);
|
||||
}
|
||||
|
||||
protected boolean ignoreTransientProject(ProjectDataActionContext context) {
|
||||
if (supportsTransientProjectData()) {
|
||||
return false;
|
||||
}
|
||||
return context.isTransient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Signals that this action can work on normal project data, as well as transient data.
|
||||
* Transient data is that which will appear in a temporary project dialog.
|
||||
*
|
||||
* @return true if this action works on transient project data
|
||||
*/
|
||||
protected boolean supportsTransientProjectData() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isEnabledForContext(ProjectDataTreeActionContext context) {
|
||||
return context.hasOneOrMoreFilesAndFolders();
|
||||
}
|
||||
|
@ -60,7 +81,7 @@ public abstract class ProjectDataTreeContextAction extends DockingAction {
|
|||
|
||||
@Override
|
||||
public boolean isAddToPopup(ActionContext context) {
|
||||
if (!(context instanceof ProjectDataTreeActionContext)) {
|
||||
if (!isEnabledForContext(context)) {
|
||||
return false;
|
||||
}
|
||||
return isAddToPopup((ProjectDataTreeActionContext) context);
|
||||
|
|
|
@ -23,6 +23,7 @@ import javax.swing.tree.TreePath;
|
|||
|
||||
import docking.dnd.GClipboard;
|
||||
import docking.widgets.tree.GTreeNode;
|
||||
import docking.widgets.tree.support.GTreeNodeTransferable;
|
||||
import ghidra.util.Msg;
|
||||
|
||||
/**
|
||||
|
@ -35,14 +36,8 @@ public class DataTreeClipboardUtils {
|
|||
* Static instance of a callback handler that is notified when the clipboard is changed
|
||||
* and our data is discarded.
|
||||
*/
|
||||
private static final ClipboardOwner DATATREE_CLIPBOARD_OWNER = new ClipboardOwner() {
|
||||
@Override
|
||||
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
||||
// This is called when something other than this class modifies the clipboard
|
||||
// and our data is discarded.
|
||||
clearCuttables(contents);
|
||||
}
|
||||
};
|
||||
private static final ClipboardOwner DATATREE_CLIPBOARD_OWNER =
|
||||
(clipboard, contents) -> clearCuttables(contents);
|
||||
|
||||
/**
|
||||
* Pushes the GTreeNodes in the specified TreePath array to the clipboard.
|
||||
|
@ -59,8 +54,9 @@ public class DataTreeClipboardUtils {
|
|||
GTreeNode node = (GTreeNode) element.getLastPathComponent();
|
||||
list.add(node);
|
||||
}
|
||||
DataTreeNodeTransferable contents =
|
||||
new DataTreeNodeTransferable(tree.getDragNDropHandler(), list);
|
||||
|
||||
GTreeNodeTransferable contents =
|
||||
new GTreeNodeTransferable(tree.getDragNDropHandler(), list);
|
||||
|
||||
try {
|
||||
clipboard.setContents(contents, DATATREE_CLIPBOARD_OWNER);
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.framework.main.datatree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import docking.widgets.tree.GTreeNode;
|
||||
import docking.widgets.tree.support.GTreeNodeTransferable;
|
||||
import docking.widgets.tree.support.GTreeTransferHandler;
|
||||
|
||||
public class DataTreeNodeTransferable extends GTreeNodeTransferable {
|
||||
public DataTreeNodeTransferable(GTreeTransferHandler handler, List<GTreeNode> selectedData) {
|
||||
super(handler, selectedData);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,14 +15,13 @@
|
|||
*/
|
||||
package ghidra.framework.main.datatree;
|
||||
|
||||
import ghidra.framework.main.datatable.ProjectDataActionContext;
|
||||
import ghidra.framework.model.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import docking.ComponentProvider;
|
||||
import ghidra.framework.main.datatable.ProjectDataActionContext;
|
||||
import ghidra.framework.model.*;
|
||||
|
||||
public class ProjectDataTreeActionContext extends ProjectDataActionContext {
|
||||
|
||||
|
@ -52,7 +50,7 @@ public class ProjectDataTreeActionContext extends ProjectDataActionContext {
|
|||
return selectionPaths;
|
||||
}
|
||||
|
||||
public DataTree getDataTree() {
|
||||
public DataTree getTree() {
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,8 +337,11 @@ public class ProjectDataTreePanel extends JPanel {
|
|||
}
|
||||
}
|
||||
|
||||
return new ProjectDataTreeActionContext(provider, projectData, selectionPaths,
|
||||
domainFolderList, domainFileList, tree, isActiveProject);
|
||||
ProjectDataTreeActionContext context = new ProjectDataTreeActionContext(provider,
|
||||
projectData, selectionPaths, domainFolderList, domainFileList, tree, isActiveProject);
|
||||
boolean isTransient = tool == null; // null for stand-alone dialog, not the project's tree
|
||||
context.setTransient(isTransient);
|
||||
return context;
|
||||
}
|
||||
|
||||
public DataTree getDataTree() {
|
||||
|
|
|
@ -33,7 +33,7 @@ public class ProjectDataCollapseAction extends ProjectDataTreeContextAction {
|
|||
|
||||
@Override
|
||||
protected void actionPerformed(ProjectDataTreeActionContext context) {
|
||||
DataTree tree = context.getDataTree();
|
||||
DataTree tree = context.getTree();
|
||||
TreePath[] paths = context.getSelectionPaths();
|
||||
collapse(tree, paths[0]);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class ProjectDataCopyAction extends ProjectDataCopyCutBaseAction {
|
|||
protected void actionPerformed(ProjectDataTreeActionContext context) {
|
||||
TreePath[] paths = adjustSelectionPaths(context.getSelectionPaths());
|
||||
|
||||
DataTreeClipboardUtils.setClipboardContents(context.getDataTree(), paths);
|
||||
DataTreeClipboardUtils.setClipboardContents(context.getTree(), paths);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class ProjectDataCutAction extends ProjectDataCopyCutBaseAction {
|
|||
protected void actionPerformed(ProjectDataTreeActionContext context) {
|
||||
TreePath[] paths = adjustSelectionPaths(context.getSelectionPaths());
|
||||
|
||||
DataTreeClipboardUtils.setClipboardContents(context.getDataTree(), paths);
|
||||
DataTreeClipboardUtils.setClipboardContents(context.getTree(), paths);
|
||||
|
||||
markNodesCut(paths);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class ProjectDataExpandAction extends ProjectDataTreeContextAction {
|
|||
|
||||
@Override
|
||||
protected void actionPerformed(ProjectDataTreeActionContext context) {
|
||||
DataTree tree = context.getDataTree();
|
||||
DataTree tree = context.getTree();
|
||||
TreePath[] paths = context.getSelectionPaths();
|
||||
expand(tree, paths[0]);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,12 @@ public class ProjectDataNewFolderAction extends ProjectDataContextAction {
|
|||
markHelpUnnecessary();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsTransientProjectData() {
|
||||
// we allow the user to create new folders even in transient projects
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(ProjectDataActionContext context) {
|
||||
createNewFolder(context);
|
||||
|
|
|
@ -44,7 +44,7 @@ public class ProjectDataPasteAction extends ProjectDataCopyCutBaseAction {
|
|||
GTreeNode node = (GTreeNode) context.getContextObject();
|
||||
DomainFolderNode destNode = getFolderForNode(node);
|
||||
|
||||
paste(context.getDataTree(), destNode);
|
||||
paste(context.getTree(), destNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,6 +50,10 @@ public class ProjectDataReadOnlyAction extends ProjectDataContextToggleAction {
|
|||
if (context.getFolderCount() != 0 || context.getFileCount() != 1) {
|
||||
return false;
|
||||
}
|
||||
if (ignoreTransientProject(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DomainFile domainFile = context.getSelectedFiles().get(0);
|
||||
setSelected(domainFile.isReadOnly());
|
||||
return true;
|
||||
|
|
|
@ -36,7 +36,7 @@ public class ProjectDataSelectAction extends ProjectDataTreeContextAction {
|
|||
|
||||
@Override
|
||||
protected void actionPerformed(ProjectDataTreeActionContext context) {
|
||||
DataTree tree = context.getDataTree();
|
||||
DataTree tree = context.getTree();
|
||||
TreePath[] paths = context.getSelectionPaths();
|
||||
GTreeNode node = (GTreeNode) paths[0].getLastPathComponent();
|
||||
selectAllChildren(tree, node);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue