Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 108563 Details for
Bug 242296
Add "Edit > Copy Qualified Name" action to Synchronize View
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
New action based off CopyToClipboardAction
org.eclipse.team.ui CopyQualifiedName patch.txt (text/plain), 15.45 KB, created by
Scott Cowan
on 2008-07-28 15:45:09 EDT
(
hide
)
Description:
New action based off CopyToClipboardAction
Filename:
MIME Type:
Creator:
Scott Cowan
Created:
2008-07-28 15:45:09 EDT
Size:
15.45 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.team.ui >Index: src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java,v >retrieving revision 1.18 >diff -u -r1.18 RefactorActionGroup.java >--- src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java 10 May 2006 17:47:28 -0000 1.18 >+++ src/org/eclipse/team/internal/ui/synchronize/actions/RefactorActionGroup.java 28 Jul 2008 19:43:39 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -33,6 +33,7 @@ > public class RefactorActionGroup extends ActionGroup { > > private CopyToClipboardAction copyAction; >+ private CopyQualifiedNameToClipboardAction copyQualifiedNameAction; > private MoveResourceAction moveAction; > private RenameResourceAction renameAction; > private ISynchronizePageSite site; >@@ -59,6 +60,8 @@ > // Actions can work on non-resource selections > copyAction.selectionChanged(getObjectSelection()); > menu.add(copyAction); >+ copyQualifiedNameAction.selectionChanged(getObjectSelection()); >+ menu.add(copyQualifiedNameAction); > > if (anyResourceSelected) { > deleteAction.selectionChanged(selection); >@@ -73,6 +76,7 @@ > > public void fillActionBars(IActionBars actionBars) { > actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction); >+ actionBars.setGlobalActionHandler("org.eclipse.team.ui.synchronize.action.copyQualifiedName", copyQualifiedNameAction); //$NON-NLS-1$ > actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), deleteAction); > actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction); > actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), moveAction); >@@ -81,6 +85,7 @@ > public void updateActionBars() { > final IStructuredSelection structuredSelection= getSelection(); > copyAction.selectionChanged(getObjectSelection()); >+ copyQualifiedNameAction.selectionChanged(getObjectSelection()); > deleteAction.selectionChanged(structuredSelection); > moveAction.selectionChanged(structuredSelection); > renameAction.selectionChanged(structuredSelection); >@@ -92,6 +97,7 @@ > final ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); > > copyAction= new CopyToClipboardAction(shell, navigatorContentService); >+ copyQualifiedNameAction= new CopyQualifiedNameToClipboardAction(shell, navigatorContentService); > moveAction= new MoveResourceAction(shell); > renameAction= new RenameResourceAction(shell); > deleteAction = new DeleteResourceAction(shell) { >@@ -103,6 +109,9 @@ > copyAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); > copyAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); > >+ copyQualifiedNameAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); >+ copyQualifiedNameAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); >+ > deleteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); > deleteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED)); > } >@@ -155,5 +164,6 @@ > public void dispose() { > super.dispose(); > copyAction.dispose(); >+ copyQualifiedNameAction.dispose(); > } > } >Index: src/org/eclipse/team/internal/ui/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties,v >retrieving revision 1.235 >diff -u -r1.235 messages.properties >--- src/org/eclipse/team/internal/ui/messages.properties 3 Apr 2008 14:51:41 -0000 1.235 >+++ src/org/eclipse/team/internal/ui/messages.properties 28 Jul 2008 19:43:39 -0000 >@@ -1,5 +1,5 @@ > ############################################################################### >-# Copyright (c) 2000, 2008 IBM Corporation and others. >+# Copyright (c) 2008 IBM Corporation and others. > # All rights reserved. This program and the accompanying materials > # are made available under the terms of the Eclipse Public License v1.0 > # which accompanies this distribution, and is available at >@@ -369,6 +369,10 @@ > CopyToClipboardAction_3=Problem Copying to Clipboard > CopyToClipboardAction_4=There was a problem when accessing the system clipboard. Retry? > >+CopyQualifiedNameToClipboardAction_1=Copy &Qualified Name >+CopyQualifiedNameToClipboardAction_2= Copy QualifiedName >+CopyQualifiedNameToClipboardAction_3=Problem Copying Qualified Name to Clipboard >+ > FlatModelProvider_6=Sort &Resources By > FlatModelProvider_7=&Name > FlatModelProvider_8=&Path >Index: src/org/eclipse/team/internal/ui/TeamUIMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIMessages.java,v >retrieving revision 1.68 >diff -u -r1.68 TeamUIMessages.java >--- src/org/eclipse/team/internal/ui/TeamUIMessages.java 3 Jun 2008 13:35:38 -0000 1.68 >+++ src/org/eclipse/team/internal/ui/TeamUIMessages.java 28 Jul 2008 19:43:39 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >+ * Copyright (c) 2008 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -519,6 +519,10 @@ > public static String CopyToClipboardAction_3; > public static String CopyToClipboardAction_4; > >+ public static String CopyQualifiedNameToClipboardAction_1; >+ public static String CopyQualifiedNameToClipboardAction_2; >+ public static String CopyQualifiedNameToClipboardAction_3; >+ > public static String FlatModelProvider_6; > public static String FlatModelProvider_7; > public static String FlatModelProvider_8; >Index: src/org/eclipse/team/internal/ui/synchronize/actions/CopyQualifiedNameToClipboardAction.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ui/synchronize/actions/CopyQualifiedNameToClipboardAction.java >diff -N src/org/eclipse/team/internal/ui/synchronize/actions/CopyQualifiedNameToClipboardAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ui/synchronize/actions/CopyQualifiedNameToClipboardAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,228 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ui.synchronize.actions; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.compare.ITypedElement; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.viewers.*; >+import org.eclipse.swt.SWTError; >+import org.eclipse.swt.dnd.*; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.team.internal.ui.*; >+import org.eclipse.ui.actions.SelectionListenerAction; >+import org.eclipse.ui.navigator.INavigatorContentService; >+import org.eclipse.ui.part.ResourceTransfer; >+ >+/** >+ * 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 CopyQualifiedNameToClipboardAction extends SelectionListenerAction { >+ >+ private static final String EOL = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ >+ >+ private static final String SEP = "/"; //$NON-NLS-1$ >+ >+ private final static String ID= TeamUIPlugin.PLUGIN_ID + ".synchronize.action.copytext"; //$NON-NLS-1$ >+ >+ private final Shell fShell; >+ private final Clipboard fClipboard; >+ >+ private final INavigatorContentService navigatorContentService; >+ >+ protected CopyQualifiedNameToClipboardAction(Shell shell, INavigatorContentService navigatorContentService) { >+ super(TeamUIMessages.CopyQualifiedNameToClipboardAction_1); >+ this.navigatorContentService = navigatorContentService; >+ Assert.isNotNull(shell); >+ fShell= shell; >+ fClipboard= new Clipboard(shell.getDisplay()); >+ setToolTipText(TeamUIMessages.CopyQualifiedNameToClipboardAction_2); >+ setId(ID); >+ } >+ >+ public void run() { >+ copyResources(getSelectedResources(), getTextualClipboardContents()); >+ } >+ >+ /* >+ * Return a text representation of all selected elements. >+ * Use the name from the tree node so what is copied >+ * matches what appears in the tree. >+ */ >+ private String getTextualClipboardContents() { >+ StringBuffer buf = new StringBuffer(); >+ int i = 0; >+ IStructuredSelection structuredSelection = getStructuredSelection(); >+ if (structuredSelection instanceof TreeSelection) { >+ TreeSelection ts = (TreeSelection) structuredSelection; >+ TreePath[] paths = ts.getPaths(); >+ for (int j = 0; j < paths.length; j++) { >+ TreePath path = paths[j]; >+ String qualifiedText = getQualifiedTextFor(path); >+ if (qualifiedText != null && qualifiedText.length() > 0) { >+ if (i > 0) >+ buf.append(EOL); >+ buf.append(qualifiedText); >+ i++; >+ } >+ } >+ } else { >+ for (Iterator it = structuredSelection.iterator(); it.hasNext();) { >+ Object element = it.next(); >+ if (element instanceof ITypedElement) { >+ if (i > 0) >+ buf.append(EOL); >+ buf.append(((ITypedElement)element).getName()); >+ i++; >+ } else { >+ IResource resource = Utils.getResource(element); >+ if (resource != null) { >+ if (i > 0) >+ buf.append(EOL); >+ buf.append(resource.getName()); >+ i++; >+ } >+ } >+ } >+ } >+ return buf.toString(); >+ } >+ >+ private String getQualifiedTextFor(TreePath path) { >+ StringBuffer qualifiedText = new StringBuffer(); >+ TreePath parentPath = path.getParentPath(); >+ if (parentPath != null) { >+ String parentText = getQualifiedTextFor(parentPath); >+ qualifiedText.append(parentText); >+ qualifiedText.append(SEP); >+ } >+ String pathText = getTextFor(path); >+ qualifiedText.append(pathText); >+ return qualifiedText.toString(); >+ } >+ >+ private String getTextFor(TreePath path) { >+ Object element = path.getLastSegment(); >+ if (element instanceof ITypedElement) { >+ return ((ITypedElement)element).getName(); >+ } >+ INavigatorContentService service = getNavigatorContentService(); >+ if (service != null) { >+ ILabelProvider provider = service.createCommonLabelProvider(); >+ if (provider instanceof ITreePathLabelProvider) { >+ ITreePathLabelProvider tplp = (ITreePathLabelProvider) provider; >+ ViewerLabel viewerLabel = new ViewerLabel("", null); //$NON-NLS-1$ >+ tplp.updateLabel(viewerLabel, path); >+ return viewerLabel.getText(); >+ } >+ return provider.getText(element); >+ } >+ if (element instanceof IResource) { >+ IResource resource = (IResource) element; >+ return resource.getName(); >+ } >+ return null; >+ } >+ >+ private INavigatorContentService getNavigatorContentService() { >+ return navigatorContentService; >+ } >+ >+ private void copyResources(List selectedResources, String text) { >+ 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]; >+ 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(); >+ } >+ // 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, text); >+ } >+ >+ /** >+ * 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 >+ List data = new ArrayList(); >+ List dataTypes = new ArrayList(); >+ if (resources.length > 0) { >+ data.add(resources); >+ dataTypes.add(ResourceTransfer.getInstance()); >+ } >+ if (fileNames.length > 0) { >+ data.add(fileNames); >+ dataTypes.add(FileTransfer.getInstance()); >+ } >+ if (names != null && names.length() > 0) { >+ data.add(names); >+ dataTypes.add(TextTransfer.getInstance()); >+ } >+ if (!data.isEmpty()) >+ fClipboard.setContents( >+ data.toArray(), >+ (Transfer[]) dataTypes.toArray(new Transfer[dataTypes.size()])); >+ } catch (SWTError e) { >+ if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) >+ throw e; >+ if (MessageDialog.openQuestion(fShell, TeamUIMessages.CopyQualifiedNameToClipboardAction_3, TeamUIMessages.CopyToClipboardAction_4)) >+ setClipboard(resources, fileNames, names); >+ } >+ } >+ >+ protected boolean updateSelection(IStructuredSelection selection) { >+ if (!super.updateSelection(selection)) >+ return false; >+ return true; >+ } >+ >+ 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(); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 242296
: 108563