Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Michel-Lemieux2004-09-22 15:14:32 +0000
committerJean Michel-Lemieux2004-09-22 15:14:32 +0000
commitccb7b157f1cdbe2b10713462a11edb6f079fa55b (patch)
treeab9d25bbd2a549f2f5f07a4c7fdee79ec9130b64
parenta34e61a370c9f88fbe7a1ac13c342ed1e6871d57 (diff)
downloadeclipse.platform.team-ccb7b157f1cdbe2b10713462a11edb6f079fa55b.tar.gz
eclipse.platform.team-ccb7b157f1cdbe2b10713462a11edb6f079fa55b.tar.xz
eclipse.platform.team-ccb7b157f1cdbe2b10713462a11edb6f079fa55b.zip
Bug 73488 Unable to copy commit set comments
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java15
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/CopyToClipboardAction.java217
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java35
3 files changed, 157 insertions, 110 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
index 33653c06e..bb50291c0 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
@@ -426,7 +426,7 @@ public class Utils {
* @param elements
* @return the list of resources contained in the given elements.
*/
- public static IResource[] getResources(Object[] elements) {
+ private static IResource[] getResources(Object[] elements, List nonResources) {
List resources = new ArrayList();
for (int i = 0; i < elements.length; i++) {
Object element = elements[i];
@@ -441,11 +441,24 @@ public class Utils {
}
if (resource != null) {
resources.add(resource);
+ } else {
+ if(nonResources != null)
+ nonResources.add(element);
}
}
return (IResource[]) resources.toArray(new IResource[resources.size()]);
}
+ public static Object[] getNonResources(Object[] elements) {
+ List nonResources = new ArrayList();
+ getResources(elements, nonResources);
+ return nonResources.toArray();
+ }
+
+ public static IResource[] getResources(Object[] element) {
+ return getResources(element, null);
+ }
+
public static Object getAdapter(Object element, Class adapter) {
if (element instanceof IAdaptable) {
return ((IAdaptable) element).getAdapter(adapter);
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/CopyToClipboardAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/CopyToClipboardAction.java
index 70c54f17d..c143d93b6 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/CopyToClipboardAction.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/CopyToClipboardAction.java
@@ -1,14 +1,17 @@
-/*
- * Created on Aug 26, 2004
- *
- * TODO To change the template for this generated file go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
package org.eclipse.team.internal.ui.synchronize.actions;
-import java.util.Iterator;
-import java.util.List;
-
+import java.util.*;
+import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
@@ -16,22 +19,19 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWTError;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.FileTransfer;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.*;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.internal.ui.Policy;
-import org.eclipse.team.internal.ui.TeamUIPlugin;
+import org.eclipse.team.internal.ui.*;
import org.eclipse.ui.actions.SelectionListenerAction;
import org.eclipse.ui.part.ResourceTransfer;
-
/**
- * Based on org.eclipse.ui.views.navigator.CopyAction.
+ * Based on org.eclipse.ui.views.navigator.CopyAction with the additional support for
+ * copying any non-resource object in the selection and putting the toString() as
+ * a text transfer.
+ *
+ * @since 3.1
*/
-
class CopyToClipboardAction extends SelectionListenerAction {
private final static String ID= TeamUIPlugin.PLUGIN_ID + ".synchronize.action.copy"; //$NON-NLS-1$
@@ -50,53 +50,79 @@ class CopyToClipboardAction extends SelectionListenerAction {
public void run() {
- List selectedResources = getSelectedResources();
- IResource[] resources = (IResource[]) selectedResources.toArray(new IResource[selectedResources.size()]);
-
- // Get the file names and a string representation
- final int length = resources.length;
- int actualLength = 0;
- String[] fileNames = new String[length];
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < length; i++) {
- final IPath location = resources[i].getLocation();
- // location may be null. See bug 29491.
- if (location != null)
- fileNames[actualLength++] = location.toOSString();
- if (i > 0)
- buf.append("\n"); //$NON-NLS-1$
- buf.append(resources[i].getName());
- }
- // was one or more of the locations null?
- if (actualLength < length) {
- String[] tempFileNames = fileNames;
- fileNames = new String[actualLength];
- for (int i = 0; i < actualLength; i++)
- fileNames[i] = tempFileNames[i];
- }
- setClipboard(resources, fileNames, buf.toString());
- }
+ List selectedResources = getSelectedResources();
+ List selectedNonResources = getSelectedNonResources();
+ if (selectedResources.size() > 0) {
+ copyResources(selectedResources);
+ } else if (selectedNonResources.size() > 0) {
+ copyObjects(selectedNonResources);
+ }
+ }
- /**
- * Set the clipboard contents. Prompt to retry if clipboard is busy.
- *
- * @param resources the resources to copy to the clipboard
- * @param fileNames file names of the resources to copy to the clipboard
- * @param names string representation of all names
- */
+ private void copyObjects(List selectedNonResources) {
+ StringBuffer buf = new StringBuffer();
+ int i = 0;
+ for (Iterator it = selectedNonResources.iterator(); it.hasNext();) {
+ Object element = (Object) it.next();
+ if (element instanceof ITypedElement) {
+ if (i > 0)
+ buf.append("\n"); //$NON-NLS-1$
+ buf.append(((ITypedElement)element).getName());
+ i++;
+ }
+ }
+ setClipboard(new IResource[0], null, buf.toString());
+ }
+
+ private void copyResources(List selectedResources) {
+ IResource[] resources = (IResource[]) selectedResources.toArray(new IResource[selectedResources.size()]);
+ // Get the file names and a string representation
+ final int length = resources.length;
+ int actualLength = 0;
+ String[] fileNames = new String[length];
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < length; i++) {
+ final IPath location = resources[i].getLocation();
+ // location may be null. See bug 29491.
+ if (location != null)
+ fileNames[actualLength++] = location.toOSString();
+ if (i > 0)
+ buf.append("\n"); //$NON-NLS-1$
+ buf.append(resources[i].getName());
+ }
+ // was one or more of the locations null?
+ if (actualLength < length) {
+ String[] tempFileNames = fileNames;
+ fileNames = new String[actualLength];
+ for (int i = 0; i < actualLength; i++)
+ fileNames[i] = tempFileNames[i];
+ }
+ setClipboard(resources, fileNames, buf.toString());
+ }
+
+ /**
+ * Set the clipboard contents. Prompt to retry if clipboard is busy.
+ *
+ * @param resources the resources to copy to the clipboard
+ * @param fileNames file names of the resources to copy to the clipboard
+ * @param names string representation of all names
+ */
private void setClipboard(IResource[] resources, String[] fileNames, String names) {
try {
// set the clipboard contents
- if (fileNames.length > 0) {
+ if (resources.length > 0 && fileNames.length > 0) {
fClipboard.setContents(new Object[] { resources, fileNames,
names },
new Transfer[] { ResourceTransfer.getInstance(),
FileTransfer.getInstance(),
TextTransfer.getInstance() });
- } else {
+ } else if(resources.length > 0 ) {
fClipboard.setContents(new Object[] { resources, names },
new Transfer[] { ResourceTransfer.getInstance(),
TextTransfer.getInstance() });
+ } else if(resources.length == 0) {
+ fClipboard.setContents(new Object[] { names },
+ new Transfer[] { TextTransfer.getInstance() });
}
} catch (SWTError e) {
if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
@@ -107,44 +133,51 @@ class CopyToClipboardAction extends SelectionListenerAction {
}
protected boolean updateSelection(IStructuredSelection selection) {
- if (!super.updateSelection(selection))
- return false;
-
- if (getSelectedNonResources().size() > 0)
- return false;
-
- List selectedResources = getSelectedResources();
- if (selectedResources.size() == 0)
- return false;
-
- boolean projSelected = selectionIsOfType(IResource.PROJECT);
- boolean fileFoldersSelected = selectionIsOfType(IResource.FILE
- | IResource.FOLDER);
- if (!projSelected && !fileFoldersSelected)
- return false;
-
- // selection must be homogeneous
- if (projSelected && fileFoldersSelected)
- return false;
-
- // must have a common parent
- IContainer firstParent = ((IResource) selectedResources.get(0))
- .getParent();
- if (firstParent == null)
- return false;
-
- Iterator resourcesEnum = selectedResources.iterator();
- while (resourcesEnum.hasNext()) {
- IResource currentResource = (IResource) resourcesEnum.next();
- if (!currentResource.getParent().equals(firstParent))
- return false;
- // resource location must exist
- if (currentResource.getLocation() == null)
- return false;
- }
-
- return true;
- }
+ if (!super.updateSelection(selection))
+ return false;
+ // Calling our own selection utility because the elements in the
+ // synchronize view can't adapt to IResource because we don't want the usual object
+ // contribution/ on them.
+ List selectedResources = getSelectedResources();
+ List selectedNonResources = getSelectedNonResources();
+ if (selectedResources.size() > 0 && selectedNonResources.size() == 0) {
+ boolean projSelected = selectionIsOfType(IResource.PROJECT);
+ boolean fileFoldersSelected = selectionIsOfType(IResource.FILE | IResource.FOLDER);
+ if (!projSelected && !fileFoldersSelected)
+ return false;
+ // selection must be homogeneous
+ if (projSelected && fileFoldersSelected)
+ return false;
+ // must have a common parent
+ IContainer firstParent = ((IResource) selectedResources.get(0)).getParent();
+ if (firstParent == null)
+ return false;
+ Iterator resourcesEnum = selectedResources.iterator();
+ while (resourcesEnum.hasNext()) {
+ IResource currentResource = (IResource) resourcesEnum.next();
+ if (!currentResource.getParent().equals(firstParent))
+ return false;
+ // resource location must exist
+ if (currentResource.getLocation() == null)
+ return false;
+ }
+ return true;
+ } else if (selectedNonResources.size() > 0 && selectedResources.size() == 0) {
+ return true;
+ }
+ return false;
+ }
+
+ protected List getSelectedNonResources() {
+ return Arrays.asList(Utils.getNonResources(getStructuredSelection().toArray()));
+ }
+
+ protected List getSelectedResources() {
+ // Calling our own selection utility because the elements in the
+ // synchronize view can't adapt to IResource because we don't want the usual object
+ // contribution/ on them.
+ return Arrays.asList(Utils.getResources(getStructuredSelection().toArray()));
+ }
public void dispose() {
fClipboard.dispose();
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java
index 90e7f11b1..8d8073033 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java
@@ -12,26 +12,17 @@ package org.eclipse.team.internal.ui.synchronize.actions;
import java.util.Iterator;
import java.util.List;
-
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.*;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.internal.ui.Policy;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.synchronize.ISynchronizePageSite;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.actions.ActionGroup;
-import org.eclipse.ui.actions.DeleteResourceAction;
-import org.eclipse.ui.actions.MoveResourceAction;
-import org.eclipse.ui.actions.RenameResourceAction;
+import org.eclipse.ui.*;
+import org.eclipse.ui.actions.*;
/**
* This action group is modeled after the class of the same name in
@@ -58,13 +49,14 @@ public class RefactorActionGroup extends ActionGroup {
final IStructuredSelection selection= getSelection();
final boolean anyResourceSelected = !selection.isEmpty() && allResourcesAreOfType(selection, IResource.PROJECT | IResource.FOLDER | IResource.FILE);
- if (anyResourceSelected) {
- copyAction.selectionChanged(selection);
+ // Actions can work on non-resource selections
+ copyAction.selectionChanged(getObjectSelection());
+ menu.add(copyAction);
+
+ if (anyResourceSelected) {
deleteAction.selectionChanged(selection);
moveAction.selectionChanged(selection);
renameAction.selectionChanged(selection);
-
- menu.add(copyAction);
menu.add(deleteAction);
menu.add(moveAction);
menu.add(renameAction);
@@ -81,7 +73,7 @@ public class RefactorActionGroup extends ActionGroup {
public void updateActionBars() {
final IStructuredSelection structuredSelection= getSelection();
- copyAction.selectionChanged(structuredSelection);
+ copyAction.selectionChanged(getObjectSelection());
deleteAction.selectionChanged(structuredSelection);
moveAction.selectionChanged(structuredSelection);
renameAction.selectionChanged(structuredSelection);
@@ -116,6 +108,15 @@ public class RefactorActionGroup extends ActionGroup {
return new StructuredSelection(Utils.getResources(((IStructuredSelection)selection).toArray()));
}
+
+ private IStructuredSelection getObjectSelection() {
+ final ISelection selection= getContext().getSelection();
+
+ if (!(selection instanceof IStructuredSelection))
+ return new StructuredSelection();
+
+ return (IStructuredSelection)selection;
+ }
private boolean allResourcesAreOfType(IStructuredSelection selection, int resourceMask) {
Iterator resources = selection.iterator();

Back to the top