Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #248 from codiga/notification-active-editor-fix
Browse files Browse the repository at this point in the history
Add null check and error balloon for Codiga Assistant notification
  • Loading branch information
dastrong-codiga authored Feb 14, 2023
2 parents 6ad3703 + 70a0dde commit eb994f0
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/main/java/io/codiga/plugins/jetbrains/starter/AppStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.serviceContainer.AlreadyDisposedException;
Expand Down Expand Up @@ -110,23 +111,35 @@ private void showShortcutKeysNotification(@NotNull Project project, AppSettingsS
.addAction(new AnAction("Snippets") {
@Override
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
ActionManager.getInstance().getAction("com.code_inspector.plugins.intellij.actions.AssistantUseRecipeAction")
.actionPerformed(new AnActionEvent(null,
DataManager.getInstance().getDataContext(FileEditorManager.getInstance(project).getSelectedEditor().getComponent()),
ActionPlaces.UNKNOWN,
new Presentation(),
ActionManager.getInstance(), 0));
//The selected editor is null when the user has no open editor by default, or closed all of them before invoking this action.
var selectedEditor = FileEditorManager.getInstance(project).getSelectedEditor();
if (selectedEditor != null) {
ActionManager.getInstance().getAction("com.code_inspector.plugins.intellij.actions.AssistantUseRecipeAction")
.actionPerformed(new AnActionEvent(null,
DataManager.getInstance().getDataContext(selectedEditor.getComponent()),
ActionPlaces.UNKNOWN,
new Presentation(),
ActionManager.getInstance(), 0));
} else {
DumbService.getInstance(project).showDumbModeNotification("There is no active editor to invoke the selected action in.");
}
}
})
.addAction(new AnAction("Shortcuts") {
@Override
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
ActionManager.getInstance().getAction("com.code_inspector.plugins.intellij.actions.AssistantListShortcuts")
.actionPerformed(new AnActionEvent(null,
DataManager.getInstance().getDataContext(FileEditorManager.getInstance(project).getSelectedEditor().getComponent()),
ActionPlaces.UNKNOWN,
new Presentation(),
ActionManager.getInstance(), 0));
//The selected editor is null when the user has no open editor by default, or closed all of them before invoking this action.
var selectedEditor = FileEditorManager.getInstance(project).getSelectedEditor();
if (selectedEditor != null) {
ActionManager.getInstance().getAction("com.code_inspector.plugins.intellij.actions.AssistantListShortcuts")
.actionPerformed(new AnActionEvent(null,
DataManager.getInstance().getDataContext(selectedEditor.getComponent()),
ActionPlaces.UNKNOWN,
new Presentation(),
ActionManager.getInstance(), 0));
} else {
DumbService.getInstance(project).showDumbModeNotification("There is no active editor to invoke the selected action in.");
}
}
})
.addAction(new AnAction("Doc") {
Expand Down

0 comments on commit eb994f0

Please sign in to comment.