mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-119669 Event Log / Mark all as read: allow to assign a keyboard shortcut
This commit is contained in:
@@ -302,4 +302,6 @@ public interface IdeActions {
|
||||
|
||||
String ACTION_RECENT_FILES = "RecentFiles";
|
||||
String ACTION_SEARCH_EVERYWHERE = "SearchEverywhere";
|
||||
|
||||
String ACTION_MARK_ALL_NOTIFICATIONS_AS_READ = "MarkNotificationsAsRead";
|
||||
}
|
||||
|
||||
+11
-25
@@ -19,6 +19,7 @@ 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;
|
||||
@@ -37,6 +38,7 @@ 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;
|
||||
|
||||
@@ -83,13 +85,21 @@ public class EventLogToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||
group.add(new DisplayBalloons());
|
||||
group.add(new ToggleSoftWraps(editor));
|
||||
group.add(new ScrollToTheEndToolbarAction(editor));
|
||||
group.add(new MarkAllAsRead(project));
|
||||
group.add(createMarkNotificationsAsReadAction(project, editor));
|
||||
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);
|
||||
@@ -134,30 +144,6 @@ public class EventLogToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||
}
|
||||
}
|
||||
|
||||
private static class MarkAllAsRead extends DumbAwareAction {
|
||||
private final Project myProject;
|
||||
|
||||
public MarkAllAsRead(Project project) {
|
||||
super("Mark all as read", "Mark all unread notifications as read", AllIcons.Actions.Selectall);
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
if (myProject.isDisposed()) return;
|
||||
e.getPresentation().setEnabled(!EventLog.getLogModel(myProject).getNotifications().isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
LogModel model = EventLog.getLogModel(myProject);
|
||||
for (Notification notification : model.getNotifications()) {
|
||||
model.removeNotification(notification);
|
||||
notification.expire();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class LogShownTracker extends AncestorListenerAdapter {
|
||||
private final Project myProject;
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ public class LogModel implements Disposable {
|
||||
return myStamps.get(notification);
|
||||
}
|
||||
|
||||
void removeNotification(Notification notification) {
|
||||
public void removeNotification(Notification notification) {
|
||||
synchronized (myNotifications) {
|
||||
myNotifications.remove(notification);
|
||||
}
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.intellij.notification.impl.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.notification.EventLog;
|
||||
import com.intellij.notification.LogModel;
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
LogModel model = EventLog.getLogModel(getProject(e));
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -704,5 +704,7 @@
|
||||
<action id="ExportTestResults" class="com.intellij.execution.testframework.export.ExportTestResultsAction" icon="AllIcons.Actions.Export"/>
|
||||
|
||||
<action id="SaveDocument" class="com.intellij.ide.actions.SaveDocumentAction"/>
|
||||
|
||||
<action id="MarkNotificationsAsRead" class="com.intellij.notification.impl.actions.MarkAllNotificationsAsReadAction"/>
|
||||
</actions>
|
||||
</component>
|
||||
|
||||
Reference in New Issue
Block a user