mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Create lambda-friendly factory methods for NotificationAction
Not only a full version, but also a short one: without event (rarely needed) and without notification (which is often available in the context).
This commit is contained in:
@@ -91,15 +91,12 @@ public abstract class DvcsBranchPopup<Repo extends Repository> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<AnActionEvent, Notification> 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());
|
||||
}
|
||||
}
|
||||
@@ -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<CommittedChangeList> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = "<b>Deleted Branch:</b> " + myBranchName;
|
||||
if (unmergedCommits) message += "<br/>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);
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user