Skip to content

Commit

Permalink
Select applicable editor for text content
Browse files Browse the repository at this point in the history
The Untitled Text File wizard creates an empty temporary file with no
file name suffix. Previously, the wizard would interrogate the editor
registry to select the default editor based on file name only. We now
specify the text content type when looking up the default editor to
avoid the possibility of opening the new file in an editor that is
associated with files having no file name suffix but is not appropriate
for text content.
  • Loading branch information
jld01 authored and laeubi committed Dec 16, 2023
1 parent 36358bd commit c6e1094
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.eclipse.core.filesystem.IFileStore;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
Expand All @@ -40,6 +42,8 @@
*/
public class UntitledTextFileWizard extends Wizard implements INewWizard {

private static final String TEXT_CONTENT_TYPE_ID= "org.eclipse.core.runtime.text"; //$NON-NLS-1$

private IWorkbenchWindow fWindow;

public UntitledTextFileWizard() {
Expand All @@ -59,7 +63,8 @@ private IFileStore queryFileStore() {
private String getEditorId(IFileStore fileStore) {
IWorkbench workbench= fWindow.getWorkbench();
IEditorRegistry editorRegistry= workbench.getEditorRegistry();
IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(fileStore.getName());
IContentType textContentType= Platform.getContentTypeManager().getContentType(TEXT_CONTENT_TYPE_ID);
IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(fileStore.getName(), textContentType);
if (descriptor != null)
return descriptor.getId();
return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
Expand Down

0 comments on commit c6e1094

Please sign in to comment.