Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deprecated notifications API usage #93

Merged
merged 1 commit into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 31 additions & 37 deletions src/main/java/com/leinardi/pycharm/mypy/util/Notifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationGroupManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
Expand All @@ -37,8 +38,6 @@
import java.io.PrintWriter;
import java.io.StringWriter;

import static com.intellij.notification.NotificationGroup.balloonGroup;
import static com.intellij.notification.NotificationGroup.logOnlyGroup;
import static com.intellij.notification.NotificationListener.URL_OPENING_LISTENER;
import static com.intellij.notification.NotificationType.ERROR;
import static com.intellij.notification.NotificationType.INFORMATION;
Expand All @@ -48,63 +47,58 @@

public final class Notifications {
private static final Logger LOG = com.intellij.openapi.diagnostic.Logger.getInstance(Notifications.class);
private static final NotificationGroup BALLOON_GROUP = balloonGroup(message("plugin.notification.alerts"));
private static final NotificationGroup LOG_ONLY_GROUP = logOnlyGroup(message("plugin.notification.logging"));
private static final NotificationGroup BALLOON_GROUP =
NotificationGroupManager.getInstance().getNotificationGroup("alerts");
private static final NotificationGroup LOG_ONLY_GROUP =
NotificationGroupManager.getInstance().getNotificationGroup("logging");
private static final String TITLE = message("plugin.name");

private Notifications() {
}

public static void showInfo(final Project project, final String infoText) {
BALLOON_GROUP
.createNotification(TITLE, infoText, INFORMATION, URL_OPENING_LISTENER)
.notify(project);
}

public static void showInfo(final Project project, final String title, final String infoText) {
BALLOON_GROUP
.createNotification(title, infoText, INFORMATION, URL_OPENING_LISTENER)
.createNotification(TITLE, infoText, INFORMATION)
.setListener(URL_OPENING_LISTENER)
.notify(project);
}

public static void showWarning(final Project project, final String warningText) {
BALLOON_GROUP
.createNotification(TITLE, warningText, WARNING, URL_OPENING_LISTENER)
.createNotification(TITLE, warningText, WARNING)
.setListener(URL_OPENING_LISTENER)
.notify(project);
}

public static void showWarning(final Project project, final String title, final String warningText) {
BALLOON_GROUP
.createNotification(title, warningText, WARNING, URL_OPENING_LISTENER)
.createNotification(title, warningText, WARNING)
.setListener(URL_OPENING_LISTENER)
.notify(project);
}

public static void showError(final Project project, final String errorText) {
BALLOON_GROUP
.createNotification(TITLE, errorText, ERROR, URL_OPENING_LISTENER)
.notify(project);
}

public static void showError(final Project project, final String title, final String errorText) {
BALLOON_GROUP
.createNotification(title, errorText, ERROR, URL_OPENING_LISTENER)
.createNotification(TITLE, errorText, ERROR)
.setListener(URL_OPENING_LISTENER)
.notify(project);
}

public static void showException(final Project project, final Throwable t) {
LOG_ONLY_GROUP
.createNotification(message("plugin.exception"), messageFor(t), ERROR, URL_OPENING_LISTENER)
.createNotification(message("plugin.exception"), messageFor(t), ERROR)
.setListener(URL_OPENING_LISTENER)
.notify(project);
}

public static void showInstallMypy(final Project project) {
Notification notification = BALLOON_GROUP
.createNotification(
TITLE,
MypyBundle.message("plugin.notification.install-mypy.subtitle"),
MypyBundle.message("plugin.notification.install-mypy.content"),
ERROR,
URL_OPENING_LISTENER);
ERROR)
.setSubtitle(MypyBundle.message("plugin.notification.install-mypy.subtitle"))
.setListener(URL_OPENING_LISTENER);
notification
.addAction(new InstallMypyAction(project, notification))
.notify(project);
Expand All @@ -114,10 +108,10 @@ public static void showUnableToRunMypy(final Project project) {
Notification notification = BALLOON_GROUP
.createNotification(
TITLE,
MypyBundle.message("plugin.notification.unable-to-run-mypy.subtitle"),
MypyBundle.message("plugin.notification.unable-to-run-mypy.content"),
ERROR,
URL_OPENING_LISTENER);
ERROR)
.setSubtitle(MypyBundle.message("plugin.notification.unable-to-run-mypy.subtitle"))
.setListener(URL_OPENING_LISTENER);
notification
.addAction(new OpenPluginSettingsAction(notification))
.notify(project);
Expand All @@ -128,8 +122,8 @@ public static void showNoPythonInterpreter(Project project) {
.createNotification(
TITLE,
MypyBundle.message("plugin.notification.no-python-interpreter.content"),
ERROR,
URL_OPENING_LISTENER);
ERROR)
.setListener(URL_OPENING_LISTENER);
notification
.addAction(new ConfigurePythonInterpreterAction(project, notification))
.notify(project);
Expand All @@ -153,23 +147,23 @@ private static String traceOf(final Throwable t) {
}

private static class OpenPluginSettingsAction extends AnAction {
private Notification notification;
private final Notification notification;

OpenPluginSettingsAction(Notification notification) {
super(MypyBundle.message("plugin.notification.action.plugin-settings"));
this.notification = notification;
}

@Override
public void actionPerformed(AnActionEvent event) {
public void actionPerformed(@NotNull AnActionEvent event) {
new Settings().actionPerformed(event);
notification.expire();
}
}

private static class ConfigurePythonInterpreterAction extends AnAction {
private Project project;
private Notification notification;
private final Project project;
private final Notification notification;

ConfigurePythonInterpreterAction(Project project, Notification notification) {
super(MypyBundle.message("plugin.notification.action.configure-python-interpreter"));
Expand All @@ -178,15 +172,15 @@ private static class ConfigurePythonInterpreterAction extends AnAction {
}

@Override
public void actionPerformed(AnActionEvent ignored) {
public void actionPerformed(@NotNull AnActionEvent ignored) {
ShowSettingsUtil.getInstance().showSettingsDialog(project, "Project Interpreter");
notification.expire();
}
}

private static class InstallMypyAction extends AnAction {
private Project project;
private Notification notification;
private final Project project;
private final Notification notification;

InstallMypyAction(Project project, Notification notification) {
super(MypyBundle.message("plugin.notification.action.install-mypy"));
Expand All @@ -195,7 +189,7 @@ private static class InstallMypyAction extends AnAction {
}

@Override
public void actionPerformed(AnActionEvent ignored) {
public void actionPerformed(@NotNull AnActionEvent ignored) {
Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
if (projectSdk == null) {
LOG.debug("Project interpreter not set");
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<!--suppress PluginXmlValidity -->
<depends>com.intellij.modules.python</depends>

<resource-bundle>com.leinardi.pycharm.mypy.MypyBundle</resource-bundle>

<project-components>
<component>
Expand All @@ -50,7 +51,6 @@

<localInspection implementationClass="com.leinardi.pycharm.mypy.MypyBatchInspection"
language="Python"
bundle="com.leinardi.pycharm.mypy.MypyBundle"
key="inspection.display-name"
groupKey="inspection.group"
shortName="Mypy"
Expand All @@ -60,6 +60,9 @@

<checkinHandlerFactory id="CheckStyleIDEACheckInHandlerFactory"
implementation="com.leinardi.pycharm.mypy.handlers.ScanFilesBeforeCheckinHandlerFactory"/>

<notificationGroup id="alerts" displayType="BALLOON" key="plugin.notification.alerts"/>
<notificationGroup id="logging" displayType="NONE" key="plugin.notification.logging"/>
</extensions>

<actions>
Expand Down