From 3e4a26c1416f4535e87f9f64b4f1496184b8efd7 Mon Sep 17 00:00:00 2001 From: Mehmet Emin Karaman Date: Wed, 28 Aug 2024 13:53:20 +0200 Subject: [PATCH] negated editor override; extensions will be included instead of excluded. --- .../XpectEditorAssociationOverride.java | 28 +++++++++++++++++-- .../preferences/XpectRootPreferencePage.java | 8 +++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/org.eclipse.xpect.ui/src/org/eclipse/xpect/ui/editor/XpectEditorAssociationOverride.java b/org.eclipse.xpect.ui/src/org/eclipse/xpect/ui/editor/XpectEditorAssociationOverride.java index 189523ff..7632efbd 100644 --- a/org.eclipse.xpect.ui/src/org/eclipse/xpect/ui/editor/XpectEditorAssociationOverride.java +++ b/org.eclipse.xpect.ui/src/org/eclipse/xpect/ui/editor/XpectEditorAssociationOverride.java @@ -12,7 +12,9 @@ package org.eclipse.xpect.ui.editor; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Set; import org.eclipse.core.resources.IFile; @@ -25,6 +27,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; import org.eclipse.ui.ide.IEditorAssociationOverride; +import org.eclipse.xpect.registry.IExtensionInfo; import org.eclipse.xpect.registry.ILanguageInfo; import org.eclipse.xpect.ui.XpectPluginActivator; import org.eclipse.xpect.ui.preferences.XpectRootPreferencePage; @@ -40,6 +43,10 @@ */ public class XpectEditorAssociationOverride implements IEditorAssociationOverride { + private static final String ATTRIBUTE_FILE_EXTENSION = "fileExtension"; + + private static final String ORG_ECLIPSE_XPECT_FILE_EXTENSIONS = "org.eclipse.xpect.fileExtensions"; + @Inject private ContentTypeUtil contentTypeHelper; @@ -49,7 +56,18 @@ public class XpectEditorAssociationOverride implements IEditorAssociationOverrid private URIDelegationHandler uriHandler; private final IEditorDescriptor xpectEditor = registry.findEditor(XpectPluginActivator.XPECT_EDITOR_ID); private final IEditorDescriptor xtEditor = registry.findEditor(XpectPluginActivator.XT_EDITOR_ID); - + private static final List supportedExtensions = new ArrayList<>(); + + static { + for (IExtensionInfo extensionInfo : IExtensionInfo.Registry.INSTANCE.getExtensions(ORG_ECLIPSE_XPECT_FILE_EXTENSIONS)) { + String ext = extensionInfo.getAttributeValue(ATTRIBUTE_FILE_EXTENSION); + if (ext == null) { + continue; + } + supportedExtensions.add(ext); + } + } + protected IFile getFile(IEditorInput input) { if (input instanceof IFileEditorInput) return ((IFileEditorInput) input).getFile(); @@ -81,8 +99,14 @@ public IEditorDescriptor overrideDefaultEditor(IEditorInput editorInput, IConten return editorDescriptor; } IFile file = getFile(editorInput); - if (file == null || hasFavoriteEditor(file) || XpectRootPreferencePage.getSkipExtensionsList().contains(file.getFileExtension())) + if (file == null || hasFavoriteEditor(file)) return editorDescriptor; + if (!supportedExtensions.contains(file.getFileExtension())) { + List overrideIncludedExtensions = XpectRootPreferencePage.getIncludedContentCheckExtensions(); + if (!overrideIncludedExtensions.contains(file.getFileExtension())) { + return editorDescriptor; + } + } XpectContentType type = contentTypeHelper.getContentType(file); switch (type) { case XPECT: diff --git a/org.eclipse.xpect.ui/src/org/eclipse/xpect/ui/preferences/XpectRootPreferencePage.java b/org.eclipse.xpect.ui/src/org/eclipse/xpect/ui/preferences/XpectRootPreferencePage.java index 6a7cc1b7..0ccf1050 100644 --- a/org.eclipse.xpect.ui/src/org/eclipse/xpect/ui/preferences/XpectRootPreferencePage.java +++ b/org.eclipse.xpect.ui/src/org/eclipse/xpect/ui/preferences/XpectRootPreferencePage.java @@ -33,7 +33,7 @@ public class XpectRootPreferencePage extends LanguageRootPreferencePage { public static final String LIVE_TEST_EXECUTION_PREFERENCE_NAME = "org.eclipse.xpect.ui.live_test_execution"; - public static final String SKIP_CONTENT_CHECK_PREFERENCE_NAME = "org.eclipse.xpect.ui.skip_content_check"; + public static final String INCLUDE_CONTENT_CHECK_PREFERENCE_NAME = "org.eclipse.xpect.ui.include_extension_content_check"; public static final String DISABLE_EDITOR_OVERRIDE_PREFERENCE_NAME = "org.eclipse.xpect.ui.editor_override"; @@ -51,7 +51,7 @@ protected void createFieldEditors() { Composite skipFileExtListComposite = new Composite(group, SWT.NONE); GridLayoutFactory.fillDefaults().margins(5, 5).applyTo(skipFileExtListComposite); GridDataFactory.fillDefaults().grab(true, false).applyTo(skipFileExtListComposite); - addField(new SkipFileExtensionList(SKIP_CONTENT_CHECK_PREFERENCE_NAME, "Exclude following file extensions from Xpect editor override:", skipFileExtListComposite)); + addField(new SkipFileExtensionList(INCLUDE_CONTENT_CHECK_PREFERENCE_NAME, "Include following file extensions from Xpect editor override (includes all if nothing is specified):", skipFileExtListComposite)); Composite disableOverrideComposite = new Composite(group, SWT.NONE); GridLayoutFactory.fillDefaults().margins(5, 5).applyTo(disableOverrideComposite); @@ -67,9 +67,9 @@ public static boolean isLiveTestExecutionEnabled(IProject project) { return enabled; } - public static List getSkipExtensionsList() { + public static List getIncludedContentCheckExtensions() { IPreferenceStoreAccess preferenceStore = XpectActivator.getInstance().getInjector(XpectActivator.ORG_ECLIPSE_XPECT_XPECT).getInstance(IPreferenceStoreAccess.class); - String extensions = preferenceStore.getWritablePreferenceStore().getString(SKIP_CONTENT_CHECK_PREFERENCE_NAME); + String extensions = preferenceStore.getWritablePreferenceStore().getString(INCLUDE_CONTENT_CHECK_PREFERENCE_NAME); if (extensions.trim().length() == 0) { return Collections.emptyList(); }