diff options
author | Michael Valenta | 2003-09-04 18:01:11 +0000 |
---|---|---|
committer | Michael Valenta | 2003-09-04 18:01:11 +0000 |
commit | 5c50d737e5cc5ab57cc3f5ad5b956ec823f56fcc (patch) | |
tree | ecaba63b2c597c599a934388654dddf78a501b89 /bundles/org.eclipse.team.ui/src/org/eclipse/team | |
parent | 49eebb1ae8e756f01a7b1c596dd2b1305d2cb283 (diff) | |
download | eclipse.platform.team-5c50d737e5cc5ab57cc3f5ad5b956ec823f56fcc.tar.gz eclipse.platform.team-5c50d737e5cc5ab57cc3f5ad5b956ec823f56fcc.tar.xz eclipse.platform.team-5c50d737e5cc5ab57cc3f5ad5b956ec823f56fcc.zip |
19598: [CVS Sync View] Delete File should be an option in Structure compare
Diffstat (limited to 'bundles/org.eclipse.team.ui/src/org/eclipse/team')
6 files changed, 643 insertions, 22 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties index c0c3369e9..d80011663 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties @@ -401,3 +401,11 @@ SyncViewerPreferencePage.15=Perspective Switching RefreshSubscriberJob.1=Team refresh {0} folders for {1} RefreshSubscriberJob.0=An error occured while synchronizing with remote contents. + +CopyAction.title=&Copy +CopyAction.toolTip=Copy +CopyAction.errorTitle=Problem Copying to Clipboard +CopyAction.errorMessage=There was a problem when accessing the system clipboard. Retry? +PasteAction.title=&Paste +PasteAction.toolTip=Paste +RefactorActionGroup.0=Edi&t diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/CopyAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/CopyAction.java new file mode 100644 index 000000000..5646fe56f --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/CopyAction.java @@ -0,0 +1,209 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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.sync.actions; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.dialogs.MessageDialog; +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.widgets.Shell; +import org.eclipse.team.internal.core.Assert; +import org.eclipse.team.internal.ui.Policy; +import org.eclipse.team.internal.ui.TeamUIPlugin; +import org.eclipse.ui.actions.SelectionListenerAction; +import org.eclipse.ui.part.ResourceTransfer; + +/** + * This action is a copy of the copy action in org.eclipse.ui.views.navigator + * (which is not visible) + */ +public class CopyAction extends SelectionListenerAction { + + /** + * The id of this action. + */ + public static final String ID = TeamUIPlugin.ID + ".CopyAction"; //$NON-NLS-1$ + + /** + * The shell in which to show any dialogs. + */ + private Shell shell; + + /** + * System clipboard + */ + private Clipboard clipboard; + + /** + * Associated paste action. May be <code>null</code> + */ + private PasteAction pasteAction; + + /** + * Creates a new action. + * + * @param shell the shell for any dialogs + * @param clipboard a platform clipboard + */ + public CopyAction(Shell shell, Clipboard clipboard) { + super(Policy.bind("CopyAction.title")); //$NON-NLS-1$ + Assert.isNotNull(shell); + Assert.isNotNull(clipboard); + this.shell = shell; + this.clipboard = clipboard; + setToolTipText(Policy.bind("CopyAction.toolTip")); //$NON-NLS-1$ + setId(CopyAction.ID); + //WorkbenchHelp.setHelp(this, INavigatorHelpContextIds.COPY_ACTION); + } + /** + * Creates a new action. + * + * @param shell the shell for any dialogs + * @param clipboard a platform clipboard + * @param pasteAction a paste action + * + * @since 2.0 + */ + public CopyAction(Shell shell, Clipboard clipboard, PasteAction pasteAction) { + this(shell, clipboard); + this.pasteAction = pasteAction; + } + /** + * The <code>CopyAction</code> implementation of this method defined + * on <code>IAction</code> copies the selected resources to the + * clipboard. + */ + 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++) { + 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()); + + // update the enablement of the paste action + // workaround since the clipboard does not suppot callbacks + if (pasteAction != null && pasteAction.getStructuredSelection() != null) + pasteAction.selectionChanged(pasteAction.getStructuredSelection()); + } + /** + * 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) { + clipboard.setContents( + new Object[]{ + resources, + fileNames, + names}, + new Transfer[]{ + ResourceTransfer.getInstance(), + FileTransfer.getInstance(), + TextTransfer.getInstance()}); + } else { + clipboard.setContents( + new Object[]{ + resources, + names}, + new Transfer[]{ + ResourceTransfer.getInstance(), + TextTransfer.getInstance()}); + } + } catch (SWTError e){ + if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) + throw e; + if (MessageDialog.openQuestion(shell, Policy.bind("CopyAction.errorTitle"), Policy.bind("CopyAction.errorMessage"))) //$NON-NLS-1$ //$NON-NLS-2$ + setClipboard(resources, fileNames, names); + } + } + /** + * The <code>CopyAction</code> implementation of this + * <code>SelectionListenerAction</code> method enables this action if + * one or more resources of compatible types are selected. + */ + 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(); + // resource must exist + if (!currentResource.exists()) + return false; + // ensure common parent + if (!currentResource.getParent().equals(firstParent)) + return false; + // resource location must exist + if (currentResource.getLocation() == null) + return false; + } + + return true; + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/PasteAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/PasteAction.java new file mode 100644 index 000000000..11d865121 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/PasteAction.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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.sync.actions; + +import java.util.List; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.TransferData; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.team.internal.core.Assert; +import org.eclipse.team.internal.ui.Policy; +import org.eclipse.team.internal.ui.TeamUIPlugin; +import org.eclipse.ui.actions.CopyFilesAndFoldersOperation; +import org.eclipse.ui.actions.CopyProjectOperation; +import org.eclipse.ui.actions.SelectionListenerAction; +import org.eclipse.ui.part.ResourceTransfer; + +/** + * This action is a copy of the paste action in org.eclipse.ui.views.navigator + * (which is not visible) + */ +public class PasteAction extends SelectionListenerAction { + + /** + * The id of this action. + */ + public static final String ID = TeamUIPlugin.ID + ".PasteAction";//$NON-NLS-1$ + + /** + * The shell in which to show any dialogs. + */ + private Shell shell; + + /** + * System clipboard + */ + private Clipboard clipboard; + + /** + * Creates a new action. + * + * @param shell the shell for any dialogs + */ + public PasteAction(Shell shell, Clipboard clipboard) { + super(Policy.bind("PasteAction.title")); //$NON-NLS-1$ + Assert.isNotNull(shell); + Assert.isNotNull(clipboard); + this.shell = shell; + this.clipboard = clipboard; + setToolTipText(Policy.bind("PasteAction.toolTip")); //$NON-NLS-1$ + setId(PasteAction.ID); + // WorkbenchHelp.setHelp(this, INavigatorHelpContextIds.PASTE_ACTION); + } + /** + * Returns the actual target of the paste action. Returns null + * if no valid target is selected. + * + * @return the actual target of the paste action + */ + private IResource getTarget() { + List selectedResources = getSelectedResources(); + + for (int i = 0; i < selectedResources.size(); i++) { + IResource resource = (IResource)selectedResources.get(i); + + if (resource instanceof IProject && !((IProject)resource).isOpen()) + return null; + if (resource.getType() == IResource.FILE) + resource = resource.getParent(); + if (resource != null) + return resource; + } + return null; + } + /** + * Returns whether any of the given resources are linked resources. + * + * @param resources resource to check for linked type. may be null + * @return true=one or more resources are linked. false=none of the + * resources are linked + */ + private boolean isLinked(IResource[] resources) { + for (int i = 0; i < resources.length; i++) { + if (resources[i].isLinked()) + return true; + } + return false; + } + /** + * Implementation of method defined on <code>IAction</code>. + */ + public void run() { + // try a resource transfer + ResourceTransfer resTransfer = ResourceTransfer.getInstance(); + IResource[] resourceData = (IResource[])clipboard.getContents(resTransfer); + + if (resourceData != null && resourceData.length > 0) { + if (resourceData[0].getType() == IResource.PROJECT) { + // enablement checks for all projects + for (int i = 0; i < resourceData.length; i++) { + CopyProjectOperation operation = new CopyProjectOperation(this.shell); + operation.copyProject((IProject) resourceData[i]); + } + } else { + // enablement should ensure that we always have access to a container + IContainer container = getContainer(); + + CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(this.shell); + operation.copyResources(resourceData, container); + } + return; + } + + // try a file transfer + FileTransfer fileTransfer = FileTransfer.getInstance(); + String[] fileData = (String[])clipboard.getContents(fileTransfer); + + if (fileData != null) { + // enablement should ensure that we always have access to a container + IContainer container = getContainer(); + + CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(this.shell); + operation.copyFiles(fileData, container); + } + } + /** + * Returns the container to hold the pasted resources. + */ + private IContainer getContainer() { + List selection = getSelectedResources(); + if (selection.get(0) instanceof IFile) + return ((IFile)selection.get(0)).getParent(); + else + return (IContainer)selection.get(0); + } + /** + * The <code>PasteAction</code> implementation of this + * <code>SelectionListenerAction</code> method enables this action if + * a resource compatible with what is on the clipboard is selected. + * + * -Clipboard must have IResource or java.io.File + * -Projects can always be pasted if they are open + * -Workspace folder may not be copied into itself + * -Files and folders may be pasted to a single selected folder in open + * project or multiple selected files in the same folder + */ + protected boolean updateSelection(IStructuredSelection selection) { + if (!super.updateSelection(selection)) + return false; + + // clipboard must have resources or files + ResourceTransfer resTransfer = ResourceTransfer.getInstance(); + IResource[] resourceData = (IResource[])clipboard.getContents(resTransfer); + boolean isProjectRes = resourceData != null + && resourceData.length > 0 + && resourceData[0].getType() == IResource.PROJECT; + + if (isProjectRes) { + for (int i = 0; i < resourceData.length; i++) { + // make sure all resource data are open projects + // can paste open projects regardless of selection + if (resourceData[i].getType() != IResource.PROJECT || ((IProject) resourceData[i]).isOpen() == false) + return false; + } + return true; + } + + if (getSelectedNonResources().size() > 0) + return false; + + IResource targetResource = getTarget(); + // targetResource is null if no valid target is selected (e.g., open project) + // or selection is empty + if (targetResource == null) + return false; + + // can paste files and folders to a single selection (file, folder, + // open project) or multiple file selection with the same parent + List selectedResources = getSelectedResources(); + if (selectedResources.size() > 1) { + for (int i = 0; i < selectedResources.size(); i++) { + IResource resource = (IResource)selectedResources.get(i); + if (resource.getType() != IResource.FILE) + return false; + if (!targetResource.equals(resource.getParent())) + return false; + } + } + if (resourceData != null) { + // linked resources can only be pasted into projects + if (isLinked(resourceData) && targetResource.getType() != IResource.PROJECT) + return false; + + if (targetResource.getType() == IResource.FOLDER) { + // don't try to copy folder to self + for (int i = 0; i < resourceData.length; i++) { + if (targetResource.equals(resourceData[i])) + return false; + } + } + return true; + } + TransferData[] transfers = clipboard.getAvailableTypes(); + FileTransfer fileTransfer = FileTransfer.getInstance(); + for (int i = 0; i < transfers.length; i++) { + if (fileTransfer.isSupportedType(transfers[i])) + return true; + } + return false; + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefactorActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefactorActionGroup.java new file mode 100644 index 000000000..749590e98 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefactorActionGroup.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 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.sync.actions; + +import java.util.Iterator; + +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.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.team.internal.ui.sync.views.SynchronizeView; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.DeleteResourceAction; +import org.eclipse.ui.actions.MoveResourceAction; +import org.eclipse.ui.actions.RenameResourceAction; +import org.eclipse.ui.actions.TextActionHandler; +import org.eclipse.team.internal.ui.Policy; + +/** + * This action group is modeled after the class of the same name in + * the org.eclipse.ui.workbench plugin. We couldn't reuse that class + * because of a hard dependency on the navigator. + */ +public class RefactorActionGroup extends SyncViewerActionGroup { + + private Clipboard clipboard; + + private CopyAction copyAction; + private DeleteResourceAction deleteAction; + private PasteAction pasteAction; + private MoveResourceAction moveAction; + private RenameResourceAction renameAction; + private TextActionHandler textActionHandler; + + protected RefactorActionGroup(SynchronizeView syncView) { + super(syncView); + makeActions(); + } + + public void dispose() { + if (clipboard != null) { + clipboard.dispose(); + clipboard = null; + } + super.dispose(); + } + + public void fillContextMenu(IMenuManager parentMenu) { + IStructuredSelection selection = getSelection(); + + boolean anyResourceSelected = + !selection.isEmpty() + && allResourcesAreOfType( + selection, + IResource.PROJECT | IResource.FOLDER | IResource.FILE); + + MenuManager menu = new MenuManager(Policy.bind("RefactorActionGroup.0")); //$NON-NLS-1$ + copyAction.selectionChanged(selection); + menu.add(copyAction); + pasteAction.selectionChanged(selection); + menu.add(pasteAction); + + if (anyResourceSelected) { + deleteAction.selectionChanged(selection); + menu.add(deleteAction); + moveAction.selectionChanged(selection); + menu.add(moveAction); + renameAction.selectionChanged(selection); + menu.add(renameAction); + } + parentMenu.add(menu); + } + + public void fillActionBars(IActionBars actionBars) { + textActionHandler = new TextActionHandler(actionBars); // hooks handlers + textActionHandler.setCopyAction(copyAction); + textActionHandler.setPasteAction(pasteAction); + textActionHandler.setDeleteAction(deleteAction); + renameAction.setTextActionHandler(textActionHandler); + + actionBars.setGlobalActionHandler(IWorkbenchActionConstants.MOVE, moveAction); + actionBars.setGlobalActionHandler(IWorkbenchActionConstants.RENAME, renameAction); + actionBars.setGlobalActionHandler(IWorkbenchActionConstants.DELETE, deleteAction); + } + + /** + * Handles a key pressed event by invoking the appropriate action. + */ + public void handleKeyPressed(KeyEvent event) { + if (event.character == SWT.DEL && event.stateMask == 0) { + if (deleteAction.isEnabled()) { + deleteAction.run(); + } + } + } + + protected void makeActions() { + Shell shell = getSyncView().getSite().getShell(); + clipboard = new Clipboard(shell.getDisplay()); + + pasteAction = new PasteAction(shell, clipboard); + ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); + pasteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED)); + pasteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); + pasteAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_HOVER)); + + copyAction = new CopyAction(shell, clipboard, pasteAction); + copyAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED)); + copyAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); + copyAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_HOVER)); + + moveAction = new MoveResourceAction(shell); + renameAction = new RenameResourceAction(shell); + + deleteAction = new DeleteResourceAction(shell); + deleteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED)); + deleteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); + deleteAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_HOVER)); + } + + public void updateActionBars() { + IStructuredSelection selection = getSelection(); + copyAction.selectionChanged(selection); + pasteAction.selectionChanged(selection); + deleteAction.selectionChanged(selection); + moveAction.selectionChanged(selection); + renameAction.selectionChanged(selection); + } + + private IStructuredSelection getSelection() { + return (IStructuredSelection)getSyncView().getSelection(); + } + + private boolean allResourcesAreOfType(IStructuredSelection selection, int resourceMask) { + Iterator resources = selection.iterator(); + while (resources.hasNext()) { + Object next = resources.next(); + IResource resource = null; + if (next instanceof IResource) { + resource = (IResource)next; + } else if (next instanceof IAdaptable) { + IAdaptable adaptable = (IAdaptable)next; + resource = (IResource)adaptable.getAdapter(IResource.class); + } + if (resource == null || (resource.getType() & resourceMask) == 0) { + return false; + } + } + return true; + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerActions.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerActions.java index 1dcc26605..4f0eaa6b9 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerActions.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerActions.java @@ -17,6 +17,7 @@ import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.events.KeyEvent; import org.eclipse.team.core.TeamException; import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.internal.ui.sync.sets.SubscriberInput; @@ -49,6 +50,8 @@ public class SyncViewerActions extends SyncViewerActionGroup { private SyncViewerToolbarDropDownAction chooseSubscriberAction; private SyncViewerToolbarDropDownAction chooseChangeFilterAction; + private RefactorActionGroup refactoringActions; + // other view actions private Action collapseAll; private Action refreshSelectionAction; @@ -66,6 +69,7 @@ public class SyncViewerActions extends SyncViewerActionGroup { directionsFilters.updateActionBars(); comparisonCriteria.updateActionBars(); subscriberInputs.updateActionBars(); + refactoringActions.updateActionBars(); expandAll.update(); } @@ -159,6 +163,7 @@ public class SyncViewerActions extends SyncViewerActionGroup { }; workingSetGroup = new WorkingSetFilterActionGroup(syncView.getSite().getShell(), workingSetUpdater); openWithActionGroup = new OpenWithActionGroup(getSyncView()); + refactoringActions = new RefactorActionGroup(getSyncView()); } /* (non-Javadoc) @@ -181,6 +186,8 @@ public class SyncViewerActions extends SyncViewerActionGroup { dropDownMenu.add(refreshViewContents); dropDownMenu.add(new Separator()); dropDownMenu.add(new SyncViewerShowPreferencesAction(getSyncView().getSite().getShell())); + + refactoringActions.fillActionBars(actionBars); } /* (non-Javadoc) @@ -192,6 +199,8 @@ public class SyncViewerActions extends SyncViewerActionGroup { manager.add(new Separator()); manager.add(expandAll); manager.add(new Separator()); + refactoringActions.fillContextMenu(manager); + manager.add(new Separator()); manager.add(refreshSelectionAction); manager.add(new Separator("SubscriberActionsGroup1")); //$NON-NLS-1$ manager.add(new Separator("SubscriberActionsGroup2")); //$NON-NLS-1$ @@ -289,4 +298,8 @@ public class SyncViewerActions extends SyncViewerActionGroup { } workingSetGroup.setWorkingSet(workingSet); } + + public void handleKeyPressed(KeyEvent event) { + refactoringActions.handleKeyPressed(event); + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SynchronizeView.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SynchronizeView.java index 14b141c70..06c54cb88 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SynchronizeView.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SynchronizeView.java @@ -11,12 +11,9 @@ package org.eclipse.team.internal.ui.sync.views; import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.Map; -import java.util.Set; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.NullProgressMonitor; @@ -40,12 +37,13 @@ import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.OpenEvent; import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.TableLayout; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; @@ -59,7 +57,6 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.team.core.TeamException; import org.eclipse.team.core.subscribers.ITeamResourceChangeListener; -import org.eclipse.team.core.subscribers.SyncInfo; import org.eclipse.team.core.subscribers.TeamDelta; import org.eclipse.team.core.subscribers.TeamSubscriber; import org.eclipse.team.internal.core.Assert; @@ -184,7 +181,7 @@ public class SynchronizeView extends ViewPart implements ITeamResourceChangeList updateTitle(); initializeJobListener(); - actions.setContext(null); + actions.setContext(null); } /* (non-Javadoc) * @see org.eclipse.ui.IViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento) @@ -301,6 +298,14 @@ public class SynchronizeView extends ViewPart implements ITeamResourceChangeList handleOpen(event); } }); + viewer.getControl().addKeyListener(new KeyListener() { + public void keyPressed(KeyEvent event) { + handleKeyPressed(event); + } + public void keyReleased(KeyEvent event) { + // do nothing + } + }); } protected void initializeActions() { actions = new SyncViewerActions(this); @@ -449,6 +454,14 @@ public class SynchronizeView extends ViewPart implements ITeamResourceChangeList } + /** + * Handles a key press event from the viewer. + * Delegates to the action group. + */ + protected void handleKeyPressed(KeyEvent event) { + actions.handleKeyPressed(event); + } + public void activateSubscriber(TeamSubscriber subscriber) { SubscriberInput newInput = (SubscriberInput)subscriberInputs.get(subscriber.getId()); if (newInput == null) { @@ -637,22 +650,7 @@ public class SynchronizeView extends ViewPart implements ITeamResourceChangeList } public ISelection getSelection() { - ISelection selection = getViewer().getSelection(); - if (! selection.isEmpty() && viewer instanceof AbstractTreeViewer) { - // For a tree, selection should be deep and only include out-of-sync resources - Object[] selected = ((IStructuredSelection)selection).toArray(); - Set result = new HashSet(); - for (int i = 0; i < selected.length; i++) { - Object object = selected[i]; - if (object instanceof SynchronizeViewNode) { - SynchronizeViewNode syncResource = (SynchronizeViewNode) object; - SyncInfo[] infos = syncResource.getChildSyncInfos(); - result.addAll(Arrays.asList(infos)); - } - } - selection = new StructuredSelection((Object[]) result.toArray(new Object[result.size()])); - } - return selection; + return getViewer().getSelection(); } /** |