trivial question about editor [message #295915] |
Mon, 12 December 2005 06:59  |
Eclipse User |
|
|
|
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 #295929 is a reply to message #295921] |
Mon, 12 December 2005 10:29   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03426 seconds