AnAction only on change Tab window

Answered

how to filter actions only on tablature changes. I mean changing the active window with a code. From the active window I would like to get the name of the tab (the name of the open class file.)

in summary I want to know when a tab window has been switched to another window

when I run the plugin on a real intelliJ the action is tweaked every now and then.

 

public class MyAction extends AnAction implements DumbAware
{
public MyAction() {
// AnAction anAction = ActionUtil.copyFrom(this, IdeActions.ACTION_EDITOR_TAB);
AnAction anAction = ActionUtil.copyFrom(this, IdeActions.ACTION_OPEN_IN_NEW_WINDOW);
}

@Override
public void update(final AnActionEvent e) {
e.getPresentation().setEnabled(e.getProject() != null && e.getData(CommonDataKeys.VIRTUAL_FILE) != null);
e.getPresentation().setEnabled(false);
}
@Override
public void actionPerformed(final AnActionEvent e) {
final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(e.getProject());
VirtualFile file = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE);
EditorWindow window = mgr.getCurrentWindow();

// if (window == null || window.isFilePinned(file)) return;
//
// if (window.findFileComposite(file) != null) {
// mgr.closeFile(file, window);
// }
}
}

public class MyPromoter implements ActionPromoter {
@Override
public List<AnAction> promote(@NotNull List<? extends AnAction> actions, @NotNull DataContext context) {

ContainerUtil.findInstance(actions, MyAction.class);
if (context.getData("psi.Element")==null) {
return action != null ? Collections.singletonList(action) : Collections.emptyList();
}
String fileName = context.getData("psi.Element").toString();


String contend = context.getData(PlatformDataKeys.CONTEXT_COMPONENT).toString();
// com.intellij.ide.projectView.impl.ProjectViewPane data = context.getData("contextComponent");
System.out.println(contend);


return action != null ? Collections.singletonList(action) : Collections.emptyList();
}
3 comments
Comment actions Permalink

Please explain the use case. What do you want to achieve and why? What is "active window" - active editor tab?

0
Comment actions Permalink

wants to detect a change the active editor tab. When we change to a different tab (click on other tab or clicking on references in the code and opening a new editor tab), I want to get the name of the active tab to perform some action. For example, display the name of the tab in a popup

 

0
Comment actions Permalink

Use com.intellij.openapi.fileEditor.FileEditorManagerListener message topic, com.intellij.openapi.fileEditor.FileEditorManagerListener#selectionChanged gives you information about new/old file and editor.

0

Please sign in to leave a comment.