How do I close an unselected TAB?

Answered

I'm trying to implement a closable TAB bar, but I'm having some problems with it. Go straight to the code

TabInfo tabInfo = new TabInfo(fn.apply(newTabIndex));
tabInfo.setText(path);
AnAction action = ActionManager.getInstance().getAction("MartinaRightSideTabToolbar");
DefaultActionGroup actionGroup = (DefaultActionGroup) action;
tabInfo.setTabLabelActions(actionGroup, TabInfo.ICON);

 the action set in tabInfo:

public class CloseTabAction extends DumbAwareAction {
private Project project;

public CloseTabAction() {
getTemplatePresentation().setText("Close Tab");
getTemplatePresentation().setIcon(AllIcons.Actions.Close);
getTemplatePresentation().setHoveredIcon(AllIcons.Actions.CloseHovered);
}


@Override
public void actionPerformed(@NotNull AnActionEvent e) {
this.project = e.getProject(); //If TAB is not selected, this value is empty
JBEditorTabs rightRequestTab = ViewHolder.getInstance(project).getRightRequestTab();
rightRequestTab.removeTab(rightRequestTab.getSelectedInfo());
}
}

I wonder if there is an easier way to close the TAB?

1
2 comments

Can anyone help me? Thanks in advance

0

answered on Slack

0

Post is closed for comments.