Bug 263316 - [Content Type] Filename patterns for content types and file associations
Summary: [Content Type] Filename patterns for content types and file associations
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 3.4.1   Edit
Hardware: All All
: P3 enhancement with 5 votes (vote)
Target Milestone: 4.8 M2   Edit
Assignee: Mickael Istria CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
: 22905 46297 89859 129747 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-02-02 18:35 EST by David Neal CLA
Modified: 2021-10-12 04:39 EDT (History)
13 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Neal CLA 2009-02-02 18:35:06 EST
Currently eclipse only supports wildcard prefixes for content types and file associations (e.g *.xml).  It needs to be able to handle wildcard suffixes as well so if you have a file format that has a fixed prefix but not suffix you can add it as a content type or file association (e.g. Makefile.*).
Comment 1 Szymon Brandys CLA 2009-09-16 06:38:16 EDT
*** Bug 129747 has been marked as a duplicate of this bug. ***
Comment 2 Pavel Mendl CLA 2014-02-14 12:38:11 EST
The best (if implementation would be possible) would be to check filenames by the standard regex pattern(s) to define associations. This would allow for all the imaginable combinations to get configured properly. Upvoting the solution.

Just for reference, this would solve bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=292229 too.
Comment 3 Mickael Istria CLA 2017-06-25 04:47:14 EDT
I'd like to see this added for 4.8. I'm assigning this to myself so it shows up in my todo list, but if anyone is also interested, I'd be glad to change assignment so it goes to the first one able to fix it.
Comment 4 Mickael Istria CLA 2017-07-13 08:37:16 EDT
The entry points to add this would be:
* org.eclipse.ui.internal.registry.FileEditorMapping (and probably interface IFileEditorMapping to add a new method, but it's no API issue as it's mark as @noimplement)
* org.eclipse.ui.internal.dialogs.ContentTypePreferencesPage.Spec
to add the regexp as a field

Then everything that reads the name or the extension of those 2 classes sould be augmented to also read the regexp, and the FileExtensionDialog should allow patterns

It does seem like a too hard piece of work to do.
Comment 5 Dennis Huebner CLA 2017-07-25 05:21:40 EDT
(In reply to Mickael Istria from comment #4)
> The entry points to add this would be:
> * org.eclipse.ui.internal.registry.FileEditorMapping (and probably interface
> IFileEditorMapping to add a new method, but it's no API issue as it's mark
> as @noimplement)
> * org.eclipse.ui.internal.dialogs.ContentTypePreferencesPage.Spec
> to add the regexp as a field
> 
> Then everything that reads the name or the extension of those 2 classes
> sould be augmented to also read the regexp, and the FileExtensionDialog
> should allow patterns
> 
> It does seem like a too hard piece of work to do.

Will the pattern matching associations have a lower priority compared with the perfect match associations?
Comment 6 Mickael Istria CLA 2017-07-27 04:38:43 EDT
Tentative for 4.8.M2. I've started to work on a patch and I believe it should be ready next week (too late for 4.8.M1)
Comment 7 Mickael Istria CLA 2017-07-27 04:50:29 EDT
(In reply to Mickael Istria from comment #6)
> Tentative for 4.8.M2. I've started to work on a patch and I believe it
> should be ready next week (too late for 4.8.M1)

WIP: https://github.com/mickaelistria/eclipse.platform.runtime/tree/263316 and https://github.com/mickaelistria/eclipse.platform.resources/tree/263316
Comment 8 Eclipse Genie CLA 2017-08-03 09:53:03 EDT
New Gerrit change created: https://git.eclipse.org/r/102464
Comment 9 Eclipse Genie CLA 2017-08-03 09:58:51 EDT
New Gerrit change created: https://git.eclipse.org/r/102466
Comment 10 Eclipse Genie CLA 2017-08-05 10:52:18 EDT
New Gerrit change created: https://git.eclipse.org/r/102569
Comment 14 Eclipse Genie CLA 2017-08-30 15:20:47 EDT
New Gerrit change created: https://git.eclipse.org/r/104028
Comment 16 Alexander Kurtakov CLA 2017-09-06 10:46:14 EDT
Please add image to the N&N entry.
Comment 17 Mickael Istria CLA 2017-09-06 17:37:35 EDT
(In reply to Alexander Kurtakov from comment #16)
> Please add image to the N&N entry.

Done.
Comment 18 Martin Lippert CLA 2018-06-04 02:22:52 EDT
I am trying this pattern-based content-type definitions at the moment and I am running into problems. When I define:

      <file-association
            content-type="org.springframework.boot.ide.properties.application.properties"
            file-names="application.properties">
      </file-association>

The file called "application.properties" gets this content-type and the associated editor/icon shows up in the package explorer.

If I instead define:

      <file-association
            content-type="org.springframework.boot.ide.properties.application.properties"
            file-patterns="*application*.properties">
      </file-association>

The associated editor/icon doesn't show up, looks like this content-type gets ignored for a file called "application.properties".

When I debug into ContentTypeCatalog.internalFindContentTypesFor, it finds the regexp-based content-type, but it is not used later, looks like the extension-based content-type that matches here (for Java properties) is selected instead.

Is there a way to get my regexp-based content-type association being selected instead of the Java properties type?
Comment 19 Mickael Istria CLA 2018-06-04 02:41:33 EDT
(In reply to Martin Lippert from comment #18)
> When I debug into ContentTypeCatalog.internalFindContentTypesFor, it finds
> the regexp-based content-type, but it is not used later, looks like the
> extension-based content-type that matches here (for Java properties) is
> selected instead.

Did you mark you content-type as extending JDT properties content-type? I think it's necessary if you want to make sure it's going to be the one returned as IIRC the ContentTypeManager returns the "most specialized" one in case it finds multiple content-type. If you don't define you type as extending base properties type, then it doesn't seem more specialized and the ContentTypeManager may return one or the other, and would be right for both.
Comment 20 Martin Lippert CLA 2018-06-04 05:05:25 EDT
Good point. I changed this, but my content type still isn't being selected. Here is the full extension declaration:

   <extension
         point="org.eclipse.core.contenttype.contentTypes">
      <content-type
            id="org.springframework.boot.ide.properties.application.properties"
            base-type="org.eclipse.jdt.core.javaProperties"
            name="Spring Properties File"
            priority="high">
      </content-type>
      <file-association
            content-type="org.springframework.boot.ide.properties.application.properties"
            file-patterns="*application*.properties">
      </file-association>
   </extension>
   
Any idea what might be going wrong here?
Comment 21 Mickael Istria CLA 2018-06-04 05:10:46 EDT
(In reply to Martin Lippert from comment #20)
> Any idea what might be going wrong here?

Nope. Please open a separate bug about it as it could be a bug in Platform.
Comment 22 Martin Lippert CLA 2018-06-04 05:44:57 EDT
Done:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=535510
Comment 23 Mickael Istria CLA 2021-03-23 14:32:53 EDT
*** Bug 22905 has been marked as a duplicate of this bug. ***
Comment 24 Andrey Loskutov CLA 2021-03-23 17:53:33 EDT
*** Bug 89859 has been marked as a duplicate of this bug. ***
Comment 25 Mickael Istria CLA 2021-10-12 04:39:31 EDT
*** Bug 46297 has been marked as a duplicate of this bug. ***