mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
[376535] RSE does not respect editor overrides
This commit is contained in:
parent
12ddebecd2
commit
d222f9cf3b
3 changed files with 95 additions and 6 deletions
|
@ -44,6 +44,7 @@
|
|||
* David McKnight (IBM) - [334839] File Content Conflict is not handled properly
|
||||
* David McKnight (IBM) - [249031] Last used editor should be set to SystemEditableRemoteFile
|
||||
* David McKnight (IBM) - [359704] SystemEditableRemoteFile does not release reference to editor
|
||||
* Rick Sawyer (IBM) - [376535] RSE does not respect editor overrides
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.files.ui.resources;
|
||||
|
@ -132,6 +133,7 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
private IEditorPart editor;
|
||||
private IFile localFile;
|
||||
private IWorkbenchPage page;
|
||||
private boolean _usingDefaultDescriptor = false;
|
||||
|
||||
/**
|
||||
* Internal class for downloading file
|
||||
|
@ -276,6 +278,10 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
IEditorDescriptor descriptor = null;
|
||||
try {
|
||||
descriptor = IDE.getEditorDescriptor(localResource);
|
||||
|
||||
if (!localResource.exists()){
|
||||
_usingDefaultDescriptor = true;
|
||||
}
|
||||
} catch (PartInitException e) {
|
||||
}
|
||||
|
||||
|
@ -1646,8 +1652,15 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
|
||||
// set editor as preferred editor for this file
|
||||
String editorId = null;
|
||||
if (_editorDescriptor != null)
|
||||
editorId = _editorDescriptor.getId();
|
||||
if (_editorDescriptor != null){
|
||||
if (_usingDefaultDescriptor){
|
||||
_editorDescriptor = IDE.getEditorDescriptor(file);
|
||||
editorId = _editorDescriptor.getId();
|
||||
}
|
||||
else {
|
||||
editorId = _editorDescriptor.getId();
|
||||
}
|
||||
}
|
||||
|
||||
IDE.setDefaultEditor(file, editorId);
|
||||
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
* David McKnight (IBM) - [284596] [regression] Open with-> problem when descriptor doesn't match previous
|
||||
* David McKnight (IBM) - [309755] SystemRemoteFileOpenWithMenu.getPreferredEditor(), the listed default editor is not always correct
|
||||
* David McKnight (IBM) - [312362] Editing Unix file after it changes on host edits old data
|
||||
* Rick Sawyer (IBM) - [376535] RSE does not respect editor overrides
|
||||
*******************************************************************************/
|
||||
package org.eclipse.rse.internal.files.ui.actions;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -32,6 +34,7 @@ import java.util.Hashtable;
|
|||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourceAttributes;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.eclipse.jface.action.ContributionItem;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
@ -56,6 +59,7 @@ import org.eclipse.swt.widgets.Listener;
|
|||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
import org.eclipse.ui.IEditorDescriptor;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorRegistry;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
|
@ -408,7 +412,22 @@ protected IEditorDescriptor getPreferredEditor(IRemoteFile remoteFile) {
|
|||
IFile localFile = getLocalResource(remoteFile);
|
||||
|
||||
if (localFile == null || !localFile.exists()){
|
||||
return registry.getDefaultEditor(remoteFile.getName());
|
||||
// bug #376535 - need to respect editor overrides
|
||||
IEditorDescriptor desc = registry.getDefaultEditor(remoteFile.getName(), IDE.guessContentType(localFile));
|
||||
// Using reflection in case IDE is older version, without this method
|
||||
//desc = IDE.overrideDefaultEditorAssociation(new FileEditorInput(localFile), IDE.guessContentType(localFile), desc);
|
||||
Class clazz = IDE.class;
|
||||
try {
|
||||
Class parmtypes[] = {IEditorInput.class, IContentType.class, IEditorDescriptor.class};
|
||||
Method method = clazz.getMethod("overrideDefaultEditorAssociation", parmtypes); //$NON-NLS-1$
|
||||
if (method != null) {
|
||||
Object args[] = {new FileEditorInput(localFile), IDE.guessContentType(localFile), desc};
|
||||
desc = (IEditorDescriptor) method.invoke(null, args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
else {
|
||||
return IDE.getDefaultEditor(localFile);
|
||||
|
@ -470,7 +489,23 @@ public void fill(Menu menu, int index)
|
|||
IEditorDescriptor defaultEditor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); // may be null //$NON-NLS-1$
|
||||
IEditorDescriptor preferredEditor = getPreferredEditor(_remoteFile); // may be null
|
||||
|
||||
Object[] editors = registry.getEditors(getFileName());
|
||||
IFile localFile = getLocalResource(_remoteFile);
|
||||
IEditorDescriptor[] editors = registry.getEditors(getFileName());
|
||||
if (localFile != null) {
|
||||
// bug #376535 - need to respect editor overrides
|
||||
// Using reflection in case IDE is older version, without this method
|
||||
//editors = IDE.overrideEditorAssociations(new FileEditorInput(localFile), IDE.guessContentType(localFile), editors);
|
||||
Class clazz = IDE.class;
|
||||
try {
|
||||
Class parmtypes[] = {IEditorInput.class, IContentType.class, IEditorDescriptor[].class};
|
||||
Method method = clazz.getMethod("overrideEditorAssociations", parmtypes); //$NON-NLS-1$
|
||||
if (method != null) {
|
||||
Object args[] = {new FileEditorInput(localFile), IDE.guessContentType(localFile), editors};
|
||||
editors = (IEditorDescriptor[]) method.invoke(null, args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
Collections.sort(Arrays.asList(editors), comparer);
|
||||
|
||||
boolean defaultFound = false;
|
||||
|
|
|
@ -76,10 +76,12 @@
|
|||
* David McKnight (IBM) - [249031] Last used editor should be set to SystemEditableRemoteFile
|
||||
* David McKnight (IBM) - [341244] folder selection input to unlocked Remote Systems Details view sometimes fails
|
||||
* David McKnight (IBM) - [363490] PHP files opening in system editor (Dreamweaver)
|
||||
* Rick Sawyer (IBM) - [376535] RSE does not respect editor overrides
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.files.ui.view;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -100,6 +102,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
|||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
|
@ -204,13 +207,14 @@ import org.eclipse.rse.ui.view.ISystemViewElementAdapter;
|
|||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IEditorDescriptor;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorRegistry;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
import org.eclipse.ui.part.FileEditorInput;
|
||||
import org.eclipse.ui.progress.IElementCollector;
|
||||
import org.eclipse.ui.views.properties.IPropertyDescriptor;
|
||||
import org.eclipse.ui.views.properties.PropertyDescriptor;
|
||||
|
@ -564,6 +568,31 @@ public class SystemViewRemoteFileAdapter
|
|||
IRemoteFile file = (IRemoteFile) element;
|
||||
if (file.isFile() || file.isArchive()) // hack to show zips without folder icons
|
||||
{
|
||||
// bug #376535 - need to respect editor overrides
|
||||
IFile localFile = getLocalResource(file);
|
||||
if (localFile != null) {
|
||||
IEditorDescriptor editorDesc = getEditorRegistry().getDefaultEditor(file.getName(), IDE.guessContentType(localFile));
|
||||
// Using reflection in case IDE is older version, without this method
|
||||
//editorDesc = IDE.overrideDefaultEditorAssociation(new FileEditorInput(localFile), IDE.guessContentType(localFile), editorDesc);
|
||||
Class clazz = IDE.class;
|
||||
try {
|
||||
Class parmtypes[] = {IEditorInput.class, IContentType.class, IEditorDescriptor.class};
|
||||
Method method = clazz.getMethod("overrideDefaultEditorAssociation", parmtypes); //$NON-NLS-1$
|
||||
if (method != null) {
|
||||
Object args[] = {new FileEditorInput(localFile), IDE.guessContentType(localFile), editorDesc};
|
||||
editorDesc = (IEditorDescriptor) method.invoke(null, args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
if (editorDesc != null) {
|
||||
ImageDescriptor image = editorDesc.getImageDescriptor();
|
||||
if (image != null) {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getEditorRegistry().getImageDescriptor(file.getName());
|
||||
}
|
||||
else
|
||||
|
@ -591,6 +620,16 @@ public class SystemViewRemoteFileAdapter
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local cache of the remote file, or <code>null</code> if none.
|
||||
* @param remoteFile the remote file.
|
||||
* @return the local cached resource, or <code>null</code> if none.
|
||||
*/
|
||||
private IFile getLocalResource(IRemoteFile remoteFile)
|
||||
{
|
||||
return (IFile)UniversalFileTransferUtility.getTempFileFor(remoteFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the label for this object. Uses getName() on the remote file object.
|
||||
*/
|
||||
|
@ -3421,8 +3460,9 @@ public class SystemViewRemoteFileAdapter
|
|||
|
||||
// open new editor for correct replica
|
||||
editable = getEditableRemoteObject(remoteFile);
|
||||
}
|
||||
}
|
||||
|
||||
/* Commenting out - no longer needed with fix to bug #376535
|
||||
if (editable instanceof SystemEditableRemoteFile){
|
||||
SystemEditableRemoteFile edit = (SystemEditableRemoteFile)editable;
|
||||
IEditorDescriptor oldDescriptor = edit.getEditorDescriptor();
|
||||
|
@ -3443,6 +3483,7 @@ public class SystemViewRemoteFileAdapter
|
|||
edit.setEditorDescriptor(curDescriptor);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue