|
Lines 10-15
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.ide; |
11 |
package org.eclipse.ui.ide; |
| 12 |
|
12 |
|
|
|
13 |
import java.io.IOException; |
| 14 |
import java.io.InputStream; |
| 13 |
import java.net.URI; |
15 |
import java.net.URI; |
| 14 |
import java.util.ArrayList; |
16 |
import java.util.ArrayList; |
| 15 |
import java.util.Collections; |
17 |
import java.util.Collections; |
|
Lines 820-825
Link Here
|
| 820 |
} |
822 |
} |
| 821 |
|
823 |
|
| 822 |
/** |
824 |
/** |
|
|
825 |
* Returns an editor id appropriate for opening the given file |
| 826 |
* store. |
| 827 |
* <p> |
| 828 |
* The editor descriptor is determined using a multi-step process. This |
| 829 |
* method will attempt to resolve the editor based on content-type bindings |
| 830 |
* as well as traditional name/extension bindings. |
| 831 |
* </p> |
| 832 |
* <ol> |
| 833 |
* <li>The workbench editor registry is consulted to determine if an editor |
| 834 |
* extension has been registered for the file type. If so, an instance of |
| 835 |
* the editor extension is opened on the file. See |
| 836 |
* <code>IEditorRegistry.getDefaultEditor(String)</code>.</li> |
| 837 |
* <li>The operating system is consulted to determine if an in-place |
| 838 |
* component editor is available (e.g. OLE editor on Win32 platforms).</li> |
| 839 |
* <li>The operating system is consulted to determine if an external editor |
| 840 |
* is available.</li> |
| 841 |
* </ol> |
| 842 |
* </p> |
| 843 |
* |
| 844 |
* @param fileStore |
| 845 |
* the file store |
| 846 |
* @return the id of an editor, appropriate for opening the file |
| 847 |
* @throws PartInitException |
| 848 |
* if no editor can be found |
| 849 |
*/ |
| 850 |
private static String getEditorId(IFileStore fileStore) throws PartInitException { |
| 851 |
String name = fileStore.fetchInfo().getName(); |
| 852 |
if (name == null) { |
| 853 |
throw new IllegalArgumentException(); |
| 854 |
} |
| 855 |
|
| 856 |
IContentType contentType= null; |
| 857 |
try { |
| 858 |
InputStream is = null; |
| 859 |
try { |
| 860 |
is = fileStore.openInputStream(EFS.NONE, null); |
| 861 |
contentType= Platform.getContentTypeManager().findContentTypeFor(is, name); |
| 862 |
} finally { |
| 863 |
if (is != null) { |
| 864 |
is.close(); |
| 865 |
} |
| 866 |
} |
| 867 |
} catch (CoreException ex) { |
| 868 |
// continue without content type |
| 869 |
} catch (IOException ex) { |
| 870 |
// continue without content type |
| 871 |
} |
| 872 |
|
| 873 |
IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry(); |
| 874 |
|
| 875 |
return getEditorDescriptor(name, editorReg, editorReg.getDefaultEditor(name, contentType)).getId(); |
| 876 |
} |
| 877 |
|
| 878 |
/** |
| 823 |
* Returns an editor descriptor appropriate for opening a file resource with |
879 |
* Returns an editor descriptor appropriate for opening a file resource with |
| 824 |
* the given name. |
880 |
* the given name. |
| 825 |
* <p> |
881 |
* <p> |
|
Lines 1090-1115
Link Here
|
| 1090 |
return page.openEditor(input, editorId); |
1146 |
return page.openEditor(input, editorId); |
| 1091 |
} |
1147 |
} |
| 1092 |
|
1148 |
|
| 1093 |
/** |
|
|
| 1094 |
* Get the id of the editor associated with the given <code>IFileStore</code>. |
| 1095 |
* |
| 1096 |
* @param fileStore |
| 1097 |
* the <code>IFileStore</code> representing the file for which the editor id is desired |
| 1098 |
* @return the id of the appropriate editor |
| 1099 |
* @since 3.3 |
| 1100 |
*/ |
| 1101 |
private static String getEditorId(IFileStore fileStore) { |
| 1102 |
IEditorDescriptor descriptor; |
| 1103 |
try { |
| 1104 |
descriptor = IDE.getEditorDescriptor(fileStore.getName()); |
| 1105 |
} catch (PartInitException e) { |
| 1106 |
return null; |
| 1107 |
} |
| 1108 |
if (descriptor != null) |
| 1109 |
return descriptor.getId(); |
| 1110 |
return null; |
| 1111 |
} |
| 1112 |
|
| 1113 |
/** |
1149 |
/** |
| 1114 |
* Save all dirty editors in the workbench whose editor input is a child |
1150 |
* Save all dirty editors in the workbench whose editor input is a child |
| 1115 |
* resource of one of the <code>IResource</code>'s provided. Opens a |
1151 |
* resource of one of the <code>IResource</code>'s provided. Opens a |