Skip to content

Commit e1eb5d8

Browse files
committed
Make ContentTypes->default text editor as Generic Code Editor.
Fixes #2527
1 parent abb10ef commit e1eb5d8

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java

+35-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2021 IBM Corporation and others.
2+
* Copyright (c) 2005, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -21,6 +21,7 @@
2121
import java.nio.charset.Charset;
2222
import java.nio.charset.IllegalCharsetNameException;
2323
import java.util.ArrayList;
24+
import java.util.Arrays;
2425
import java.util.Collection;
2526
import java.util.List;
2627
import java.util.Objects;
@@ -352,10 +353,40 @@ private void createEditors(Composite parent) {
352353
editorAssociationsViewer = new TableViewer(composite);
353354
editorAssociationsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
354355
editorAssociationsViewer.setContentProvider((IStructuredContentProvider) arg0 -> {
355-
if (arg0 instanceof IContentType) {
356-
return editorRegistry.getEditors(null, (IContentType) arg0);
356+
if (!(arg0 instanceof IContentType)) {
357+
return new Object[0];
357358
}
358-
return new Object[0];
359+
360+
List<IEditorDescriptor> editorList = new ArrayList<>(
361+
Arrays.asList(editorRegistry.getEditors(null, (IContentType) arg0)));
362+
363+
IEditorDescriptor genericEditor = null;
364+
int index = -1;
365+
for (int i = 0; i < editorList.size(); i++) {
366+
if ("org.eclipse.ui.genericeditor.GenericEditor".equals(editorList.get(i).getId())) { //$NON-NLS-1$
367+
genericEditor = editorList.get(i);
368+
index = i;
369+
break;
370+
}
371+
}
372+
373+
if (genericEditor != null) {
374+
IContentType defaultContentType = (IContentType) editorAssociationsViewer.getInput();
375+
IPreferenceStore defaultStore = WorkbenchPlugin.getDefault().getPreferenceStore();
376+
String defaultKey = IPreferenceConstants.DEFAULT_EDITOR_FOR_CONTENT_TYPE + defaultContentType.getId();
377+
378+
if (!genericEditor.getId().equals(defaultStore.getString(defaultKey))) {
379+
defaultStore.setValue(defaultKey, genericEditor.getId());
380+
}
381+
382+
if (index > 0) {
383+
editorList.remove(index);
384+
editorList.add(0, genericEditor);
385+
}
386+
}
387+
388+
editorAssociationsViewer.refresh();
389+
return editorList.toArray(new IEditorDescriptor[0]);
359390
});
360391
editorAssociationsViewer.setLabelProvider(
361392
createTextImageProvider(element -> {

0 commit comments

Comments
 (0)