|
1 | 1 | /*******************************************************************************
|
2 |
| - * Copyright (c) 2005, 2021 IBM Corporation and others. |
| 2 | + * Copyright (c) 2005, 2025 IBM Corporation and others. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials
|
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0
|
|
21 | 21 | import java.nio.charset.Charset;
|
22 | 22 | import java.nio.charset.IllegalCharsetNameException;
|
23 | 23 | import java.util.ArrayList;
|
| 24 | +import java.util.Arrays; |
24 | 25 | import java.util.Collection;
|
25 | 26 | import java.util.List;
|
26 | 27 | import java.util.Objects;
|
@@ -352,10 +353,40 @@ private void createEditors(Composite parent) {
|
352 | 353 | editorAssociationsViewer = new TableViewer(composite);
|
353 | 354 | editorAssociationsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
354 | 355 | 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]; |
357 | 358 | }
|
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]); |
359 | 390 | });
|
360 | 391 | editorAssociationsViewer.setLabelProvider(
|
361 | 392 | createTextImageProvider(element -> {
|
|
0 commit comments