Bug 37935 - [Editor Mgmt] [Plan Item] Allow editors to open files outside workspace
Summary: [Editor Mgmt] [Plan Item] Allow editors to open files outside workspace
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P2 enhancement with 7 votes (vote)
Target Milestone: 3.0   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: plan
: 2869 36949 38716 39189 39430 40661 58944 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-05-21 12:42 EDT by Jim des Rivieres CLA
Modified: 2006-08-23 08:39 EDT (History)
21 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jim des Rivieres CLA 2003-05-21 12:42:47 EDT
Allow editors to open files outside workspace. A common request is to be able 
to use Eclipse to open a file that is not part of the workspace, or perhaps 
even one on a remote system. In addition, applications would like to provide 
file extension associations so that double-clicking on a file in the OS 
desktop would open the associated Eclipse editor. The operations and 
capabilities available on these "outside of the workspace" files would need to 
be defined. [Platform UI] [Themes: User experience]
Comment 1 Jim des Rivieres CLA 2003-05-21 12:44:04 EDT
*** Bug 36949 has been marked as a duplicate of this bug. ***
Comment 2 Rafael Chaves CLA 2003-06-10 13:16:32 EDT
*** Bug 38716 has been marked as a duplicate of this bug. ***
Comment 3 Debbie Wilson CLA 2003-06-30 11:49:06 EDT
*** Bug 39430 has been marked as a duplicate of this bug. ***
Comment 4 Simon Arsenault CLA 2003-07-10 13:59:06 EDT
*** Bug 39189 has been marked as a duplicate of this bug. ***
Comment 5 Rafael Chaves CLA 2003-07-23 12:32:21 EDT
*** Bug 40661 has been marked as a duplicate of this bug. ***
Comment 6 Simon Arsenault CLA 2003-07-24 10:37:33 EDT
*** Bug 2869 has been marked as a duplicate of this bug. ***
Comment 7 Ed Burnette CLA 2003-09-15 17:11:54 EDT
The Fileopen plugin does this - it open files not part of the Workspace and 
provides a way to do file extension associations so that double-clicking on a 
file in the OS desktop will open the associated Eclipse editor. You have my 
permission to use any of the code in Eclipse if you want. See 
www.eclipsepowered.org > Download area > Fileopen. It works by creating a new 
class that implements IStorageEditorInput and a new class that implements 
IStorage, similar to the way viewing CVS resources and things in zip files 
work. Some of the ideas were from an earlier plugin called filedrag (see the 
readme). However filedrag worked by creating a new top level visible project 
called "Desktop" and using links.

Fileopen has some problems though. First, it's hard to make the file editable. 
Saves are controlled by IDocumentProvider instead of IStorage, and you can't 
always replace the document provider (Java forces its internal one no matter 
what). Even if you could replace the document provider, you wouldn't want to 
anyway because it also controls syntax highlighting. The second big problem is 
that annotations, markers, quickdiffs, and outlines are not functional. The 
edit area is flush against the left margin, and the regular context menus are 
not created. But it's better than nothing.

A new way:
It seems that the current plan for handling files outside the workspace is to 
not use Resources for them, but Resources are shot throughout the Eclipse API 
so this requires large API changes. I'm worried there might be some loss of 
functionality for Resource-less external files too - would all the editors 
work with them? Would outline managers? Markers? Resource change events? Would 
they suffer some of the same problems as Fileopen? I wondered if it would be 
possible to keep the concept of "Resource" but extend it to objects both 
within and without a Workspace. So I did some playing around this past week to 
try and find a totally different way to handle external files. This was just 
an experiment to see how far I could get, not a general solution. But I 
thought I'd share my findings here in case they would be useful.

Experiment:
Currently a Resource must be in the Workspace, in particular it has to be in 
the element tree that hangs off the WorkspaceRoot. So do all the Folders and 
Projects that lead down to it. Resources have an IPath, and various places in 
org.eclipse.core.resources make assumptions that the 0th segment of a path is 
the Project name. For the experiment I looked at opening files of the 
form //server/dir1/dir2/filename.ext (a UNC name). If I just try to get a 
resource for this file (workspace.getRoot().getFile(path)) it fails because no 
part of that path exists in the Workspace.

First I tried creating a File resource with a null workspace reference, but 
that didn't work at all because the core code makes heavy use of that pointer. 
So I went back to the current Workspace but added "//server" as a 
Project, "dir1" and "dir2" as Folders, and "filename.ext" as a File. I made 
the Project a phantom project so it would not show up in the navigator and 
would not be saved when the Workbench closed. Now, this has obvious problems 
(like, what if you had a real project called "server"), but it was good enough 
for the experiment.

Problems:
The first thing I ran into was that WorkspaceRoot.getProject() only takes a 
string, and it doesn't want to create a project with a UNC name, so I had to 
call Path.makeUNC(true) on the project after creating it.

I had to use an internal routine Workspace.createResource() to populate the 
element tree. Also, I had to explicitly call IResource.setLocal(true, 
DEPTH_ZERO, monitor) on the final File to make core.resources treat it as 
local. Although these UNC files were actually out on the network I believe it 
is correct to call them local in this context.

There were some problems preserving that UNC flag in different routines. For 
example FileSystemResourceManager.localtionFor() really wanted to make the 
project path non-UNC and relative to the Platform location so I put a special 
case there.

Several places called Resource.getResourceInfo() with a false phantom flag so 
it couldn't find my fake project. For example, PropertyManager.getPropertyStore
() and setPropertyStore(), several places in File, Project, and Resource.

Resource.getProject() ate the UNC flag by doing a getProject(path.segment(0)) 
so I had to add a special case there.

Finally there was a problem with Eclipse thinking the external file was out of 
date. I didn't completely track that down but I managed to work around it by 
modifying File.getContents().

Results:
I was able to view both a normal text file and a Java file (with outline) in 
the editor. I didn't try to edit read/write files but I'm sure that can be 
made to work. The usual marker and quickdiff areas were visible, as were the 
usual Java menu items like Search (but they complained because the current 
resource was not on the build path of any project). There were a few odd 
things but it looked better than my previous attempts that involved creating a 
new ExternalEditorInput class (ala fileopen).

Conclusions:
I've proven that it's possible to have Resource objects that don't really live 
in the Workspace. This could be a good way to support editing files outside 
the Workspace. I'm sure cleaner ways could be devised to do this, for example 
maybe there could be a new Resource type - currently you have ROOT, FILE, 
FOLDER, and PROJECT, how about EXTERNAL? Relying on the UNC file was pretty 
fragile so a new Resource type would be better.

My experimental code is purposefully kludgy so I'm hesitant to post it 
anywhere. But if you twist my arm and promise not to laugh too hard at it (I 
*can* write better code than this, honest :) then I can.
Comment 8 Dan Berger CLA 2003-09-18 18:30:35 EDT
Just a comment - I grabbed the file open plugin and it's a viable stopgap
solution.  But what I'd really like is to be able to create a view of part of
the file system in the Navigator pane, and be able to easily navigate and
open/edit files in that hierarchy.  JBuilder 8 has this functionality, and it's
very handy.  Means you essentially never need to leave the IDE.
Comment 9 Thomas Fletcher CLA 2003-10-05 23:47:44 EDT
This generic type of support is also generally required for handling
standard C/C++ support (the CDT project) which often includes source 
header file locations which are external to the workspace and shared 
in the system.  Being able to _easily_ incorporate these types of resources
without having to jump through many hoops would be delightful.
Comment 10 Steven Van Langendonck CLA 2004-01-06 06:31:46 EST
If this feature is available, it should be made possible with drag and drop. In
JBuilder (starting from 7) you simply drag a file to the text area and it gets
opened. Very handy if you have to open e.g. a configuration file or something.
Comment 11 Ed Burnette CLA 2004-02-25 17:17:17 EST
With 3.0 having the Open External File menu, why not mark this one complete? 
There are other bugs already open for the remaining issues:

- having an Open icon (bug 47486)
- defining the Control-O key sequence to do an Open (bug 47485)
- opening a file by dragging it onto Eclipse (bug 13221 and bug 21973 and bug 
36606 - some of these might be dups)
- double-clicking a file in a file explorer and have it open up in Eclipse by 
a file association (bug 21973)
- searching on external files (bug 29389)

Did I miss any?
Comment 12 Nick Edgar CLA 2004-02-25 17:41:30 EST
The Text team actually did this work on this one, and I'm not up to date on 
whether anything else remains to be done.
Comment 13 Dani Megert CLA 2004-02-26 03:00:34 EST


*** This bug has been marked as a duplicate of 21973 ***
Comment 14 Steven Van Langendonck CLA 2004-02-26 03:53:12 EST
This bug is marked as duplicate of bug 21973 which is marked as resolved. Still
I can not open a file outside my workspace :the open external file DOES NOT WORK
except for Java files. I leave the bug as it is sice I am not directly involved
in the project, but in my opinion this bug is not resolved.
Comment 15 Dani Megert CLA 2004-02-26 04:18:06 EST
Well, it works for me using I20040225 - just verified it again.
Please help us and file a bug report with steps to reproduce.
Comment 16 Ye Zhang CLA 2004-04-20 18:06:37 EDT
Yes in 3.0 you can "Open external file" but after you did some editing and you 
want to save the file to another different location in file system by 
selecting "Save as", you can not do it without the workspace. So, imo, this bug 
is not fixed, at least not completely.
Comment 17 Dani Megert CLA 2004-04-21 03:46:05 EDT
The bug is about opening the file and not "Saving as...". Please file a new
feature request.
Comment 18 John Arthorne CLA 2004-04-27 14:52:33 EDT
*** Bug 58944 has been marked as a duplicate of this bug. ***
Comment 19 Jim des Rivieres CLA 2004-04-28 13:29:01 EDT
This plan item has been revised. The sentence "In addition, applications would 
like to provide file extension associations so that double-clicking on a file 
in the OS desktop would open the associated Eclipse editor." has moved to a 
separate plan item (bug 60289).
Comment 20 Carolyn MacLeod CLA 2004-10-01 12:39:56 EDT
FYI, opened bug 75472 to address comment 17.
Comment 21 Carolyn MacLeod CLA 2004-10-01 14:18:39 EDT
Further to comment 11 - yes, you missed one:
- "Open" always follows "New" in the file menu (bug 75483).