Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » trivial question about editor
trivial question about editor [message #295915] Mon, 12 December 2005 06:59 Go to next message
Eclipse UserFriend
Originally posted by: atykhonov.i-hypergrid.com

How I can open ANY file on my computer by means of default editor?

I try IDE.openEditor but for sorry I do not know where and how can get the
needed interfaces. :(
Re: trivial question about editor [message #295917 is a reply to message #295915] Mon, 12 December 2005 08:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

In short: you can't. Eclipse only knows about the resources under its watchful eye, which includes the files contained in each of the projects in the workspace. If the file isn't in the workspace, then you won't be able to open it up in an Eclipse editor.

On the other hand, if you want to open any type of file in the Eclipse workspace, you can right-click the file and choose 'Open With' to select editing in the default editor.

Alex.
Re: trivial question about editor [message #295921 is a reply to message #295917] Mon, 12 December 2005 09:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: atykhonov.i-hypergrid.com

Alex Blewitt wrote:

> In short: you can't. Eclipse only knows about the resources under its
watchful eye, which includes the files contained in each of the projects in
the workspace. If the file isn't in the workspace, then you won't be able to
open it up in an Eclipse editor.

hmmm...
in this case, why we CAN open any local file which placed outside
workspace, by means of File->Open, or File->Open File? How I can do the
same but from plugin?
Re: trivial question about editor [message #295926 is a reply to message #295921] Mon, 12 December 2005 10:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

Novel... I didn't know you could do that. Opening up a file certainly doesn't play well with other views; the outline doesn't work, nor do other project-oriented views (e.g. members/types/packages view) ...

Maybe it's firing up a particular type of editor that handles external files instead of Eclipse's internal file representation. If I find out more, I'll let you know.

Alex.
Re: trivial question about editor [message #295927 is a reply to message #295926] Mon, 12 December 2005 10:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: atykhonov.i-hypergrid.com

Alex Blewitt wrote:

> Novel...

Not novel.

> I didn't know you could do that. Opening up a file certainly doesn't > >
play > well with other views; the outline doesn't work, nor do other > > >
> > > project-oriented views (e.g. members/types/packages
view) ...

I am not interested in working of opened editor with other views, outline
etc. I need just open file that placed outside workspace. That's all.

> Maybe it's firing up a particular type of editor that handles external files
> > instead of Eclipse's internal file representation. If I find out
more, I'll let > you know.

Thank you.

> Alex.
Re: trivial question about editor [message #295928 is a reply to message #295926] Mon, 12 December 2005 10:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: automatic.javalobby.org

It looks like it's kicking off something via the (internal) OpenExternalFileAction which is then crafted to cunningly instantiate a text editor, which is defaulting to a JAvaFileEditorInput (thus limiting the choicse of what type of file it can handle, I guess).

As far as I know, there's no public API to be able to do the same thing and/or hook it into Eclipse, but I've been wrong before :-)

Alex.
Re: trivial question about editor [message #295929 is a reply to message #295921] Mon, 12 December 2005 10:29 Go to previous messageGo to next message
Eclipse UserFriend
atykhonov@i-hypergrid.com (Andrey) wrote in
news:71fde607fb6893577723e31e7744a323$1@eclipse.org:

> Alex Blewitt wrote:
>
>> In short: you can't. Eclipse only knows about the resources under
>> its watchful eye, which includes the files contained in each of
>> the projects in the workspace. If the file isn't in the workspace,
>> then you won't be able to open it up in an Eclipse editor.
>
> hmmm...
> in this case, why we CAN open any local file which placed outside
> workspace, by means of File->Open, or File->Open File? How I can do
> the same but from plugin?

Take a look at class "OpenExternalFileAction" in
org.eclipse.ui.editors/org.eclipse.ui.internal.editors.text.

The underlying trick is to implement a class that can create an
IEditorInput when given a java.io.File object. The existing
"JavaFileEditorInput" can do that, but it's internal to
org.eclipse.ui.editors (in the same package as
OpenExternalFileAction), so you can't reference it directly from your
plugin.

I had to do this for our own project, but had to go farther to allow
the user to not only open an external file, but to choose which
editor was going to be used to edit it since we had no control on
what extension (if any) was on any particular filename.

--
Bert Hyman | Unisys - Roseville MN
bert.hyman@unisys.com | (651) 635-7791 | net2: 524-7791
Re: trivial question about editor [message #295931 is a reply to message #295929] Mon, 12 December 2005 10:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: atykhonov.i-hypergrid.com

Bert Hyman wrote:

> atykhonov@i-hypergrid.com (Andrey) wrote in
> news:71fde607fb6893577723e31e7744a323$1@eclipse.org:

>> Alex Blewitt wrote:
>>
>>> In short: you can't. Eclipse only knows about the resources under
>>> its watchful eye, which includes the files contained in each of
>>> the projects in the workspace. If the file isn't in the workspace,
>>> then you won't be able to open it up in an Eclipse editor.
>>
>> hmmm...
>> in this case, why we CAN open any local file which placed outside
>> workspace, by means of File->Open, or File->Open File? How I can do
>> the same but from plugin?

> Take a look at class "OpenExternalFileAction" in
> org.eclipse.ui.editors/org.eclipse.ui.internal.editors.text.

> The underlying trick is to implement a class that can create an
> IEditorInput when given a java.io.File object. The existing
> "JavaFileEditorInput" can do that, but it's internal to
> org.eclipse.ui.editors (in the same package as
> OpenExternalFileAction), so you can't reference it directly from your
> plugin.

> I had to do this for our own project, but had to go farther to allow
> the user to not only open an external file, but to choose which
> editor was going to be used to edit it since we had no control on
> what extension (if any) was on any particular filename. Can you give short
example how


can you give short example code?
thank you in advance!
Re: trivial question about editor [message #295935 is a reply to message #295931] Mon, 12 December 2005 12:42 Go to previous message
Eclipse UserFriend
atykhonov@i-hypergrid.com (Andrey) wrote in
news:c0a8e5f54508b60e13cd067470e889fc$1@eclipse.org:

> Bert Hyman wrote:
>
>> atykhonov@i-hypergrid.com (Andrey) wrote in
>> news:71fde607fb6893577723e31e7744a323$1@eclipse.org:
>
>>> Alex Blewitt wrote:
>>>
>>>> In short: you can't. Eclipse only knows about the resources
>>>> under its watchful eye, which includes the files contained in
>>>> each of the projects in the workspace. If the file isn't in the
>>>> workspace, then you won't be able to open it up in an Eclipse
>>>> editor.
>>>
>>> hmmm...
>>> in this case, why we CAN open any local file which placed outside
>>> workspace, by means of File->Open, or File->Open File? How I can
>>> do the same but from plugin?
>
>> Take a look at class "OpenExternalFileAction" in
>> org.eclipse.ui.editors/org.eclipse.ui.internal.editors.text.
>
>> The underlying trick is to implement a class that can create an
>> IEditorInput when given a java.io.File object. The existing
>> "JavaFileEditorInput" can do that, but it's internal to
>> org.eclipse.ui.editors (in the same package as
>> OpenExternalFileAction), so you can't reference it directly from
>> your plugin.
>
>> I had to do this for our own project, but had to go farther to
>> allow the user to not only open an external file, but to choose
>> which editor was going to be used to edit it since we had no
>> control on what extension (if any) was on any particular filename.
>> Can you give short
> example how
>
>
> can you give short example code?

Well, the entire "OpenExternalFileAction.java" is only about 200
lines of code, and the "JavaFileEditorInput.java" is about 150 lines
(including comments).

But, the heart of OpenExternalFileAction is this:

IEditorInput input= createEditorInput(file);
String editorId= getEditorId(file);
IWorkbenchPage page= fWindow.getActivePage();
page.openEditor(input, editorId);

For an external (non-project) file, routine "createEditorInput"
collapses to just:

return new JavaFileEditorInput(file);

The routine getEditorId looks in the "editor registry":

IEditorRegistry editorRegistry= workbench.getEditorRegistry();

to find an editor that specifically knows how to handle "file", or if
it can't find one, returns the default text editor ID:

EditorsUI.DEFAULT_TEXT_EDITOR_ID;

> thank you in advance!

Exploring the existing Eclipse source code and "borrowing" parts you
need is a tradition worth preserving.

--
Bert Hyman | Unisys - Roseville MN
bert.hyman@unisys.com | (651) 635-7791 | net2: 524-7791
Previous Topic:Reading from plugin folder...
Next Topic:Ant Variables to Eclipse .classpath
Goto Forum:
  


Current Time: Fri May 02 08:23:11 EDT 2025

Powered by FUDForum. Page generated in 0.03426 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top