Placing IntelliJ plugin in status bar

Viewed 434

I'm just starting playing around with the plugin SDK for IntelliJ IDEA. However I already have some trouble with the first step.

I'd like to place an action in the lower status bar, next to the Git actions.

How can I place that action there?

Screenshot showing desired position

1 Answers

This type of UI is called EditorBasedWidget. If you like to explore how it works in git4idea plugin, I can suggest you to start with GitBranchWidget and DvcsStatusWidget classes.

Here is the code for the simplest example:

MyWidget.java

public class MyWidget extends EditorBasedWidget {
    public MyWidget(@NotNull Project project) {
        super(project);
    }

    @NotNull
    @Override
    public String ID() {
        return "MyWidget";
    }

    @Nullable
    @Override
    public WidgetPresentation getPresentation(@NotNull PlatformType type) {
        return new MyPresentation();
    }
}

MyPresentation.java

public class MyPresentation implements StatusBarWidget.MultipleTextValuesPresentation {
    @Nullable("null means the widget is unable to show the popup")
    @Override
    public ListPopup getPopupStep() {
        return null;
    }

    @Nullable
    @Override
    public String getSelectedValue() {
        return "Selected value";
    }

    @NotNull
    @Override
    public String getMaxValue() {
        return "Max value";
    }

    @Nullable
    @Override
    public String getTooltipText() {
        return "Tooltip text";
    }

    @Nullable
    @Override
    public Consumer<MouseEvent> getClickConsumer() {
        return null;
    }
}

Somewhere, for example in ProjectComponent

ApplicationManager.getApplication().invokeLater(() -> {
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
    if (statusBar != null) {
       statusBar.addWidget(new MyWidget(myProject));
    }
});

And here is the result:

enter image description here

Related