Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2012-11-19 18:47:14 -0500
committerSam Davis2013-08-22 16:43:00 -0400
commit5dbe1d119010c4ebef52ec5300281cad07cc97bc (patch)
treeada45681fc7f5b90d3ae61bf4b4edb308044c271 /org.eclipse.mylyn.tasks.ui
parentdcdeca0f318eb14ede254e597a203a56e0e6c770 (diff)
downloadorg.eclipse.mylyn.tasks-5dbe1d119010c4ebef52ec5300281cad07cc97bc.tar.gz
org.eclipse.mylyn.tasks-5dbe1d119010c4ebef52ec5300281cad07cc97bc.tar.xz
org.eclipse.mylyn.tasks-5dbe1d119010c4ebef52ec5300281cad07cc97bc.zip
374458: open attachments with system editor
Change-Id: I3ff815347205b6377e76ad9ec27d2e3880d34734 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=374458
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui')
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskAttachmentViewer.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java6
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentBrowserViewer.java4
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentEditorViewer.java60
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewerManager.java34
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/commands/OpenTaskAttachmentWithMenu.java28
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties3
7 files changed, 119 insertions, 18 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskAttachmentViewer.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskAttachmentViewer.java
index e6bc072a7..6a082faa6 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskAttachmentViewer.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskAttachmentViewer.java
@@ -32,4 +32,6 @@ public interface ITaskAttachmentViewer {
public String getLabel();
public void openAttachment(IWorkbenchPage page, ITaskAttachment attachment) throws CoreException;
+
+ public boolean isWorkbenchDefault();
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java
index 7b2377f6f..7bbc1825a 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java
@@ -71,8 +71,14 @@ public class Messages extends NLS {
public static String TaskActivationExternalizationParticipant_Task_Activation_History;
+ public static String TaskAttachmentEditorViewer_Do_not_warn_me_again;
+
+ public static String TaskAttachmentEditorViewer_Open_Attachment;
+
public static String TaskAttachmentEditorViewer_openingAttachment;
+ public static String TaskAttachmentEditorViewer_Some_files_can_harm_your_computer;
+
public static String TaskAttachmentViewerBrowser_browser;
public static String TaskHistoryDropDown_Activate_Task_;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentBrowserViewer.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentBrowserViewer.java
index 92d1099df..f1bb01ca0 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentBrowserViewer.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentBrowserViewer.java
@@ -31,4 +31,8 @@ public class TaskAttachmentBrowserViewer implements ITaskAttachmentViewer {
TasksUiUtil.openUrl(attachment.getUrl());
}
+ public boolean isWorkbenchDefault() {
+ return false;
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentEditorViewer.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentEditorViewer.java
index 7fbfc7df8..41c389526 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentEditorViewer.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentEditorViewer.java
@@ -14,9 +14,13 @@ package org.eclipse.mylyn.internal.tasks.ui;
import java.text.MessageFormat;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.mylyn.commons.workbench.WorkbenchUtil;
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IWorkbenchPage;
@@ -25,10 +29,26 @@ import org.eclipse.ui.IWorkbenchPage;
*/
public class TaskAttachmentEditorViewer implements ITaskAttachmentViewer {
+ private static final String PREF_DO_NOT_WARN_BEFORE_OPENING_ATTACHMENTS = "do.not.warn.before.opening.attachments"; //$NON-NLS-1$
+
private final IEditorDescriptor descriptor;
+ private final boolean isWorkbenchDefault;
+
+ private final boolean isSystem;
+
TaskAttachmentEditorViewer(IEditorDescriptor descriptor) {
+ this(descriptor, false);
+ }
+
+ TaskAttachmentEditorViewer(IEditorDescriptor descriptor, boolean isWorkbenchDefault) {
+ this(descriptor, isWorkbenchDefault, false);
+ }
+
+ TaskAttachmentEditorViewer(IEditorDescriptor descriptor, boolean isWorkbenchDefault, boolean isSystem) {
this.descriptor = descriptor;
+ this.isWorkbenchDefault = isWorkbenchDefault;
+ this.isSystem = isSystem;
}
public String getId() {
@@ -40,10 +60,42 @@ public class TaskAttachmentEditorViewer implements ITaskAttachmentViewer {
}
public void openAttachment(final IWorkbenchPage page, final ITaskAttachment attachment) throws CoreException {
- DownloadAndOpenTaskAttachmentJob job = new DownloadAndOpenTaskAttachmentJob(
- MessageFormat.format(Messages.TaskAttachmentEditorViewer_openingAttachment,
- AttachmentUtil.getAttachmentFilename(attachment)), attachment, page, descriptor.getId());
- WorkbenchUtil.busyCursorWhile(job);
+ if (promptToConfirmOpen(attachment)) {
+ DownloadAndOpenTaskAttachmentJob job = new DownloadAndOpenTaskAttachmentJob(MessageFormat.format(
+ Messages.TaskAttachmentEditorViewer_openingAttachment,
+ AttachmentUtil.getAttachmentFilename(attachment)), attachment, page, descriptor.getId());
+ WorkbenchUtil.busyCursorWhile(job);
+ }
+ }
+
+ private boolean promptToConfirmOpen(final ITaskAttachment attachment) {
+ if (isSystem()) {
+ IPreferenceStore store = TasksUiPlugin.getDefault().getPreferenceStore();
+ if (!store.getBoolean(PREF_DO_NOT_WARN_BEFORE_OPENING_ATTACHMENTS)) {
+ MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
+ WorkbenchUtil.getShell(),
+ Messages.TaskAttachmentEditorViewer_Open_Attachment,
+ NLS.bind(Messages.TaskAttachmentEditorViewer_Some_files_can_harm_your_computer,
+ attachment.getFileName()), Messages.TaskAttachmentEditorViewer_Do_not_warn_me_again,
+ false, null, null);
+ if (dialog.getReturnCode() == IDialogConstants.YES_ID) {
+ if (dialog.getToggleState()) {
+ store.setValue(PREF_DO_NOT_WARN_BEFORE_OPENING_ATTACHMENTS, true);
+ TasksUiPlugin.getDefault().savePluginPreferences();
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+ return true;
}
+ public boolean isWorkbenchDefault() {
+ return isWorkbenchDefault;
+ }
+
+ protected boolean isSystem() {
+ return isSystem;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewerManager.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewerManager.java
index 0b568edd0..ce28336cb 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewerManager.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskAttachmentViewerManager.java
@@ -15,6 +15,7 @@ package org.eclipse.mylyn.internal.tasks.ui;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
@@ -41,7 +42,7 @@ public class TaskAttachmentViewerManager {
IEditorDescriptor defaultEditor = registry.getDefaultEditor(AttachmentUtil.getAttachmentFilename(attachment));
if (defaultEditor != null) {
- result.add(new TaskAttachmentEditorViewer(defaultEditor));
+ result.add(new TaskAttachmentEditorViewer(defaultEditor, true));
}
IEditorDescriptor defaultTextEditor = registry.findEditor(EditorsUI.DEFAULT_TEXT_EDITOR_ID); // may be null
@@ -67,11 +68,11 @@ public class TaskAttachmentViewerManager {
// Don't check whether system external editor is available (IEditorRegistry.isSystemExternalEditorAvailable) ...
// At least Windows can handle even unknown files, and offers user to choose correct program to open file with
IEditorDescriptor extern = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
- result.add(new TaskAttachmentEditorViewer(extern));
+ result.add(new TaskAttachmentEditorViewer(extern, false, true));
if (registry.isSystemInPlaceEditorAvailable(AttachmentUtil.getAttachmentFilename(attachment))) {
IEditorDescriptor inplace = registry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
- result.add(new TaskAttachmentEditorViewer(inplace));
+ result.add(new TaskAttachmentEditorViewer(inplace, false, true));
}
return result;
@@ -93,22 +94,27 @@ public class TaskAttachmentViewerManager {
* @return preferred attachment viewers, or null if no suitable viewer can be found
*/
public ITaskAttachmentViewer getPreferredViewer(ITaskAttachment attachment) {
+ /*
+ * Find viewers in order of preference: preferred, workbench default, system editor, first editor in list
+ */
List<ITaskAttachmentViewer> viewers = getTaskAttachmentViewers(attachment);
-
+ ITaskAttachmentViewer defaultViewer = null;
String preferred = getPreferredViewerID(attachment);
- if (preferred != null) {
- for (int i = 0; i < viewers.size(); i++) {
- if (preferred.equals(viewers.get(i).getId())) {
- return viewers.get(i);
- }
+ for (ITaskAttachmentViewer viewer : viewers) {
+ if ((preferred != null && preferred.equals(viewer.getId()))) {
+ return viewer;
+ } else if (viewer.isWorkbenchDefault()) {
+ defaultViewer = viewer;
+ } else if (defaultViewer == null && Platform.getOS().equals(Platform.OS_WIN32)
+ && IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID.equals(viewer.getId())) {
+ defaultViewer = viewer;
}
}
-
- if (viewers.isEmpty()) {
- return null;
+ if (defaultViewer == null && !viewers.isEmpty()) {
+ defaultViewer = viewers.get(0);
}
- return viewers.get(0);
+ return defaultViewer;
}
public String getPreferredViewerID(ITaskAttachment attachment) {
@@ -118,7 +124,7 @@ public class TaskAttachmentViewerManager {
}
return getPreferencesStore().getString(
- ITasksUiPreferenceConstants.PREFERRED_TASK_ATTACHMENT_VIEWER_ID + "_" + ext); //$NON-NLS-1$
+ ITasksUiPreferenceConstants.PREFERRED_TASK_ATTACHMENT_VIEWER_ID + "_" + ext);//$NON-NLS-1$
}
private IPreferenceStore getPreferencesStore() {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/commands/OpenTaskAttachmentWithMenu.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/commands/OpenTaskAttachmentWithMenu.java
index bab91be17..ecae84dae 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/commands/OpenTaskAttachmentWithMenu.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/commands/OpenTaskAttachmentWithMenu.java
@@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.mylyn.internal.tasks.ui.ITaskAttachmentViewer;
import org.eclipse.mylyn.internal.tasks.ui.TaskAttachmentViewerManager;
@@ -27,6 +28,7 @@ import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
@@ -63,11 +65,17 @@ public class OpenTaskAttachmentWithMenu extends ContributionItem {
index += itemsAdded;
}
+ int defaultViewerIndex = -1;
List<ITaskAttachmentViewer> viewers = manager.getWorkbenchViewers(attachment);
if (viewers.size() > 0) {
itemsAdded = addSeparator(menu, index, itemsAdded);
index += itemsAdded;
+ for (int i = 0; i < viewers.size(); i++) {
+ if (viewers.get(i).isWorkbenchDefault()) {
+ defaultViewerIndex = index + i;
+ }
+ }
itemsAdded = addItems(menu, index, viewers, attachments, viewerId);
index += itemsAdded;
}
@@ -77,9 +85,29 @@ public class OpenTaskAttachmentWithMenu extends ContributionItem {
itemsAdded = addSeparator(menu, index, itemsAdded);
index += itemsAdded;
+ if (defaultViewerIndex == -1 && Platform.getOS().equals(Platform.OS_WIN32)) {
+ for (int i = 0; i < viewers.size(); i++) {
+ if (IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID.equals(viewers.get(i).getId())) {
+ defaultViewerIndex = index + i;
+ }
+ }
+ }
itemsAdded = addItems(menu, index, viewers, attachments, viewerId);
index += itemsAdded;
}
+ if (defaultViewerIndex != -1) {
+ boolean selectedPreferredViewer = false;
+ for (MenuItem item : menu.getItems()) {
+ if (item.getSelection()) {
+ selectedPreferredViewer = true;
+ break;
+ }
+ }
+ if (!selectedPreferredViewer) {
+ menu.getItem(defaultViewerIndex).setSelection(true);
+ }
+ }
+
}
protected int addSeparator(Menu menu, int index, int itemsAdded) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties
index cb13d7820..ad28d642f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties
@@ -98,5 +98,8 @@ TaskHyperlink_Open_Task_X_in_X=Open Task {0} in {1}
AbstractRetrieveTitleFromUrlJob_Retrieving_summary_from_URL=Retrieving summary from URL
FileStorage_unableToReadAttachmentFile=Unable to read attachment file
+TaskAttachmentEditorViewer_Do_not_warn_me_again=Do not warn me again
+TaskAttachmentEditorViewer_Open_Attachment=Open Attachment
TaskAttachmentEditorViewer_openingAttachment=Opening attachment {0}
+TaskAttachmentEditorViewer_Some_files_can_harm_your_computer=Some files can harm your computer when opened. Are you sure you want to open {0}?
TaskAttachmentViewerBrowser_browser=Browser

Back to the top