Hook to Save Action in Eclipse plugin(在 Eclipse 插件中保存操作的挂钩)
问题描述
我想为 Eclipse 创建一个 Google Closure Compiler 插件.我已经有一个弹出菜单项来将 JavaScript 文件编译为其缩小版本.但是,如果您每次保存 *.js 时都会自动生成缩小版本,那将非常有帮助.我读过/听说过性质和构建器、扩展点和 IResourceChangeListener.但我没有弄清楚我应该使用什么,尤其是如何让它发挥作用.
I want to create a Google Closure Compiler plugin for Eclipse. I already have a popup menu entry to compile a JavaScript file to its minified version. But it would be more than helpful if every time you save a *.js that minified version would be generated automatically. I read/heard about natures and builders, extension points and IResourceChangeListener. But I did not manage to figure out what I should use and especially how to get it to work.
是否有一个插件的工作示例可以执行相同类型的事情",以便我可以使用它或教程来编写这样的东西?
Is there a working example of a plugin that does "the same kind of thing" so I can work from that or a tutorial to write such?
根据下面的答案,我搜索了使用 IResourceChangeListener 的项目并想出了以下代码:
With the answer below I searched for projects that use the IResourceChangeListener and came up with this code:
清单:http://codepaste.net/3yahwe
plugin.xml:http://codepaste.net/qek3rw
激活器:http://codepaste.net/s7xowm
DummyStartup:http://codepaste.net/rkub82
DummyStartup: http://codepaste.net/rkub82
MinifiedJavascriptUpdater:http://codepaste.net/koweuh
MinifiedJavascriptUpdater: http://codepaste.net/koweuh
在包含 IResourceChangeListener 代码的 MinifiedJavascriptUpdater.java 中,永远无法到达 resourceChanged() 函数.
There in the MinifiedJavascriptUpdater.java which holds the code for the IResourceChangeListener the resourceChanged() function is never reached.
推荐答案
从这里回答 http://www.eclipse.org/forums/index.php/t/362425/
解决方法是将代码放入激活器,去掉MinifiedJavascriptUpdater:
Solution is to get the code into the activator and get rid of the MinifiedJavascriptUpdater:
package closure_compiler_save;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "closure-compiler-save"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
} //gets here
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
Activator.plugin = this;
ResourcesPlugin.getWorkspace().addResourceChangeListener(new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
System.out.println("Something changed!");
}
});
}
@Override
public void stop(BundleContext context) throws Exception {
Activator.plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
这篇关于在 Eclipse 插件中保存操作的挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Eclipse 插件中保存操作的挂钩
基础教程推荐
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
