Sync intention menu contributor

Answered

Hi!

https://github.com/JetBrains/intellij-community/commit/ce7801efc9ffa237e3b63593ec37bdb7d71b7f4a#diff-eab36da2303724d6d2162347da339119L16

Why it was decided not to introduce a new extension point for EditorNotificationActions? 

I use the extension of IntentionMenuContributor and in my logic use com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl#getTopComponents method, and as a result, I get the exception 'Access is allowed from event dispatch thread only.' because the code is not called from the ApplicationManager.getApplication().invokeLater .

What should I do? Given that my code is being called from a ReadAction

 

public class CubaEditorNotificationActions implements IntentionMenuContributor {
@Override
public void collectActions(@NotNull Editor hostEditor, @NotNull PsiFile hostFile,
@NotNull ShowIntentionsPass.IntentionsInfo intentions, int passIdToShowIntentionsFor, int offset) {
if (hostEditor.getSelectionModel().hasSelection() || isCursorOutOfClass(hostFile, offset)) {
return;
}
Project project = hostEditor.getProject();
if (project == null) return;
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
if (!(fileEditorManager instanceof FileEditorManagerImpl)) return;
TextEditor fileEditor = TextEditorProvider.getInstance().getTextEditor(hostEditor);
List<JComponent> components = ((FileEditorManagerImpl) fileEditorManager).getTopComponents(fileEditor);
for (JComponent component : components) {
if (component instanceof CubaEditorNotificationPanel) {
for (IntentionAction intentionAction : ((CubaEditorNotificationPanel) component).getIntentionActions()) {
intentions.notificationActionsToShow.add(
new HighlightInfo.IntentionActionDescriptor(intentionAction, null));
}
}
}
}
}
0
4 comments

Is CubaEditorNotificationPanel a com.intellij.ui.EditorNotificationPanel ? Then using com.intellij.ui.EditorNotificationPanel#createActionLabel(java.lang.String, java.lang.String) would expose intentions automatically?

0

Yes CubaEditorNotificationPanel extends EditorNotificationPanel. But, I use custom components for EditorNotificationPanel. HyperlinkLabel doesn't suit me, for example, I use ActionButtonWithText. 


Collection com.intellij.ui.EditorNotificationPanel.MyIntentionAction#myOptions is formed relative to HyperlinkLabel class. com.intellij.ui.EditorNotificationPanel#getIntentionAction method returns one action. I would like to add a list of actions.

In version 2019.1 this code worked correctly.

 

 

0

Please note that IntentionMenuContributor is marked as Internal API and shouldn't be used by 3rd party plugins in the first place. You could provide corresponding IntentionAction that replicate your custom component's quickfixes.

0

Thanks, I will not use IntentionMenuContributor. 

0

Please sign in to leave a comment.