当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to add a listener to the default code editor in Eclipse?

问题描述:

I want to add a listener to the default code editor in Eclipse. It should be triggered whenever a new code file is opened or closed. Is there anything available like that? I did a google search for hours, but could find a working solution.

I'm especially focusing the default Java code editor. But once I know how to hook into such an editor it shouldn't be a big problem to add additional ones. The main problem I have so far is, that I don't know what I should do with the IEditorDescriptor I could get.

网友答案:

You can register an IPartListener2 with the PartService, for example:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(aListener)

There are other ways to register the IPartListener, for example if you have a reference to an IWorkbenchPage.

The part listener is notified when editors are opened or closed, among other things. For IPartListener2, you get an IWorkbenchPartReference which you can use to check what kind of editor is involved. For example, to detect the standard Java editor, you can check for the ID org.eclipse.jdt.ui.CompilationUnitEditor.

分享给朋友:
您可能感兴趣的文章:
随机阅读: