1
/*******************************************************************************
2
* Copyright (c) 2008, 2009 Andrew Gvozdev.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Andrew Gvozdev (Quoin Inc.) - Initial implementation
10
*******************************************************************************/
12
package org.eclipse.cdt.make.ui.views;
14
import org.eclipse.cdt.make.core.IMakeTarget;
15
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
16
import org.eclipse.cdt.make.internal.ui.dnd.MakeTargetDndUtil;
17
import org.eclipse.cdt.make.internal.ui.dnd.MakeTargetTransfer;
18
import org.eclipse.cdt.make.internal.ui.dnd.MakeTargetTransferData;
19
import org.eclipse.cdt.make.internal.ui.dnd.TextTransferDragSourceListener;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.swt.SWTError;
22
import org.eclipse.swt.dnd.Clipboard;
23
import org.eclipse.swt.dnd.TextTransfer;
24
import org.eclipse.swt.dnd.Transfer;
25
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.ui.ISharedImages;
27
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.actions.SelectionListenerAction;
31
* Action to copy make targets from Make Target View to clipboard.
32
* {@link CopyTargetAction} can transfer targets as {@link IMakeTarget}s or
35
* {@link CopyTargetAction} and {@link PasteTargetAction} are able to transfer
36
* targets inside Make Target View or between eclipse sessions.
39
public class CopyTargetAction extends SelectionListenerAction {
41
private final Shell shell;
42
private final Clipboard clipboard;
43
private final PasteTargetAction pasteAction;
46
* Constructor setting internal private fields and initializing the action.
48
* @param shell - the shell in which to show any dialogs.
49
* @param clipboard - system clipboard.
50
* @param pasteAction -associated paste action. May be {@code null}.
52
protected CopyTargetAction(Shell shell, Clipboard clipboard, PasteTargetAction pasteAction) {
53
super(MakeUIPlugin.getResourceString("CopyTargetAction.label")); //$NON-NLS-1$
55
this.clipboard = clipboard;
56
this.pasteAction = pasteAction;
58
ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
59
setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
60
setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
61
setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
63
setToolTipText(MakeUIPlugin.getResourceString("CopyTargetAction.tooltip")); //$NON-NLS-1$
67
* Updates enablement of this action in response to the given selection.
70
protected boolean updateSelection(IStructuredSelection selection) {
71
if (!super.updateSelection(selection)) {
75
return MakeTargetDndUtil.isDragable(selection);
79
* Perform actual action of copying of make targets to clipboard. Two
80
* transfer agents are initiated, {@link MakeTargetTransfer} and
81
* {@link TextTransfer}.
85
IStructuredSelection selection = getStructuredSelection();
87
MakeTargetTransferData makeTargetTransferData = new MakeTargetTransferData();
88
for (Object selectionItem : selection.toList()) {
89
if (selectionItem instanceof IMakeTarget) {
90
makeTargetTransferData.addMakeTarget((IMakeTarget) selectionItem);
95
clipboard.setContents(new Object[] { makeTargetTransferData,
96
TextTransferDragSourceListener.convertSelectedMakeTargetsToText(selection) },
97
new Transfer[] { MakeTargetTransfer.getInstance(), TextTransfer.getInstance() });
99
// update the enablement of the paste action
100
if (pasteAction != null && pasteAction.getStructuredSelection() != null) {
101
pasteAction.selectionChanged(pasteAction.getStructuredSelection());
104
} catch (SWTError e) {
105
MakeUIPlugin.errorDialog(shell,
106
MakeUIPlugin.getResourceString("CopyTargetAction.title.clipboardProblem"), //$NON-NLS-1$
107
MakeUIPlugin.getResourceString("CopyTargetAction.message.clipboardProblem"), //$NON-NLS-1$