Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2017-07-27 10:20:23 +0000
committerMickael Istria2017-07-27 15:38:41 +0000
commit8721e8f2c0b9d45756b6434c28db32f9f71c2664 (patch)
treebb8b3bac65e3f8201cb7c5bc707b6f54fc544869
parenta294209babf0c5ad2d98e0ae31347c051e5934e7 (diff)
downloadeclipse.platform.ui-8721e8f2c0b9d45756b6434c28db32f9f71c2664.tar.gz
eclipse.platform.ui-8721e8f2c0b9d45756b6434c28db32f9f71c2664.tar.xz
eclipse.platform.ui-8721e8f2c0b9d45756b6434c28db32f9f71c2664.zip
Bug 520239 - Removing content-type doesn't remove editor associationI20170727-2000
Change-Id: I0d19bfe0c323c8f7a13a8a0671362db03486827d Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java2
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java23
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java20
3 files changed, 38 insertions, 7 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java
index 04422d86968..5bbdac95e51 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java
@@ -1418,7 +1418,7 @@ public class WorkbenchPlugin extends AbstractUIPlugin {
@Override
public Object compute(IEclipseContext context, String contextKey) {
if (editorRegistry == null) {
- editorRegistry = new EditorRegistry();
+ editorRegistry = new EditorRegistry(Platform.getContentTypeManager());
}
return editorRegistry;
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java
index 4187b87d316..2aeda81471d 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java
@@ -44,6 +44,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
@@ -164,18 +165,28 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx
private RelatedRegistry relatedRegistry;
+ private final IContentTypeManager contentTypeManager;
+
public static final String EMPTY_EDITOR_ID = "org.eclipse.ui.internal.emptyEditorTab"; //$NON-NLS-1$
/**
* Return an instance of the receiver. Adds listeners into the extension
* registry for dynamic UI purposes.
+ * @param contentTypeManager
*/
- public EditorRegistry() {
+ public EditorRegistry(IContentTypeManager contentTypeManager) {
super();
+ this.contentTypeManager = contentTypeManager;
initializeFromStorage();
IExtensionTracker tracker = PlatformUI.getWorkbench().getExtensionTracker();
tracker.registerHandler(this, ExtensionTracker.createExtensionPointFilter(getExtensionPointFilter()));
relatedRegistry = new RelatedRegistry();
+ contentTypeManager.addContentTypeChangeListener(event -> {
+ if (contentTypeManager.getContentType(event.getContentType().getId()) == null) {
+ contentTypeToEditorMappingsFromUser.remove(event.getContentType());
+ saveAssociations();
+ }
+ });
}
/**
@@ -250,7 +261,7 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx
for (String contentTypeId : contentTypeVector) {
if (contentTypeId != null && contentTypeId.length() > 0) {
- IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId);
+ IContentType contentType = contentTypeManager.getContentType(contentTypeId);
if (contentType != null) {
addContentTypeBindingFromPlugin(contentType, editor, bDefault);
}
@@ -340,7 +351,7 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx
return defaultEditor;
}
- IContentType[] contentTypes = Platform.getContentTypeManager().findContentTypesFor(filename);
+ IContentType[] contentTypes = contentTypeManager.findContentTypesFor(filename);
for (IContentType contentType : contentTypes) {
IEditorDescriptor editor = getDefaultEditor(filename, contentType);
if (editor != null) {
@@ -358,7 +369,7 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx
* @since 3.1
*/
private IContentType guessAtContentType(String filename) {
- return Platform.getContentTypeManager().findContentTypeFor(filename);
+ return contentTypeManager.findContentTypeFor(filename);
}
/**
@@ -754,7 +765,7 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx
});
String contentTypeId = childMemento.getString(IWorkbenchConstants.TAG_CONTENT_TYPE);
if (contentTypeId != null) {
- IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeId);
+ IContentType contentType = contentTypeManager.getContentType(contentTypeId);
if (contentType != null) {
contentTypeToEditorMappingsFromUser.put(contentType, new LinkedHashSet<>(editors));
}
@@ -1567,7 +1578,7 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx
List<IFileEditorMapping> allMappings = new ArrayList<>(Arrays.asList(standardMappings));
// mock-up content type extensions into IFileEditorMappings
- for (IContentType type : Platform.getContentTypeManager().getAllContentTypes()) {
+ for (IContentType type : contentTypeManager.getAllContentTypes()) {
for (String extension : type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)) {
boolean found = false;
for (IFileEditorMapping mapping : allMappings) {
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java
index 2a1c439a9da..b6c39337981 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java
@@ -11,6 +11,9 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;
+import static org.junit.Assert.assertArrayEquals;
+
+import org.eclipse.core.internal.content.ContentTypeManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
@@ -559,4 +562,21 @@ public class IEditorRegistryTest extends TestCase {
assertEquals(1, editors.length);
assertEquals(MockEditorPart.ID1, editors[0].getId());
}
+
+ public void testRemoveContentType_bug520239() throws CoreException {
+ ContentTypeManager contentTypeManager = (ContentTypeManager) Platform.getContentTypeManager();
+ IContentType contentType = contentTypeManager.addContentType("bug520239", "bug520239", null);
+ contentType.addFileSpec("bug520239", IContentType.FILE_EXTENSION_SPEC);
+ assertArrayEquals("No editor should be bound by default", new IEditorDescriptor[0],
+ fReg.getEditors("blah.bug520239"));
+
+ IEditorDescriptor anEditor = ((EditorRegistry) fReg).getSortedEditorsFromPlugins()[0];
+ ((EditorRegistry) fReg).addUserAssociation(contentType, anEditor);
+ assertArrayEquals("Missing editor association", new IEditorDescriptor[] { anEditor },
+ fReg.getEditors("blah.bug520239"));
+
+ contentTypeManager.removeContentType(contentType.getId());
+ assertArrayEquals("No editor should be bound after contenttype removal", new IEditorDescriptor[0],
+ fReg.getEditors("blah.bug520239"));
+ }
}

Back to the top