GT-2705 - File Import - review fixes; updated transient project dialogs

to not have copy/paste actions etc
This commit is contained in:
dragonmacher 2019-03-28 18:25:09 -04:00
parent 84c16c2b27
commit f3ef6956c9
20 changed files with 201 additions and 134 deletions

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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();
}

View file

@ -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);

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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() {

View file

@ -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]);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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]);
}

View file

@ -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);

View file

@ -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

View file

@ -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;

View file

@ -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);