Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Programmatically close file in text editor?
Programmatically close file in text editor? [message #1065030] Sun, 23 June 2013 16:40 Go to next message
Eclipse Explorer is currently offline Eclipse Explorer
Messages: 18
Registered: February 2013
Junior Member
Hello,

I have a TextEditor open and it displays text from several files.

How can I programmatically close one of these files?

Thanks for your help.
Re: Programmatically close file in text editor? [message #1065032 is a reply to message #1065030] Sun, 23 June 2013 17:11 Go to previous messageGo to next message
Luuk 34 is currently offline Luuk 34
Messages: 12
Registered: November 2012
Junior Member
On 23-06-2013 18:40, Eclipse Explorer wrote:
> Hello,
>
> I have a TextEditor open and it displays text from several files.
>
> How can I programmatically close one of these files?
>
> Thanks for your help.
>


You dont have to write a program for that,
The have a build in key, just for that purpose
It's: ALT+F4


;)
Re: Programmatically close file in text editor? [message #1065033 is a reply to message #1065032] Sun, 23 June 2013 17:29 Go to previous messageGo to next message
Eclipse Explorer is currently offline Eclipse Explorer
Messages: 18
Registered: February 2013
Junior Member
Thanks Luuk,

I realize that I can use key combinations, or click the "x" in the editor. However, the logic for the code that I am writing requires that I close the file programmatically.
Re: Programmatically close file in text editor? [message #1065034 is a reply to message #1065033] Sun, 23 June 2013 18:55 Go to previous messageGo to next message
Luuk 34 is currently offline Luuk 34
Messages: 12
Registered: November 2012
Junior Member
On 23-06-2013 19:29, Eclipse Explorer wrote:
> Thanks Luuk,
>
> I realize that I can use key combinations, or click the "x" in the
> editor. However, the logic for the code that I am writing requires that
> I close the file programmatically.

Ok,
what language do you want to program this in?
and on what OS?

If its Windows, take look at AutoIt
(http://www.autoitscript.com/site/autoit/)
Re: Programmatically close file in text editor? [message #1065039 is a reply to message #1065034] Mon, 24 June 2013 03:30 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2266
Registered: July 2009
Senior Member
You should call IWorkbenchPage.html#closeEditor() .

http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/IWorkbenchPage.html


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: Programmatically close file in text editor? [message #1065156 is a reply to message #1065039] Mon, 24 June 2013 14:07 Go to previous messageGo to next message
Eclipse Explorer is currently offline Eclipse Explorer
Messages: 18
Registered: February 2013
Junior Member
Hi Nitin,

When the editor has several pages (files) open, I only want to close one of the pages.

The snippet that you provided closes all the pages.

Thanks for your help.

Re: Programmatically close file in text editor? [message #1065157 is a reply to message #1065156] Mon, 24 June 2013 14:12 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2266
Registered: July 2009
Senior Member
It's not possible to close a single page of a MultiPageEditorPart without that editor having done a significant amount of work to allow it, and presumably, giving you an API of its own to do so. There's no standard way to do so.

---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: Programmatically close file in text editor? [message #1065162 is a reply to message #1065157] Mon, 24 June 2013 14:33 Go to previous messageGo to next message
Eclipse Explorer is currently offline Eclipse Explorer
Messages: 18
Registered: February 2013
Junior Member
Hi Nitin,

It's not a multipage editor; it's an extension from org.eclipse.ui.editors.text.TextEditor.

An analogy is the Java Editor. If you have several java files open, and delete one of these files in the Package Explorer, "Eclipse" no longer displays the file that you deleted in the Java editor. I am attempting to accomplish this programmatically.

Once again, thank you for your help.
Re: Programmatically close file in text editor? [message #1065382 is a reply to message #1065162] Tue, 25 June 2013 13:58 Go to previous message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2266
Registered: July 2009
Senior Member
If that's the case, you should look more closely at the JavaDoc page I linked. There are methods for closing specific editor parts.

---
Nitin Dahyabhai
Eclipse WTP, IBM
Previous Topic:Java: Multidimensional Array Initialization Formatting
Next Topic:JUnit plugin
Goto Forum:
  


Current Time: Wed Sep 17 01:32:50 GMT 2014

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

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