1

I was wondering if there is a manner to make it impossible to open more than 1 editor at a time? what I have now is a button that each time it is pressed gives a new editor. I am using eclipse RCP

thanks

jean
  • 11
  • 1
  • 1
    Why are you using an editor? - Doesn't make a ViewPart which is refreshed on clicking on the button much more sense at all? - What happens if the editor is dirty, what if the editor contains invalid values? – Tom Seidel Aug 12 '11 at 17:54

1 Answers1

1

You could add an IPartListener on the IPartService of the IWorkbenchWindow that close all other editors when a new editor is opened. You find the current set of editors via IWorkbenchPage.getEditorReferences().

Tonny Madsen
  • 12,628
  • 4
  • 31
  • 70
  • Assuming that there is always only one editor open, IWorkbenchPage.getActiveEditor() should be enough ;) – Tom Seidel Aug 12 '11 at 17:57
  • 1
    @Tom Well, the problem is that you only get notified _after_ the new editor is opened and then `IWorkbenchPage.getActiveEditor()` will return the new editor and not the old editor. Anyway, I usually prefer algorithms that have as few pre-conditions as possible - even if it is a little more complex... :-) – Tonny Madsen Aug 12 '11 at 18:13
  • you're right. My comment was misleading, getActiveEditor must be called **before** opening the new editor. Anyways, probably the easiest would be IWorkbenchPage.closeAllEditors(save) before opening a new one :) – Tom Seidel Aug 12 '11 at 18:30
  • Agree... The problem is just how to do that. AFAIK, there are no hook or listener for just that :-( – Tonny Madsen Aug 12 '11 at 22:59
  • @Tom Ohh, I agree about the use of views rather than editors. Any day! – Tonny Madsen Aug 12 '11 at 23:00