gpt4 book ai didi

eclipse - 如何在编辑器页面获得 Eclipse 焦点时运行类?

转载 作者:行者123 更新时间:2023-12-02 17:15:34 25 4
gpt4 key购买 nike

是否有一种方法可以在每次编辑器页面接收焦点时运行一个类,例如类源在 Eclipse 外部更改时的提示消息?插件编辑器或扩展可以完成这项工作吗?

最佳答案

常见问题解答“How do I find out what view or editor is selected?”可以帮助您在编辑器处于事件状态时调用您的类(此时您可以测试它是否也具有焦点),作者:using a IPartService :

Two types of listeners can be added to the part service:

You should always use this second one as it can handle part-change events on parts that have not yet been created because they are hidden in a stack behind another part.
This listener will also tell you when a part is made visible or hidden or when an editor's input is changed:

IWorkbenchPage page = ...;
//the active part
IWorkbenchPart active = page.getActivePart();
//adding a listener
IPartListener2 pl = new IPartListener2() {
public void partActivated(IWorkbenchPartReference ref)
System.out.println("Active: "+ref.getTitle());
}
... other listener methods ...
};
page.addPartListener(pl);

注:IWorkbenchPage直接实现IPartService
您还可以通过 using IWorkbenchWindow.getPartService() 获取激活服务.

关于eclipse - 如何在编辑器页面获得 Eclipse 焦点时运行类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4294738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com