如何在编辑页面上随时运行一个类来重点关注Eclipse? [英] How to run a class anytime a editor page receive focus on Eclipse?

查看:93
本文介绍了如何在编辑页面上随时运行一个类来重点关注Eclipse?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次编辑器页面都接收到焦点时,是否有一种方法来运行类,当类源文件在eclipse之外更改时,会出现提示信息?插件编辑器或扩展程序可以执行此操作吗?

Is there a way to run a class everytime editor page receive focus, something like prompt message when a class source has changed outside eclipse? Can a plug-in editor or extension do this work?

推荐答案

常见问题如何找到选择的视图或编辑器?可以帮助您在编辑器处于活动状态时调用您的课程(当您可以测试是否具有焦点时),由使用 IPartService

The FAQ "How do I find out what view or editor is selected?" can help you call your class when the Editor is active (which is when you can test if it has focus as well), by using a IPartService:


可以将两种类型的侦听器添加到零件服务中:

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




  • IPartListener

  • 命名不及的 IPartListener2


  • 您应该总是使用第二个,因为它可以处理零件上的零件更改事件尚未创建,因为它们隐藏在另一部分后面的堆栈中。

    此监听器还会告诉您,当某个部分可见或隐藏时,或者编辑者的输入更改时:

    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 br>
    您还可以通过使用 IWorkbenchWindow.getPartService()

    Note: IWorkbenchPage implements IPartService directly.
    You can also access an activation service by using IWorkbenchWindow.getPartService().

    这篇关于如何在编辑页面上随时运行一个类来重点关注Eclipse?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆