Index: VcsFSCommandsAction.java =================================================================== RCS file: /cvs/vcscore/src/org/netbeans/modules/vcscore/VcsFSCommandsAction.java,v retrieving revision 1.19 diff -u -r1.19 VcsFSCommandsAction.java --- VcsFSCommandsAction.java 18 Feb 2005 19:17:36 -0000 1.19 +++ VcsFSCommandsAction.java 4 Apr 2005 17:15:15 -0000 @@ -34,6 +34,7 @@ import javax.swing.JPopupMenu; import org.netbeans.api.fileinfo.NonRecursiveFolder; +import org.openide.actions.FileSystemAction; import org.openide.awt.Actions; import org.openide.awt.JInlineMenu; @@ -93,11 +94,21 @@ * Currently the info can be a String message, or NonRecursiveFolder.class * or null. */ - private Map getSelectedFileObjectsFromActiveNodes (Lookup lookup) { + private Map getSelectedFileObjectsFromActiveNodes (Lookup lookup, boolean checkFSAction) { Map filesWithInfo = new Table(); ArrayList files = new ArrayList(); Node[] nodes = (Node[])lookup.lookup (new Lookup.Template (Node.class)).allInstances().toArray (new Node[0]); for (int i = 0; i < nodes.length; i++) { + boolean isFSAction = !checkFSAction; + if (checkFSAction) { + javax.swing.Action[] actions = nodes[i].getActions(true); + for (int a = 0; a < actions.length; a++) { + if (actions[a] instanceof FileSystemAction) { + isFSAction = true; + break; + } + } + } GroupCookie gc = (GroupCookie) nodes[i].getCookie(GroupCookie.class); if (gc != null) { // Put any preceding files there to keep the order: @@ -147,6 +158,12 @@ Collection fos; if (fileObjects != null && (fos = fileObjects.allInstances()).size() > 0) { FileObject one = (FileObject) fos.iterator().next(); + // Ignore nodes that represent folders and do not have + // FileSystemAction associated. It might be dangerous to + // add VCS actions there, because the UI might not be + // descriptive enough for the user to see what's going + // to happen. + if (!isFSAction && one.isFolder()) continue; addAllFromSingleFS(one, fos, files); } else { DataObject dd = (DataObject) (nodes[i].getCookie(DataObject.class)); @@ -155,8 +172,12 @@ // We want to have the same VCS actions on the link as on the original. dd = ((DataShadow) dd).getOriginal(); } - //files.addAll(dd.files()); - //addAllWorkaround(dd.files(), files); + // Ignore nodes that represent folders and do not have + // FileSystemAction associated. It might be dangerous to + // add VCS actions there, because the UI might not be + // descriptive enough for the user to see what's going + // to happen. + if (!isFSAction && dd.getPrimaryFile().isFolder()) continue; addAllFromSingleFS(dd.getPrimaryFile(), dd.files(), files); } } @@ -266,7 +287,10 @@ } public JMenuItem[] createMenuItems(boolean inMenu, Lookup lookup) { - Map filesWithInfo = getSelectedFileObjectsFromActiveNodes (lookup); + return createMenuItems(inMenu, lookup, false); + } + public JMenuItem[] createMenuItems(boolean inMenu, Lookup lookup, boolean checkFSAction) { + Map filesWithInfo = getSelectedFileObjectsFromActiveNodes (lookup, checkFSAction); //System.out.println("VcsFSCommandsAction.getPresenter(): selected filesWithInfo: "+filesWithInfo); ArrayList menuItems = new ArrayList(); //CommandsTree[] commands = actionCommandsTree.children(); Index: actions/GeneralCommandAction.java =================================================================== RCS file: /cvs/vcscore/src/org/netbeans/modules/vcscore/actions/GeneralCommandAction.java,v retrieving revision 1.25 diff -u -r1.25 GeneralCommandAction.java --- actions/GeneralCommandAction.java 30 Aug 2004 17:46:21 -0000 1.25 +++ actions/GeneralCommandAction.java 4 Apr 2005 17:15:15 -0000 @@ -20,6 +20,7 @@ import java.util.Enumeration; import java.lang.ref.WeakReference; import java.util.Collection; +import org.openide.actions.FileSystemAction; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; @@ -313,14 +314,25 @@ System.out.println("checking action on data shadow=" + dobj.getName() + " " + dobj.getClass()); } */ - if (!checkDataObject(dobj)) return false; + if (!checkDataObject(dobj, true)) return false; } } } else { + boolean isFSAction = false; + javax.swing.Action[] actions = nodes[i].getActions(true); + for (int a = 0; a < actions.length; a++) { + if (actions[a] instanceof FileSystemAction) { + isFSAction = true; + break; + } + } Lookup.Result fileObjects = nodes[i].getLookup().lookup(new Lookup.Template(FileObject.class)); Collection fos = fileObjects.allInstances(); if (fos.size() > 0) { - if (!checkFileObjects(fos)) return false; + if (!checkFileObjects(fos, isFSAction)) { + suppMap = null; + return false; + } } else { DataObject dataObj; dataObj = (DataObject)nodes[i].getCookie(DataObject.class); @@ -328,23 +340,25 @@ dataObj = ((DataShadow)dataObj).getOriginal(); } // System.out.println("dataobj =" + dataObj); - if (!checkDataObject(dataObj)) return false; + if (!checkDataObject(dataObj, isFSAction)) { + suppMap = null; + return false; + } } } } return true; } - private boolean checkDataObject(DataObject dataObj) { + private boolean checkDataObject(DataObject dataObj, boolean isFSAction) { if (dataObj == null) { - suppMap = null; return false; } FileObject fileOb = dataObj.getPrimaryFile(); if (fileOb == null) { - suppMap = null; return false; } + if (!isFSAction && fileOb.isFolder()) return false; FileSystem primaryFS = (FileSystem) fileOb.getAttribute(org.netbeans.modules.vcscore.VcsAttributes.VCS_NATIVE_FS); CommandActionSupporter supp = (CommandActionSupporter)fileOb.getAttribute(VCS_ACTION_ATTRIBUTE); if (supp != null) { @@ -365,7 +379,6 @@ } // addToMap(suppMap, supp, dataObj.files()); } else { - suppMap = null; // System.out.println("no supporter found for " + dataObj.getName()); // one of the files is not under version control.. return false; @@ -373,11 +386,12 @@ return true; } - private boolean checkFileObjects(Collection fileObjects) { + private boolean checkFileObjects(Collection fileObjects, boolean isFSAction) { FileSystem primaryFS = null; boolean addedSomething = false; for (Iterator it = fileObjects.iterator(); it.hasNext(); ) { FileObject fileOb = (FileObject) it.next(); + if (!isFSAction && fileOb.isFolder()) return false; FileSystem fs = (FileSystem) fileOb.getAttribute(org.netbeans.modules.vcscore.VcsAttributes.VCS_NATIVE_FS); if (fs == null) continue; if (primaryFS == null) primaryFS = fs; Index: actions/VcsAllCommandsAction.java =================================================================== RCS file: /cvs/vcscore/src/org/netbeans/modules/vcscore/actions/VcsAllCommandsAction.java,v retrieving revision 1.15 diff -u -r1.15 VcsAllCommandsAction.java --- actions/VcsAllCommandsAction.java 24 Feb 2005 12:13:31 -0000 1.15 +++ actions/VcsAllCommandsAction.java 4 Apr 2005 17:15:15 -0000 @@ -144,7 +144,7 @@ private static JMenuItem[] getContextMenu(boolean inMenu, Lookup actionContext) { VcsFSCommandsAction contextAction = (VcsFSCommandsAction) VcsFSCommandsAction.get(VcsFSCommandsAction.class); - JMenuItem[] contextMenu = contextAction.createMenuItems(inMenu, actionContext); + JMenuItem[] contextMenu = contextAction.createMenuItems(inMenu, actionContext, true); return contextMenu; }