Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Open a file(Not in a project)
Open a file [message #714225] Wed, 10 August 2011 05:44 Go to next message
Kitesurfer () is currently offline Kitesurfer ()Friend
Messages: 87
Registered: December 2009
Member

How do I open (in a plugin) an external file in Eclipse, but not in a projekt ? ... so just an editor-window.

It must be possible, because when I open a file via menu "File", "Open file ..." it opens the file outside a projekt in an editorwindow, and my plugin (with reserved words and stuff) does it's thing.
Re: Open a file [message #714266 is a reply to message #714225] Wed, 10 August 2011 07:30 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 10.08.2011 07:44, Kitesurfer wrote:
>
> How do I open (in a plugin) an external file in Eclipse, but not in a
> projekt ? ... so just an editor-window.
>
> It must be possible, because when I open a file via menu "File", "Open
> file ..." it opens the file outside a projekt in an editorwindow, and
> my plugin (with reserved words and stuff) does it's thing.
>
See org.eclipse.ui.ide.IDE.openEditorOnFileStore(IWorkbenchPage,
IFileStore).

Dani
Re: Open a file [message #714291 is a reply to message #714266] Wed, 10 August 2011 08:59 Go to previous messageGo to next message
Kitesurfer () is currently offline Kitesurfer ()Friend
Messages: 87
Registered: December 2009
Member
Hi Dani,

Thanks for your reply. Doing it with "openEditorOnFileStore" only works if the file-extension is by default opened with Eclipse (f.e. when you double-click in the Windows file Explorer). For files that are by default opened f.e. with Notepad it doesn't work ... whereas when I open these files via menu "Open - Open file ..." the file (off course) is opened by Eclipse.

Do you have any idea how menu "Open - Open file ..." does it ?
Re: Open a file [message #714325 is a reply to message #714291] Wed, 10 August 2011 10:22 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 10.08.2011 10:59, Kitesurfer wrote:
> Hi Dani,
>
> Thanks for your reply. Doing it with "openEditorOnFileStore" only
> works if the file-extension is by default opened with Eclipse (f.e.
> when you double-click in the Windows file Explorer). For files that
> are by default opened f.e. with Notepad it doesn't work ... whereas
> when I open these files via menu "Open - Open file ..." the file (off
> course) is opened by Eclipse.
>
> Do you have any idea how menu "Open - Open file ..." does it ?
Yes, it calls the method I gave you. I guess when you tested in your
workspace, you had an association defined in Eclipse.

Dani
Re: Open a file [message #714342 is a reply to message #714325] Wed, 10 August 2011 11:22 Go to previous messageGo to next message
Kitesurfer () is currently offline Kitesurfer ()Friend
Messages: 87
Registered: December 2009
Member
Nope, the association is not to Eclipse.
But I got it working with a method of the same class :
IDE.openEditor( page, lcUri, lcEditorId, true );

Thanks for your help. By the way, do you know how to prevent this :

when I remove (via my plugin, but also when I do it manually) the last file from a project the project visually still has one empty "something" open. I see a small dotted line in the project. When I unfold the project, it's gone. Is this something I could prevent in my plugin when I remove the last files ?

Re: Open a file [message #715082 is a reply to message #714342] Fri, 12 August 2011 10:17 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 10.08.2011 13:22, Kitesurfer wrote:
> Nope, the association is not to Eclipse.
Well, you can File > Open File on some file type not known by Eclipse
and it will open it with the OS editor.
> But I got it working with a method of the same class :
> IDE.openEditor( page, lcUri, lcEditorId, true );
>
> Thanks for your help. By the way, do you know how to prevent this :
>
> when I remove (via my plugin, but also when I do it manually) the last
> file from a project the project visually still has one empty
> "something" open. I see a small dotted line in the project.
I've never seen that.

Dani
> When I unfold the project, it's gone. Is this something I could
> prevent in my plugin when I remove the last files ?
>
>
Re: Open a file [message #716379 is a reply to message #715082] Wed, 17 August 2011 08:47 Go to previous message
Kitesurfer () is currently offline Kitesurfer ()Friend
Messages: 87
Registered: December 2009
Member
There is a difference between files opened inside / outside a project.
I have made a new editor which is attached to file-extension ABC.

When I open an ABC-file inside a project, I can get its full filename with below code :

private IEditorPart prvEditor;
private IEditorInput prvEditorInput;
private IFileEditorInput prvFEI;
private IFile prvFile;
private String prvFullFileName;

prvEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
prvEditorInput = prvEditor.getEditorInput();
prvFEI = (IFileEditorInput) prvEditorInput;
prvFile = prvFEI.getFile();
prvFullFileName = prvFile.getLocation().toOSString();

When I open an ABC-file outside a project, I can't get its full filename with above code, it goes into catch on statement "prvFEI = (IFileEditorInput) prvEditorInput;"

How to make above code working for a file which is opened outside a project?

Previous Topic:Report Engine history log
Next Topic:CTabFolder using GridLayout
Goto Forum:
  


Current Time: Thu Apr 25 23:11:37 GMT 2024

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

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

Back to the top