Editor Open Listener [message #299491] |
Fri, 17 February 2006 19:06  |
Eclipse User |
|
|
|
Originally posted by: ian.ianbull.com
I am trying to write a plugin that will be notified every time an editor
is opened. So far I have implemented an IPartListener and on startup
(using the ui.startup extension point) I add the IPartListener to every
"page" in the workbench.
IWorkbenchWindow window =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage[] pages = window.getPages();
for (int i = 0; i < pages.length; i++) {
IWorkbenchPage p = pages[i];
p.addPartListener(new MyPartListener());
}
}
this seem to work. However, editors that are already opened are missed.
Is there a way to get these editors added?
Thanks,
Ian
|
|
|
|
|
Re: Editor Open Listener [message #299517 is a reply to message #299494] |
Mon, 20 February 2006 05:47  |
Eclipse User |
|
|
|
Originally posted by: daniel.megert.eclipse.org
AL wrote:
> Have your class implement org.eclipse.ui.IPartListener.
Even better: use IPartListener2.
Dani
> Then you get notified when a workbench part (an IEditorPart, etc.)
> just got opened/closed. You can actually filter out which parts you
> want to pay attention to.
>
> The tricky part (no pun intended) is to register the listener to
> workbench.
>
> So, the first thing to do is get a valid IWorkbenchPage so that you
> can call IWorkbenchPage.addPartListener(<your class that implements
> IPartListener>).
>
> Here is how to get a workbench page.
>
> IWorkbenchPage page = null;
> IWorkbenchWindow window =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow();
> if (window != null)
> {
> page = window.getActivePage();
> }
>
> if (page == null)
> {
> // Look for a window and get the page off it!
> IWorkbenchWindow[] windows =
> PlatformUI.getWorkbench().getWorkbenchWindows();
> for (int i = 0; i < windows.length; i++)
> {
> if (windows[i] != null)
> {
> window = windows[i];
> page = windows[i].getActivePage();
> if (page != null)
> break;
> }
> }
> }
>
> Ian Bull wrote:
>
>> Let me clarify a bit... When I say "already opened" I mean the ones
>> that are opened from my previous run of eclipse. It seems that the
>> early startup runs after these editors are opened.
>>
>> I could go through and look for currently opened editors, but I
>> actually want to change the way some of the data is loaded, so I need
>> to get a handle to the editor before it actually loads its contents.
>>
>> - ian
>>
>>
>> Ian Bull wrote:
>>
>>> I am trying to write a plugin that will be notified every time an
>>> editor is opened. So far I have implemented an IPartListener and on
>>> startup (using the ui.startup extension point) I add the
>>> IPartListener to every "page" in the workbench.
>>>
>>>
>>> IWorkbenchWindow window =
>>> PlatformUI.getWorkbench().getActiveWorkbenchWindow();
>>>
>>> if (window != null) {
>>> IWorkbenchPage[] pages = window.getPages();
>>> for (int i = 0; i < pages.length; i++) {
>>> IWorkbenchPage p = pages[i];
>>> p.addPartListener(new MyPartListener());
>>> }
>>> }
>>>
>>> this seem to work. However, editors that are already opened are
>>> missed. Is there a way to get these editors added?
>>>
>>> Thanks,
>>> Ian
>>
|
|
|
Powered by
FUDForum. Page generated in 0.07965 seconds