Skip to content

Commit f01e82a

Browse files
committed
migrate to last notification api
1 parent b10bf20 commit f01e82a

1 file changed

Lines changed: 28 additions & 37 deletions

File tree

‎python-impl/src/main/java/com/jetbrains/python/impl/packaging/PyPackageManagerUI.java‎

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
import consulo.application.progress.Task;
2727
import consulo.content.bundle.Sdk;
2828
import consulo.execution.RunCanceledByUserException;
29+
import consulo.ide.impl.idea.webcore.packaging.PackagesNotificationPanel;
30+
import consulo.localize.LocalizeValue;
2931
import consulo.logging.Logger;
3032
import consulo.platform.base.icon.PlatformIconGroup;
3133
import consulo.process.ExecutionException;
3234
import consulo.project.Project;
3335
import consulo.project.ui.notification.Notification;
3436
import consulo.project.ui.notification.NotificationGroup;
35-
import consulo.project.ui.notification.NotificationType;
36-
import consulo.project.ui.notification.NotificationsManager;
37+
import consulo.project.ui.notification.NotificationService;
3738
import consulo.project.ui.notification.event.NotificationListener;
3839
import consulo.repository.ui.PackageManagementService;
3940
import consulo.ui.annotation.RequiredUIAccess;
@@ -174,8 +175,8 @@ public void run(ProgressIndicator indicator) {
174175

175176
protected void taskStarted(ProgressIndicator indicator) {
176177
Project project = (Project) getProject();
177-
PackagingNotification[] notifications =
178-
NotificationsManager.getNotificationsManager().getNotificationsOfType(PackagingNotification.class, project);
178+
List<PackagingNotification> notifications =
179+
NotificationService.getInstance().getNotificationsOfType(PackagingNotification.class, project);
179180
for (PackagingNotification notification : notifications) {
180181
notification.expire();
181182
}
@@ -188,13 +189,11 @@ protected void taskStarted(ProgressIndicator indicator) {
188189
protected void taskFinished(List<ExecutionException> exceptions) {
189190
SimpleReference<Notification> notificationRef = new SimpleReference<>(null);
190191
if (exceptions.isEmpty()) {
191-
notificationRef.set(new PackagingNotification(
192-
PACKAGING_GROUP_ID,
193-
getSuccessTitle(),
194-
getSuccessDescription(),
195-
NotificationType.INFORMATION,
196-
null
197-
));
192+
Notification.Builder builder = NotificationService.getInstance().newInfo(PACKAGING_GROUP_ID)
193+
.title(LocalizeValue.localizeTODO(getSuccessTitle()))
194+
.content(LocalizeValue.localizeTODO(getSuccessDescription()));
195+
196+
notificationRef.set(new PackagingNotification(builder));
198197
}
199198
else {
200199
PackageManagementService.ErrorDescription description = PyPackageManagementService.toErrorDescription(exceptions, mySdk);
@@ -203,39 +202,31 @@ protected void taskFinished(List<ExecutionException> exceptions) {
203202
NotificationListener listener = (notification, event) -> {
204203
assert myProject != null;
205204
String title = StringUtil.capitalizeWords(getFailureTitle(), true);
206-
consulo.ide.impl.idea.webcore.packaging.PackagesNotificationPanel.showError(title, description);
205+
PackagesNotificationPanel.showError(title, description);
207206
};
208-
notificationRef.set(new PackagingNotification(
209-
PACKAGING_GROUP_ID,
210-
getFailureTitle(),
211-
firstLine + " <a href=\"xxx\">Details...</a>",
212-
consulo.project.ui.notification.NotificationType.ERROR,
213-
listener
214-
));
207+
208+
Notification.Builder builder = NotificationService.getInstance().newError(PACKAGING_GROUP_ID)
209+
.title(LocalizeValue.localizeTODO(getFailureTitle()))
210+
.content(LocalizeValue.localizeTODO(firstLine + " <a href=\"xxx\">Details...</a>"))
211+
.hyperlinkListener(listener);
212+
213+
notificationRef.set(new PackagingNotification(builder));
215214
}
216215
}
216+
217217
Project project = (Project) myProject;
218-
project.getApplication().invokeLater(() -> {
219-
if (myListener != null) {
220-
myListener.finished(exceptions);
221-
}
222-
Notification notification = notificationRef.get();
223-
if (notification != null) {
224-
notification.notify(project);
225-
}
226-
});
218+
if (myListener != null) {
219+
myListener.finished(exceptions);
220+
}
221+
Notification notification = notificationRef.get();
222+
if (notification != null) {
223+
notification.notify(project);
224+
}
227225
}
228226

229227
private static class PackagingNotification extends Notification {
230-
231-
public PackagingNotification(
232-
NotificationGroup groupDisplayId,
233-
String title,
234-
String content,
235-
consulo.project.ui.notification.NotificationType type,
236-
@Nullable NotificationListener listener
237-
) {
238-
super(groupDisplayId, title, content, type, listener);
228+
private PackagingNotification(Builder notificationBuilder) {
229+
super(notificationBuilder);
239230
}
240231
}
241232
}

0 commit comments

Comments
 (0)