IDEA-119669 Event Log / Mark all as read: allow to assign a keyboard shortcut

This commit is contained in:
Alexander Zolotov
2015-03-12 11:19:03 +01:00
parent cb4e613ce4
commit 2ae3446abc
2 changed files with 4 additions and 36 deletions
@@ -19,7 +19,6 @@ import com.intellij.icons.AllIcons;
import com.intellij.ide.actions.ContextHelpAction;
import com.intellij.notification.impl.NotificationsConfigurable;
import com.intellij.notification.impl.NotificationsConfigurationImpl;
import com.intellij.notification.impl.actions.MarkAllNotificationsAsReadAction;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actions.ScrollToTheEndToolbarAction;
@@ -38,7 +37,6 @@ import com.intellij.ui.content.ContentFactory;
import com.intellij.ui.content.ContentManager;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.event.AncestorEvent;
@@ -85,21 +83,13 @@ public class EventLogToolWindowFactory implements ToolWindowFactory, DumbAware {
group.add(new DisplayBalloons());
group.add(new ToggleSoftWraps(editor));
group.add(new ScrollToTheEndToolbarAction(editor));
group.add(createMarkNotificationsAsReadAction(project, editor));
group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_MARK_ALL_NOTIFICATIONS_AS_READ));
group.add(new EventLogConsole.ClearLogAction(console));
group.add(new ContextHelpAction(EventLog.HELP_ID));
return ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, false);
}
@NotNull
private static MarkAllNotificationsAsReadAction createMarkNotificationsAsReadAction(@Nullable Project project, @NotNull Editor editor) {
MarkAllNotificationsAsReadAction result = new MarkAllNotificationsAsReadAction(project);
ShortcutSet shortcutSet = ActionManager.getInstance().getAction(IdeActions.ACTION_MARK_ALL_NOTIFICATIONS_AS_READ).getShortcutSet();
result.registerCustomShortcutSet(shortcutSet, editor.getContentComponent());
return result;
}
private static class DisplayBalloons extends ToggleAction implements DumbAware {
public DisplayBalloons() {
super("Show balloons", "Enable or suppress notification balloons", AllIcons.General.Balloon);
@@ -7,45 +7,23 @@ import com.intellij.notification.Notification;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.Nullable;
public class MarkAllNotificationsAsReadAction extends DumbAwareAction {
@Nullable
private final Project myProject;
@SuppressWarnings("unused")
// needed for picoContainer
public MarkAllNotificationsAsReadAction() {
this(null);
}
public MarkAllNotificationsAsReadAction(@Nullable Project project) {
super("Mark all notifications as read", "Mark all unread notifications as read", AllIcons.Actions.Selectall);
myProject = project;
}
@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabled(!EventLog.getLogModel(getProject(e)).getNotifications().isEmpty());
e.getPresentation().setEnabled(!EventLog.getLogModel(e.getData(CommonDataKeys.PROJECT)).getNotifications().isEmpty());
}
@Override
public void actionPerformed(AnActionEvent e) {
LogModel model = EventLog.getLogModel(getProject(e));
LogModel model = EventLog.getLogModel(e.getData(CommonDataKeys.PROJECT));
for (Notification notification : model.getNotifications()) {
model.removeNotification(notification);
notification.expire();
}
}
@Nullable
private Project getProject(AnActionEvent e) {
Project project = ObjectUtils.chooseNotNull(myProject, e.getData(CommonDataKeys.PROJECT));
if (project != null && (project.isDisposed() || project.isDefault())) {
return null;
}
return project;
}
}