答案 0 :(得分:2)
这种类型的UI称为EditorBasedWidget
。如果您想探索它在git4idea
插件中的工作方式,建议您从GitBranchWidget
和DvcsStatusWidget
类开始。
以下是最简单示例的代码:
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;
}
}
某个地方,例如ProjectComponent
ApplicationManager.getApplication().invokeLater(() -> {
StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
if (statusBar != null) {
statusBar.addWidget(new MyWidget(myProject));
}
});
结果如下: