简体   繁体   English

Eclipse插件完全取消

[英]Eclipse Plugin Cancel Completely

When in an eclipse plugin you implement Job and Override the run()-method, you can make changes to the parameter IProgressMonitor and skip tasks if the user pushed Cancel like this: 在eclipse插件中实现Job并覆盖run()方法时,可以更改参数IProgressMonitor并跳过该任务(如果用户按如下所示按Cancel):

        if (!monitor.isCanceled()){
            monitor.subTask("Doing stuff");
            //do task
        } else {
            returnedStatus = Status.CANCEL_STATUS;
        }

But that means that at least the currently active task has to be finished before skipping the rest. 但这意味着至少当前活动的任务必须先完成才能跳过其余任务。 Is there any way to completely abort the plugin activity and execute a finally block when the user pushes cancel, without waiting for the next if (!monitor.isCanceled()) and without subdividing your whole program into subTasks? 有什么方法可以完全中止插件活动,并在用户按下cancel时执行finally块,而无需等待下一个if (!monitor.isCanceled())并且无需将整个程序细分为subTasks?

No. Your Job has to be the one to react to cancellation, so you need to either break the job up into tasks for which you can report progress with worked() and check cancellation, or you have to send around sub-progressmonitors and do the same thing. 不能。您的工作必须是对取消做出反应的一项工作,因此您需要将工作分解为一些任务,您可以报告worked()进度并检查取消,或者您必须派遣子进度监视器并执行一样的东西。

https://eclipse.org/articles/Article-Progress-Monitors/article.html https://eclipse.org/articles/Article-Progress-Monitors/article.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM