From c6e1094f7601c90a0bf7cd34b6dd076dc56246a2 Mon Sep 17 00:00:00 2001 From: John Dallaway Date: Sat, 7 Oct 2023 19:51:47 +0100 Subject: [PATCH] Select applicable editor for text content 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. --- .../ui/internal/editors/text/UntitledTextFileWizard.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/UntitledTextFileWizard.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/UntitledTextFileWizard.java index c980e0024ef..6221d1e697b 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/UntitledTextFileWizard.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/UntitledTextFileWizard.java @@ -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; @@ -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() { @@ -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;