Eclipse 关闭钩子能够停止终止

编程入门 行业动态 更新时间:2024-10-15 16:20:49
本文介绍了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屋!

更多推荐

[db:关键词]

本文发布于:2023-03-19 07:47:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/637048.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:钩子   Eclipse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!