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

Bug 146248

Summary: [EditorMgmt] Another editor is opened even if the editor referenced is already open
Product: [Eclipse Project] Platform Reporter: Fabio Zadrozny <fabiofz>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: Tod_Creasey
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Fabio Zadrozny CLA 2006-06-09 09:19:17 EDT
In Eclipse, if I open a file from the resource navigator, and then open the same file from the 'Open File...' menu (so, opening an external file) will create 2 editors for editing the same file. 

The same thing happens in Pydev when I open a definition with the full path using:

IEditorInput file = createEditorInput(fullPath);
...
IWorkbenchPage wp = activeWorkbenchWindow.getActivePage();
return IDE.openEditor(wp, file, PyEdit.EDITOR_ID);

Creating 2 instances of the same editor being edited.

I'm reporting both bugs here because I believe they're closely related (the API is broken).

The API states:

If the page already has an editor open on the target object then that editor is brought to front; otherwise, a new editor is opened.

Cheers,

Fabio
Comment 1 Fabio Zadrozny CLA 2006-06-09 09:24:56 EDT
Some more details:

In the title of the editor, the editor opened from the navigator shows:
projName/src/mod.py
whereas opening it with the full path shows:
c:\projName\src\mod.py

And if I make the 'show in navigator', it does not work for the one opened with the full path.
Comment 2 Eric Moffatt CLA 2006-06-09 11:02:29 EDT
You may also want to look at bug 143731 as being related to this one...
Comment 3 Tod Creasey CLA 2006-06-09 13:41:05 EDT
If you open a file externally it is not tracked by Eclipse any more as you have chosen to open it outside of Eclipse.
Comment 4 Tod Creasey CLA 2006-06-09 13:41:22 EDT
Marking as WORKSFORME
Comment 5 Fabio Zadrozny CLA 2006-06-09 13:46:48 EDT
Note that in pydev I do not open it externally, and it still is not tracked by Eclipse. I believe that most plugins that open some file (on trackbacks, go to definition, etc) use the same code I do... so, I think you could give it a second thought

IEditorInput file = createEditorInput(fullPath);
...
IWorkbenchPage wp = activeWorkbenchWindow.getActivePage();
return IDE.openEditor(wp, file, PyEdit.EDITOR_ID);

If that's not how it should be, then at least a VERY BIG warning should be in the documentation, because, as I said it states:

The API states:

    /**
     * Opens an editor on the given object.
     * <p>
     * If the page already has an editor open on the target object then that
     * editor is brought to front; otherwise, a new editor is opened.
     * <p>
     * 
     * @param page
     *            the page in which the editor will be opened
     * @param input
     *            the editor input
     * @param editorId
     *            the id of the editor extension to use
     * @return an open editor or <code>null</code> if an external editor was
     *         opened
     * @exception PartInitException
     *                if the editor could not be initialized
     * @see org.eclipse.ui.IWorkbenchPage#openEditor(IEditorInput, String)
     */
Comment 6 Susan McCourt CLA 2009-07-09 19:08:58 EDT
As per http://wiki.eclipse.org/Platform_UI/Bug_Triage_Change_2009
Comment 7 Boris Bokowski CLA 2009-11-17 13:06:41 EST
Remy is now responsible for watching the [EditorMgmt] component area.
Comment 8 Remy Suen CLA 2010-04-14 08:32:12 EDT
(In reply to comment #0)
> In Eclipse, if I open a file from the resource navigator, and then open the
> same file from the 'Open File...' menu (so, opening an external file) will
> create 2 editors for editing the same file.

This particular case doesn't seem to be a problem anymore.

If your case is still failing, Fabio, I believe you may have to ensure that 'true' is answered for 'equals(Object)' between your created editor input and the editor input that's already there in the currently opened editor.
Comment 9 Fabio Zadrozny CLA 2010-04-29 19:56:06 EDT
Actually, if you create a FileEditorInput and a FileStoreEditorInput for the same file in the filesystem, you also end up with 2 editors...

I think the real problem is that the equals of each class is being used, whereas what the user expects would be checking if it implements the default interfaces (e.g.: IURIEditorInput, IPathEditorInput, etc), and try to match that to a file in the filesystem to know if it matches.

Note that I was able to fix this in pydev by never creating an input directly, but through a factory method that will give priority for the FileEditorInput (so, for any file received -- e.g.: from the debugger -- it needs to search for a match in the workspace to create an IFile from it, but this is far from perfect as the same file could have multiple representations in the workspace and this shouldn't be needed if the editor input matching was better).
Comment 10 Eclipse Webmaster CLA 2019-09-06 16:04:39 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 11 Eclipse Genie CLA 2021-09-08 03:54:21 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.