Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 230865

Summary: [EditorMgmt] File > Open File editor should also use content describer
Product: [Eclipse Project] Platform Reporter: David Whiteman <dlwhiteman>
Component: UIAssignee: Dani Megert <daniel_megert>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: bokowski, daniel_megert, Darin_Swanson, Ed.Merks, nammoula, remy.suen, valentinbaciu
Version: 3.4Flags: bokowski: review+
Target Milestone: 3.4 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 199164    
Attachments:
Description Flags
Use proper content type support to determine the editor ID for a file store
none
Fix
none
Sample file to test opening correctly
none
Fix none

Description David Whiteman CLA 2008-05-07 06:46:05 EDT
When you open a file in the workspace, there is a certain algorithm used to determine the correct editor for that file.  When you open an external file using File->Open File..., the algorithm for determining the correct editor seems to be different.  An example of this is the Ant editor.

When I create an Ant build file in Eclipse, and I double click to open the file, the Ant editor is used for the file.  However, if I export that file to the file system, and then open it using File->Open File..., the default XML editor is used for the file.  

I am trying to address a similar problem in the COSMOS project, as we have a content describer used to determine if .xml files should be opened with our SML-IF editor by inspecting some of the file content (same case as the Ant editor where there is more than one possible match for a particular file extension).
Comment 1 Dani Megert CLA 2008-05-07 08:03:16 EDT
Currently, content types are honored but only based on the file's name i.e. we don't look into the file. We need to use
org.eclipse.core.runtime.content.IContentTypeMatcher.findContentTypesFor(InputStream, String).

This is in class 'IDE'.
Comment 2 Ed Merks CLA 2008-05-07 08:27:57 EDT
Created attachment 99059 [details]
Use proper content type support to determine the editor ID for a file store

It seems to me that unless the file store's input stream is properly examined to determine the content type the open behavior for an external file will never properly match that of a file in the workspace.  The attached patch directly addresses that shortcoming.
Comment 3 Dani Megert CLA 2008-05-07 09:00:16 EDT
Sorry Ed, there was a little typo in my previous comment: you can simply use
org.eclipse.core.runtime.content.IContentTypeMatcher.findContentTypeFor(InputStream, String) to get the preferred content type.

Also, you should use openInputStream(EFS.NONE, null) instead of openInputStream(0, null) and of course ensure that the stream gets closed again.

I'll attach a new patch shorty.
Comment 4 Boris Bokowski CLA 2008-05-07 09:04:42 EDT
Dani, would you like to take care of this one yourself?
Comment 5 Dani Megert CLA 2008-05-07 09:09:54 EDT
Sure.
Comment 6 Dani Megert CLA 2008-05-07 09:12:00 EDT
David, a simple test case based on Eclipse SDK would help to verify our fix.
Comment 7 Dani Megert CLA 2008-05-07 09:15:46 EDT
Created attachment 99064 [details]
Fix
Comment 8 Dani Megert CLA 2008-05-07 09:16:41 EDT
Ed, can you give the patch a try as well?
Comment 9 Ed Merks CLA 2008-05-07 10:12:50 EDT
Created attachment 99076 [details]
Sample file to test opening correctly

This fix works well.

So the idea is to make this private method public for the next release?

To test I was opening the attached file named "customBuildCallbacks.xml".  Without the fix it opens as text; with the fix, it opens using the ant editor.
Comment 10 David Whiteman CLA 2008-05-07 10:23:17 EDT
Can the testcase be manual?  I can tell you the steps to follow from the standard Eclipse SDK:

1. Create a new file called foo.xml in a project
2. In the Ant editor that opens, paste the following in the file and save it:

<?xml version="1.0"?>
<project default="main" basedir=".">
	<target name="main"/>
</project>

3. Export the file to the file system
4. Choose File > Open File... from the menu bar and select the file you just exported (foo.xml)
5. Observe whether the Ant editor or the default XML editor is used
Comment 11 Dani Megert CLA 2008-05-07 10:40:44 EDT
>So the idea is to make this private method public for the next release?
Do you need it? If so, there's nothing against that - would by in sync with the other methods we already have as API.
Comment 12 Ed Merks CLA 2008-05-07 11:02:11 EDT
No, I don't have any immediate need for it.  It just looked to fit in so nicely as you said.  So I assumed you just made it private for now because of API freeze and will make it public later...
Comment 13 Dani Megert CLA 2008-05-07 12:51:03 EDT
Created attachment 99116 [details]
Fix

Grrr! I hate that bug 148844! We need to rename that method, otherwise we force plug-ins to add additional required bundles. So, that leaves to patch to just tweak the getEditorId method.
Comment 14 Boris Bokowski CLA 2008-05-07 16:02:53 EDT
*** Bug 223064 has been marked as a duplicate of this bug. ***
Comment 15 Dani Megert CLA 2008-05-08 03:28:26 EDT
Committed to HEAD.
Available in builds >= I20080508-2000.
Comment 16 Szymon Brandys CLA 2008-05-13 12:07:03 EDT
*** Bug 194935 has been marked as a duplicate of this bug. ***