diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/branch/DvcsBranchPopup.java b/platform/dvcs-impl/src/com/intellij/dvcs/branch/DvcsBranchPopup.java index afb8c9a78009..ba9e829b99ad 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/branch/DvcsBranchPopup.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/branch/DvcsBranchPopup.java @@ -91,15 +91,12 @@ public abstract class DvcsBranchPopup { private void notifyAboutSyncedBranches() { Notification notification = STANDARD_NOTIFICATION.createNotification("Branch operations are executed on all roots.", "", NotificationType.INFORMATION, null); - notification.addAction(new NotificationAction("Disable...") { - @Override - public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) { - ShowSettingsUtil.getInstance().showSettingsDialog(myProject, myVcs.getConfigurable().getDisplayName()); - if (myVcsSettings.getSyncSetting() == DvcsSyncSettings.Value.DONT_SYNC) { - notification.expire(); - } + notification.addAction(NotificationAction.createSimple("Disable...", () -> { + ShowSettingsUtil.getInstance().showSettingsDialog(myProject, myVcs.getConfigurable().getDisplayName()); + if (myVcsSettings.getSyncSetting() == DvcsSyncSettings.Value.DONT_SYNC) { + notification.expire(); } - }); + })); VcsNotifier.getInstance(myProject).notify(notification); } diff --git a/platform/platform-api/src/com/intellij/notification/NotificationAction.java b/platform/platform-api/src/com/intellij/notification/NotificationAction.java index 156e3dd72101..04ce9cdab9f0 100644 --- a/platform/platform-api/src/com/intellij/notification/NotificationAction.java +++ b/platform/platform-api/src/com/intellij/notification/NotificationAction.java @@ -20,6 +20,8 @@ import com.intellij.openapi.project.DumbAwareAction; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.BiConsumer; + /** * @author Alexander Lobas */ @@ -34,4 +36,19 @@ public abstract class NotificationAction extends DumbAwareAction { } public abstract void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification); + + @NotNull + public static NotificationAction create(@NotNull String text, @NotNull BiConsumer performAction) { + return new NotificationAction(text) { + @Override + public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) { + performAction.accept(e, notification); + } + }; + } + + @NotNull + public static NotificationAction createSimple(@NotNull String text, @NotNull Runnable performAction) { + return create(text, (event, notification) -> performAction.run()); + } } \ No newline at end of file diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index 41a0b12a7e11..c0ac69901d62 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -20,7 +20,6 @@ import com.intellij.notification.BrowseNotificationAction; import com.intellij.notification.Notification; import com.intellij.notification.NotificationAction; import com.intellij.notification.NotificationType; -import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; @@ -399,12 +398,8 @@ public class GitVcs extends AbstractVcs { String message = String.format("At least %s is required.",GitVersion.MIN.getPresentation()); Notification notification = STANDARD_NOTIFICATION.createNotification(title, message, NotificationType.ERROR, null); notification.addAction(new BrowseNotificationAction("Download...", "http://git-scm.com/download")); - notification.addAction(new NotificationAction("Configure...") { - @Override - public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) { - ShowSettingsUtil.getInstance().showSettingsDialog(myProject, getConfigurable().getDisplayName()); - } - }); + notification.addAction(NotificationAction.createSimple("Configure...", () -> + ShowSettingsUtil.getInstance().showSettingsDialog(myProject, getConfigurable().getDisplayName()))); VcsNotifier.getInstance(myProject).notify(notification); } } diff --git a/plugins/git4idea/src/git4idea/branch/GitDeleteBranchOperation.java b/plugins/git4idea/src/git4idea/branch/GitDeleteBranchOperation.java index 6c09908978e7..883a457704a0 100644 --- a/plugins/git4idea/src/git4idea/branch/GitDeleteBranchOperation.java +++ b/plugins/git4idea/src/git4idea/branch/GitDeleteBranchOperation.java @@ -19,7 +19,6 @@ import com.google.common.collect.Maps; import com.intellij.notification.Notification; import com.intellij.notification.NotificationAction; import com.intellij.notification.NotificationType; -import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; @@ -144,29 +143,14 @@ class GitDeleteBranchOperation extends GitBranchOperation { String message = "Deleted Branch: " + myBranchName; if (unmergedCommits) message += "
Unmerged commits were discarded"; Notification notification = STANDARD_NOTIFICATION.createNotification("", message, NotificationType.INFORMATION, null); - notification.addAction(new NotificationAction(RESTORE) { - @Override - public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) { - restoreInBackground(notification); - } - }); + notification.addAction(NotificationAction.createSimple(RESTORE, () -> restoreInBackground(notification))); if (unmergedCommits) { - notification.addAction(new NotificationAction(VIEW_COMMITS) { - @Override - public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) { - viewUnmergedCommitsInBackground(notification); - } - }); + notification.addAction(NotificationAction.createSimple(VIEW_COMMITS, () -> viewUnmergedCommitsInBackground(notification))); } if (!myTrackedBranches.isEmpty() && hasNoOtherTrackingBranch(myTrackedBranches, myBranchName) && trackedBranchIsNotProtected()) { - notification.addAction(new NotificationAction(DELETE_TRACKED_BRANCH) { - @Override - public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) { - deleteTrackedBranchInBackground(); - } - }); + notification.addAction(NotificationAction.createSimple(DELETE_TRACKED_BRANCH, () -> deleteTrackedBranchInBackground())); } myNotifier.notify(notification); } diff --git a/plugins/git4idea/src/git4idea/rebase/GitRewordOperation.kt b/plugins/git4idea/src/git4idea/rebase/GitRewordOperation.kt index 37a852b6c0e0..3b01f7f33598 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRewordOperation.kt +++ b/plugins/git4idea/src/git4idea/rebase/GitRewordOperation.kt @@ -15,10 +15,8 @@ */ package git4idea.rebase -import com.intellij.notification.Notification import com.intellij.notification.NotificationAction import com.intellij.notification.NotificationType -import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.diagnostic.Attachment import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.progress.EmptyProgressIndicator @@ -192,11 +190,9 @@ class GitRewordOperation(private val repository: GitRepository, private fun notifySuccess() { val notification = STANDARD_NOTIFICATION.createNotification("Reworded Successfully", "", NotificationType.INFORMATION, null) - notification.addAction(object : NotificationAction("Undo") { - override fun actionPerformed(e: AnActionEvent, notification: Notification) { - notification.expire() - undoInBackground() - } + notification.addAction(NotificationAction.createSimple("Undo") { + notification.expire() + undoInBackground() }) val connection = project.messageBus.connect()