Skip to content

Commit

Permalink
Remember computed content type in CompareConfiguration
Browse files Browse the repository at this point in the history
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 eclipse-platform/eclipse.platform.ui#1747
  • Loading branch information
iloveeclipse committed Apr 8, 2024
1 parent ce64a2d commit de6a702
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions team/bundles/org.eclipse.compare/.settings/.api_filters
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
</message_arguments>
</filter>
</resource>
<resource path="compare/org/eclipse/compare/CompareConfiguration.java" type="org.eclipse.compare.CompareConfiguration">
<filter id="336658481">
<message_arguments>
<message_argument value="org.eclipse.compare.CompareConfiguration"/>
<message_argument value="CONTENT_TYPE"/>
</message_arguments>
</filter>
</resource>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,11 @@ public ViewerDescriptor[] findContentViewerDescriptor(Viewer oldViewer, Object i
if (ctype != null) {
initializeRegistries();
List<ViewerDescriptor> 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);
Expand Down

0 comments on commit de6a702

Please sign in to comment.