blob: 4e2535851a45bb6fa5502c83fd1b0f78c790d808 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*******************************************************************************
* Copyright (c) 2004, 2009 Tasktop Technologies 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:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.ui.util;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.mylyn.internal.tasks.ui.actions.SaveAttachmentsAction;
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
/**
* @author Steffen Pingel
*/
public class TasksUiMenus {
public static void fillTaskAttachmentMenu(IMenuManager manager) {
final Action saveAction = new SaveAttachmentsAction(Messages.TasksUiMenus_Save_);
final Action copyURLToClipAction = new Action(Messages.TasksUiMenus_Copy_URL) {
@Override
public void run() {
ITaskAttachment attachment = AttachmentUtil.getSelectedAttachment();
if (attachment != null) {
Clipboard clip = new Clipboard(PlatformUI.getWorkbench().getDisplay());
clip.setContents(new Object[] { attachment.getUrl() },
new Transfer[] { TextTransfer.getInstance() });
clip.dispose();
}
}
@Override
public boolean isEnabled() {
ITaskAttachment attachment = AttachmentUtil.getSelectedAttachment();
if (attachment != null) {
return attachment.getUrl() != null;
}
return super.isEnabled();
}
};
final Action copyToClipAction = new Action(Messages.TasksUiMenus_Copy_Contents) {
@Override
public void run() {
ITaskAttachment attachment = AttachmentUtil.getSelectedAttachment();
if (attachment != null) {
CopyAttachmentToClipboardJob job = new CopyAttachmentToClipboardJob(attachment);
job.setUser(true);
job.schedule();
}
}
};
manager.add(new Separator("group.open")); //$NON-NLS-1$
manager.add(new Separator("group.save")); //$NON-NLS-1$
manager.add(saveAction);
manager.add(copyURLToClipAction);
manager.add(copyToClipAction);
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
}
|