From de6a702d41ed30e3b9d5a35eb0295f7d40ebaec9 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Mon, 8 Apr 2024 17:17:58 +0200 Subject: [PATCH] Remember computed content type in CompareConfiguration Remember detected content type id in CompareConfiguration with the CONTENT_TYPE key. This value can be picked up as a hint by TextMergeViewer implementations (like GenericEditorMergeViewer) that need to know which content type was detected by compare editor. Most TextMergeViewer implementations don't need that hint because they aren't generic and usually always know which content type they will have - not so for GenericEditorMergeViewer which is generic. The hint allows GenericEditorMergeViewer to know for which content type was it actually created and so use that in cases where the content type can't be always derived from the input (like data from git revisions that don't have regular files or buffers associated to the viewer). See https://github.com/eclipse-platform/eclipse.platform.ui/issues/1747 --- team/bundles/org.eclipse.compare/.settings/.api_filters | 8 ++++++++ .../compare/org/eclipse/compare/CompareConfiguration.java | 8 ++++++++ .../org/eclipse/compare/internal/CompareUIPlugin.java | 5 ++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/team/bundles/org.eclipse.compare/.settings/.api_filters b/team/bundles/org.eclipse.compare/.settings/.api_filters index e4b95513f05..0eba7365ef7 100644 --- a/team/bundles/org.eclipse.compare/.settings/.api_filters +++ b/team/bundles/org.eclipse.compare/.settings/.api_filters @@ -8,4 +8,12 @@ + + + + + + + + diff --git a/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareConfiguration.java b/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareConfiguration.java index 82d924c1aed..882a159a15e 100644 --- a/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareConfiguration.java +++ b/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareConfiguration.java @@ -79,6 +79,14 @@ public class CompareConfiguration { */ public static final String MIRRORED = "MIRRORED"; //$NON-NLS-1$ + /** + * (Optional) id of the common content type for compare input detected by the + * compare editor + * + * @since 3.11 + */ + public static final String CONTENT_TYPE = "CONTENT_TYPE"; //$NON-NLS-1$ + private static ImageDescriptor[] fgImages= new ImageDescriptor[32]; static { diff --git a/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java b/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java index e6000e118ed..86c92651ba0 100644 --- a/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java +++ b/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java @@ -1030,8 +1030,11 @@ public ViewerDescriptor[] findContentViewerDescriptor(Viewer oldViewer, Object i if (ctype != null) { initializeRegistries(); List list = fContentMergeViewers.searchAll(ctype); - if (list != null) + if (list != null) { result.addAll(list); + } + // Add a hint for the viewers which content type we have detected + cc.setProperty(CompareConfiguration.CONTENT_TYPE, ctype.getId()); } String[] types= getTypes(input);