9 comments

Hi François,

I’m sorry for the delay. This class looks internal from the beginning (it is located in impl package of a *-impl.jar module, see: https://plugins.jetbrains.com/docs/intellij/explore-api.html#26-refrain-from-using-internal-classes), and was documented probably by accident. We will probably remove it from the docs soon.

I think widgets should be controlled only from the menu displayed after right-clicking the status bar.
Why do you need to do it programmatically? What is the use case?

0

Thanks Karol Lewandowski!

I work on the Preview.js IntelliJ plugin, which starts a local dev server on user action. I'd like to use the status bar to show a widget that says "Preview.js server running". Clicking on it would let you either stop the server, or open the browser at the corresponding URL. Of course, the widget should only appear when the server is running!

If this is not possible, what approach would you recommend? Perhaps setting the widget text to an empty string?

0

Hi Karol Lewandowski, as I didn't get an answer in this thread, I ended up implementing my feature with statusBar.addWidget() (source) and statusBar.removeWidget() (source).

As expected, I'm now getting increasingly threatening warning emails about usage of internal APIs. What would you recommend instead?

Thank you :)

0

Hi François,

Please try implementing com.intellij.openapi.wm.StatusBarWidgetFactory#isAvailable.

0

Thank you for the pointer Karol Lewandowski.

How can the IDE be notified that `isAvailable` has changed and the status bar should now be created / destroyed?

0

I suggest creating a helper service which will hold a flag that will be updated when your server is started and stopped. The isAvailable  method should return the flag from this service.

0

Thank you. What I'd like to know is how does the helper service notify IntelliJ that the flag value has changed?

0

Hi François,

As far as I understand the API, it would work like this:

  • When the server is started, you set the flag to true in the service
  • When the server is stopped, you set the flag to false in the service
  • StatusBarWidgetFactory#isAvailable() returns the flag set on server start/stop
  • When the server is started or stopped, after setting the flag, you call StatusBarWidgetsManager.updateWidget(StatusBarWidgetFactory) for your factory (you can get it by class: StatusBarWidgetFactory.EP_NAME.findExtension(YourFactory.class))
0

Thank you Karol Lewandowski, I can confirm the `updateWidget` part was what I was missing. Would be great to add it to the docs too :)

0

Please sign in to leave a comment.