Eclipse 关闭钩子能够停止终止 [英] Eclipse shut down hook able to stop the termination

查看:12
本文介绍了Eclipse 关闭钩子能够停止终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个插件.该插件执行外部工具,如果用户尝试退出 Eclipse,当进程正在运行时,我必须提供一个确认对话框.有正在运行的进程.你真的要退出吗? 如果用户点击No,Eclipse 可能不会终止.

I'm working on a plugin. The plugin executes external tools and I have to provide a confirm dialog, if the user tries to exit Eclipse, when a process is running yet. There are running processes. Do you really want to exit? If the user clicks No, the Eclipse may not terminate.

我刚刚发现,如何将退出命令挂接到清理的想法.(插件的激活器有 stop() 方法.)但是 Eclipse 总是不可避免地终止.

I've just found, how to hook the exit command to clean thinks up. (The plugin's activator has the stop() method.) But the Eclipse will always terminate inevitably.

推荐答案

一位同事帮我解决了问题.解决方案其实很简单.我只需要一个在激活器中注册的 worgbench 侦听器.侦听器有两种方法用于关闭前和关闭后的事件.第一个返回布尔值.如果返回 true,则 Eclipse 退出.否则退出程序被中断,用户可以继续他的工作.

One colleague helped me to solve the problem. The solution is actually easy. All I need is a worgbench listener registered in activator. The listener has two methods for events pre- and postshutdown. The first one returns boolean. If it has returned true, the Eclipse exits. Otherwise the exit procedure is interrupted and the user can continue in his work.

在激活器类中:

public void start(BundleContext context) {
    ...
    IWorkbench iwb = PlatformUI.getWorkbench();
    WBListener wbl = new ...;
    iwb.addWorkbenchListener(wbl);
    ...
}

WBListener的代码:

import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;

public class WBListener implements IWorkbenchListener {

    @Override
    public void postShutdown(IWorkbench w) {
    }

    @Override
    public boolean preShutdown(IWorkbench w, boolean b) {
        boolean exitEclipse = ...; //get it somehow

        return exitEclipse;
    }
}

就是这样.

这篇关于Eclipse 关闭钩子能够停止终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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