问题描述
我正在尝试在我的 Eclipse 插件中添加 IResourceChangeListener,使用以下教程:
https://eclipse.org/articles/Article-Resource-deltas/resource-deltas.html
但是,我从来没有找到任何地方,我应该在哪里添加这些侦听器代码.我发现他们只是在创建一个新类,在其中添加了侦听器代码.如果我将它添加到任何 java 类中,那么 eclipse 将如何知道事件发生时触发哪个类?我尝试将代码放在 activator.java 中,如下所示(我将其添加到那里是因为它维护了插件生命周期).
我修改了启动和停止方法.
但它不起作用.当我通过外部 MKS 签出更改我当前的编辑器时,它没有将某些内容已更改"打印到 consol,或者根本无法正常工作.
我怎样才能让它工作?我应该在哪里实际添加代码?我想在 eclipse 中修改工作编辑器(可以是默认的 java 编辑器),而不用这个监听器创建任何新的编辑器.
非常感谢.
有两种方法可以做到这一点.
- 通过实现 IResourceChangeListener 编写您自己的类.这将提供良好的控制.
- 使用下面的代码
<块引用>
workspace.addResourceChangeListener(listener,IResourceChangeEvent.POST_CHANGE|IResourceChangeEvent.PRE_BUILD);
I am trying to add IResourceChangeListener in my eclipse plugin, using following tutorial:
https://eclipse.org/articles/Article-Resource-deltas/resource-deltas.html
However, I never found anywhere, where should I add these listener code. I found that they are just creating a new class where they added the listener code. If I add it just in any java class, then how eclipse will know, which class to trigger when the events occur? I tried to put the code in activator.java as following (I added it there because it maintains the plugin life cycle).
I modified the start and stop method.
But its not working. When I change my current editor by external MKS check out, its not printing "Something has changed" to consol, or simply its not working.
How can I make it working? Where should I add the code actually? I want to modify the working editor (can be default java editor) in eclipse without creating any new editor with this listener.
Thanks a lot in advance.
There are 2 ways to do this.
- Write your own class by implementing IResourceChangeListener. This will provide fine control.
- Use below code
workspace.addResourceChangeListener(listener,IResourceChangeEvent.POST_CHANGE|IResourceChangeEvent.PRE_BUILD);
这篇关于如何在 Eclipse 插件中添加 IResourceChangeListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!