mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract EventLogToolWindowFactory, event driven logShown instead of polling (IDEA-88837)
This commit is contained in:
@@ -17,39 +17,24 @@
|
||||
package com.intellij.notification;
|
||||
|
||||
import com.intellij.execution.filters.HyperlinkInfo;
|
||||
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.NotificationsManagerImpl;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.AbstractProjectComponent;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.actions.ScrollToTheEndToolbarAction;
|
||||
import com.intellij.openapi.editor.actions.ToggleUseSoftWrapsToolbarAction;
|
||||
import com.intellij.openapi.editor.impl.DocumentImpl;
|
||||
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.ui.SimpleToolWindowPanel;
|
||||
import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.*;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentFactory;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.hash.LinkedHashMap;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -335,7 +320,6 @@ public class EventLog {
|
||||
if (eventLog != null) {
|
||||
if (!eventLog.isVisible()) {
|
||||
eventLog.activate(null, true);
|
||||
getLogModel(project).logShown();
|
||||
} else {
|
||||
eventLog.hide(null);
|
||||
}
|
||||
@@ -375,6 +359,10 @@ public class EventLog {
|
||||
|
||||
}
|
||||
|
||||
EventLogConsole getConsole() {
|
||||
return myConsole;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectOpened() {
|
||||
myConsole = new EventLogConsole(myProjectModel);
|
||||
@@ -416,79 +404,9 @@ public class EventLog {
|
||||
|
||||
}
|
||||
|
||||
private static ProjectTracker getProjectComponent(Project project) {
|
||||
static ProjectTracker getProjectComponent(Project project) {
|
||||
return project.getComponent(ProjectTracker.class);
|
||||
}
|
||||
public static class FactoryItself implements ToolWindowFactory, DumbAware {
|
||||
@Override
|
||||
public void createToolWindowContent(final Project project, ToolWindow toolWindow) {
|
||||
final Editor editor = getProjectComponent(project).myConsole.getConsoleEditor();
|
||||
|
||||
SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true) {
|
||||
@Override
|
||||
public Object getData(@NonNls String dataId) {
|
||||
return PlatformDataKeys.HELP_ID.is(dataId) ? HELP_ID : super.getData(dataId);
|
||||
}
|
||||
};
|
||||
panel.setContent(editor.getComponent());
|
||||
|
||||
DefaultActionGroup group = new DefaultActionGroup();
|
||||
group.add(new DumbAwareAction("Settings", "Edit notification settings", AllIcons.Actions.ShowSettings) {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
ShowSettingsUtil.getInstance().editConfigurable(project, new NotificationsConfigurable());
|
||||
}
|
||||
});
|
||||
group.add(new DisplayBalloons());
|
||||
group.add(new ToggleUseSoftWrapsToolbarAction(SoftWrapAppliancePlaces.CONSOLE) {
|
||||
@Override
|
||||
protected Editor getEditor(AnActionEvent e) {
|
||||
return editor;
|
||||
}
|
||||
});
|
||||
group.add(new ScrollToTheEndToolbarAction(editor));
|
||||
group.add(new DumbAwareAction("Mark all as read", "Mark all unread notifications as read", AllIcons.General.Reset) {
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
if (project.isDisposed()) return;
|
||||
e.getPresentation().setEnabled(!getProjectComponent(project).myProjectModel.getNotifications().isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
LogModel model = getProjectComponent(project).myProjectModel;
|
||||
for (Notification notification : model.getNotifications()) {
|
||||
model.removeNotification(notification);
|
||||
notification.expire();
|
||||
}
|
||||
}
|
||||
});
|
||||
group.add(new ContextHelpAction(HELP_ID));
|
||||
|
||||
ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, false);
|
||||
toolbar.setTargetComponent(panel);
|
||||
panel.setToolbar(toolbar.getComponent());
|
||||
|
||||
final Content content = ContentFactory.SERVICE.getInstance().createContent(panel, "", false);
|
||||
toolWindow.getContentManager().addContent(content);
|
||||
}
|
||||
|
||||
private static class DisplayBalloons extends ToggleAction implements DumbAware {
|
||||
public DisplayBalloons() {
|
||||
super("Show balloons", "Enable or suppress notification balloons", AllIcons.General.Balloon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class NotificationHyperlinkInfo implements HyperlinkInfo {
|
||||
private final Notification myNotification;
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.notification;
|
||||
|
||||
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.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actions.ScrollToTheEndToolbarAction;
|
||||
import com.intellij.openapi.editor.actions.ToggleUseSoftWrapsToolbarAction;
|
||||
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.SimpleToolWindowPanel;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowFactory;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentFactory;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.event.AncestorEvent;
|
||||
import javax.swing.event.AncestorListener;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class EventLogToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||
@Override
|
||||
public void createToolWindowContent(final Project project, ToolWindow toolWindow) {
|
||||
final Editor editor = EventLog.getProjectComponent(project).getConsole().getConsoleEditor();
|
||||
|
||||
SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true) {
|
||||
@Override
|
||||
public Object getData(@NonNls String dataId) {
|
||||
return PlatformDataKeys.HELP_ID.is(dataId) ? EventLog.HELP_ID : super.getData(dataId);
|
||||
}
|
||||
};
|
||||
panel.setContent(editor.getComponent());
|
||||
panel.addAncestorListener(new LogShownTracker(project));
|
||||
|
||||
ActionToolbar toolbar = createToolbar(project, editor);
|
||||
toolbar.setTargetComponent(panel);
|
||||
panel.setToolbar(toolbar.getComponent());
|
||||
|
||||
final Content content = ContentFactory.SERVICE.getInstance().createContent(panel, "", false);
|
||||
toolWindow.getContentManager().addContent(content);
|
||||
}
|
||||
|
||||
private static ActionToolbar createToolbar(Project project, Editor editor) {
|
||||
DefaultActionGroup group = new DefaultActionGroup();
|
||||
group.add(new EditNotificationSettings(project));
|
||||
group.add(new DisplayBalloons());
|
||||
group.add(new ToggleSoftWraps(editor));
|
||||
group.add(new ScrollToTheEndToolbarAction(editor));
|
||||
group.add(new MarkAllAsRead(project));
|
||||
group.add(new ContextHelpAction(EventLog.HELP_ID));
|
||||
|
||||
return ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, false);
|
||||
}
|
||||
|
||||
private static class DisplayBalloons extends ToggleAction implements DumbAware {
|
||||
public DisplayBalloons() {
|
||||
super("Show balloons", "Enable or suppress notification balloons", AllIcons.General.Balloon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
NotificationsConfigurationImpl.getNotificationsConfigurationImpl().SHOW_BALLOONS = state;
|
||||
}
|
||||
}
|
||||
|
||||
private static class EditNotificationSettings extends DumbAwareAction {
|
||||
private final Project myProject;
|
||||
|
||||
public EditNotificationSettings(Project project) {
|
||||
super("Settings", "Edit notification settings", AllIcons.Actions.ShowSettings);
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
ShowSettingsUtil.getInstance().editConfigurable(myProject, new NotificationsConfigurable());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ToggleSoftWraps extends ToggleUseSoftWrapsToolbarAction {
|
||||
private final Editor myEditor;
|
||||
|
||||
public ToggleSoftWraps(Editor editor) {
|
||||
super(SoftWrapAppliancePlaces.CONSOLE);
|
||||
myEditor = editor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Editor getEditor(AnActionEvent e) {
|
||||
return myEditor;
|
||||
}
|
||||
}
|
||||
|
||||
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.General.Reset);
|
||||
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 implements AncestorListener {
|
||||
private final Project myProject;
|
||||
|
||||
public LogShownTracker(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ancestorAdded(AncestorEvent event) {
|
||||
ToolWindow log = EventLog.getEventLog(myProject);
|
||||
if (log != null && log.isVisible()) {
|
||||
EventLog.getLogModel(myProject).logShown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ancestorRemoved(AncestorEvent event) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ancestorMoved(AncestorEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class LogModel implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
public void logShown() {
|
||||
void logShown() {
|
||||
for (Notification notification : getNotifications()) {
|
||||
if (!notification.isImportant()) {
|
||||
removeNotification(notification);
|
||||
|
||||
@@ -102,9 +102,6 @@ public class IdeNotificationArea extends JLabel implements CustomStatusBarWidget
|
||||
final Project project = getProject();
|
||||
LogModel logModel = EventLog.getLogModel(project);
|
||||
ToolWindow eventLog = EventLog.getEventLog(project);
|
||||
if (eventLog != null && eventLog.isVisible()) {
|
||||
logModel.logShown();
|
||||
}
|
||||
boolean stripesVisible = !UISettings.getInstance().HIDE_TOOL_STRIPES;
|
||||
ArrayList<Notification> notifications = logModel.getNotifications();
|
||||
LayeredIcon icon = new LayeredIcon(2);
|
||||
|
||||
@@ -242,8 +242,7 @@
|
||||
<virtualFileSystem key="http" implementationClass="com.intellij.openapi.vfs.impl.http.HttpFileSystemImpl"/>
|
||||
<virtualFileSystem key="https" implementationClass="com.intellij.openapi.vfs.impl.http.HttpsFileSystem"/>
|
||||
|
||||
<toolWindow id="Event Log" anchor="bottom" secondary="true"
|
||||
factoryClass="com.intellij.notification.EventLog$FactoryItself"/>
|
||||
<toolWindow id="Event Log" anchor="bottom" secondary="true" factoryClass="com.intellij.notification.EventLogToolWindowFactory"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.openapi.wm.impl.ProjectFrameBounds"
|
||||
serviceImplementation="com.intellij.openapi.wm.impl.ProjectFrameBounds"/>
|
||||
|
||||
Reference in New Issue
Block a user