user feedback during plugin activity?

My plugin iterates over lots of PsiElements, changing almost all of them.

If the file is large, it gets real slow, sometimes popping up a dialog "optimizing imports" or some such (it is real quick.. I cannot read it).

Two questions:

1. Can I speed up this plugin, deferring whatever those popups are telling me about until everything is done?

2. How do Alert the user when the plugin has completed its magic?  Should I lock the UI while the plugin is underway?

6 comments
Comment actions Permalink

You can wrap the entire operation of your plugin into a single progress indicator - use the ProgressManager.runProcessWithProgress() method for that.

0
Comment actions Permalink

Is there an example of this somewhere?

0
Comment actions Permalink

Just open the Community Edition source code and do a Find Usages on the method. You'll find a ton of examples.

0
Comment actions Permalink

Tips like these are immensely important for us plugin devs, since the chance of stumbling upon gems like this is very small! Thank you and keep 'em coming! :)

0
Comment actions Permalink

Warner: If you happen to get to learning how to implement this before I do, please share.  I've'n't had a chance to review the source code yet to discern the technique.

0
Comment actions Permalink

Here you go, it's really easy once you know which classes you have to use ;)

This is for a background task:

ProgressManager.getInstance().run(new Task.Backgroundable(project, "Performing some background task", true, PerformInBackgroundOption.ALWAYS_BACKGROUND) {
    @Override
    public void run(@NotNull ProgressIndicator indicator) {
        //long running task here
        //Use the ProgressIndicator to change status text and more
    }
});

This is for a foreground task:

ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
                public void run() {
                    //task here
               }
}, "Title here", true, project);

0

Please sign in to leave a comment.