Should we use StatusBarWidgetSettings?
已回答
I saw that StatusBarWidgetSettings.setEnabled() is the recommended way to show/hide a status bar widget according to the docs: https://plugins.jetbrains.com/docs/intellij/status-bar-widgets.html#controlling-widgets-programmatically
However, StatusBarWidgetSettings is currently annotated with @Internal.
What is the officially supported approach? Thank you!
请先登录再写评论。
Hi François,
I’m sorry for the delay. This class looks internal from the beginning (it is located in
implpackage of a*-impl.jarmodule, 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?
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?
Hi Karol Lewandowski, as I didn't get an answer in this thread, I ended up implementing my feature with
statusBar.addWidget()(source) andstatusBar.removeWidget()(source).As expected, I'm now getting increasingly threatening warning emails about usage of internal APIs. What would you recommend instead?
Thank you :)
Hi François,
Please try implementing com.intellij.openapi.wm.StatusBarWidgetFactory#isAvailable.
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?
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.
Thank you. What I'd like to know is how does the helper service notify IntelliJ that the flag value has changed?
Hi François,
As far as I understand the API, it would work like this:
StatusBarWidgetFactory#isAvailable()returns the flag set on server start/stopStatusBarWidgetsManager.updateWidget(StatusBarWidgetFactory)for your factory (you can get it by class:StatusBarWidgetFactory.EP_NAME.findExtension(YourFactory.class))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 :)