use message bus instead of custom dispatcher

This commit is contained in:
Vladimir Krivosheev
2016-09-14 17:51:50 +02:00
parent c20dca02cf
commit 53ee582735
16 changed files with 94 additions and 79 deletions
@@ -142,16 +142,16 @@ public class DebuggerManagerImpl extends DebuggerManagerEx implements Persistent
myDispatcher.removeListener(listener);
}
public DebuggerManagerImpl(Project project, StartupManager startupManager, EditorColorsManager colorsManager) {
public DebuggerManagerImpl(Project project, StartupManager startupManager) {
myProject = project;
myBreakpointManager = new BreakpointManager(myProject, startupManager, this);
if (!project.isDefault()) {
colorsManager.addEditorColorsListener(new EditorColorsListener() {
project.getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
getBreakpointManager().updateBreakpointsUI();
}
}, project);
});
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -16,13 +16,17 @@
package com.intellij.openapi.editor.colors;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.util.messages.Topic;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public abstract class EditorColorsManager {
public static final Topic<EditorColorsListener> TOPIC = Topic.create("EditorColorsListener", EditorColorsListener.class);
@NonNls public static final String DEFAULT_SCHEME_NAME = "Default";
public static EditorColorsManager getInstance() {
@@ -50,15 +54,24 @@ public abstract class EditorColorsManager {
public abstract boolean isDefaultScheme(EditorColorsScheme scheme);
/**
* @deprecated use {@link #addEditorColorsListener(EditorColorsListener, Disposable)} instead
* @deprecated use {@link #TOPIC} instead
*/
public abstract void addEditorColorsListener(@NotNull EditorColorsListener listener);
@SuppressWarnings("MethodMayBeStatic")
@Deprecated
public final void addEditorColorsListener(@NotNull EditorColorsListener listener) {
ApplicationManager.getApplication().getMessageBus().connect().subscribe(TOPIC, listener);
}
/**
* @deprecated use {@link #addEditorColorsListener(EditorColorsListener, Disposable)} instead
* @deprecated use {@link #TOPIC} instead
*/
public abstract void removeEditorColorsListener(@NotNull EditorColorsListener listener);
public abstract void addEditorColorsListener(@NotNull EditorColorsListener listener, @NotNull Disposable disposable);
@SuppressWarnings("MethodMayBeStatic")
@Deprecated
public final void addEditorColorsListener(@NotNull EditorColorsListener listener, @NotNull Disposable disposable) {
ApplicationManager.getApplication().getMessageBus().connect(disposable).subscribe(TOPIC, listener);
}
public abstract boolean isUseOnlyMonospacedFonts();
public abstract void setUseOnlyMonospacedFonts(boolean b);
}
@@ -57,14 +57,14 @@ public class TodoConfiguration implements PersistentStateComponent<Element>, Dis
@NonNls private static final String ELEMENT_FILTER = "filter";
private final MessageBus myMessageBus;
public TodoConfiguration(@NotNull MessageBus messageBus, EditorColorsManager manager) {
public TodoConfiguration(@NotNull MessageBus messageBus) {
myMessageBus = messageBus;
manager.addEditorColorsListener(new EditorColorsListener() {
messageBus.connect(this).subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
colorSettingsChanged();
}
}, this);
});
resetToDefaultTodoPatterns();
}
@@ -36,16 +36,15 @@ public interface Filter {
Filter[] EMPTY_ARRAY = new Filter[0];
class Result extends ResultItem {
private static final Map<TextAttributesKey, TextAttributes> GRAYED_BY_NORMAL_CACHE = ContainerUtil.newConcurrentMap(2);
static {
EditorColorsManager.getInstance().addEditorColorsListener(new EditorColorsListener() {
ApplicationManager.getApplication().getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
// invalidate cache on Appearance Theme/Editor Scheme change
GRAYED_BY_NORMAL_CACHE.clear();
}
}, ApplicationManager.getApplication());
});
}
protected NextAction myNextAction = NextAction.EXIT;
@@ -279,12 +279,15 @@ public class DaemonListeners implements Disposable {
});
connection.subscribe(PowerSaveMode.TOPIC, () -> stopDaemon(true, "Power save mode change"));
editorColorsManager.addEditorColorsListener(scheme -> stopDaemonAndRestartAllFiles("Global color scheme changed"), this);
connection.subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
stopDaemonAndRestartAllFiles("Editor color scheme changed");
}
});
commandProcessor.addCommandListener(new MyCommandListener(), this);
application.addApplicationListener(new MyApplicationListener(), this);
editorColorsManager.addEditorColorsListener(new MyEditorColorsListener(), this);
inspectionProfileManager.addProfileChangeListener(new MyProfileChangeListener(), this);
inspectionProjectProfileManager.addProfileChangeListener(new MyProfileChangeListener(), this);
todoConfiguration.addPropertyChangeListener(new MyTodoListener(), this);
@@ -476,14 +479,6 @@ public class DaemonListeners implements Disposable {
}
}
private class MyEditorColorsListener implements EditorColorsListener {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
TodoConfiguration.getInstance().colorSettingsChanged();
stopDaemonAndRestartAllFiles("Editor color scheme changed");
}
}
private class MyTodoListener implements PropertyChangeListener {
@Override
public void propertyChange(@NotNull PropertyChangeEvent evt) {
@@ -82,12 +82,13 @@ public class BookmarkManager extends AbstractProjectComponent implements Persist
EditorColorsManager colorsManager,
EditorFactory editorFactory) {
super(project);
colorsManager.addEditorColorsListener(new EditorColorsListener() {
project.getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
colorsChanged();
}
}, project);
});
myBus = bus;
EditorEventMulticaster multicaster = editorFactory.getEventMulticaster();
multicaster.addDocumentListener(new MyDocumentListener(), myProject);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -15,6 +15,10 @@
*/
package com.intellij.openapi.editor.colors;
/**
* @deprecated Use EditorColorsListener directly
*/
@Deprecated
public abstract class EditorColorsAdapter implements EditorColorsListener {
public void globalSchemeChange(EditorColorsScheme scheme) {
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -25,6 +25,7 @@ import com.intellij.notification.impl.NotificationsConfigurationImpl;
import com.intellij.notification.impl.NotificationsManagerImpl;
import com.intellij.notification.impl.ui.NotificationsUtil;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.colors.EditorColorsListener;
import com.intellij.openapi.editor.colors.EditorColorsManager;
@@ -161,13 +162,14 @@ class EventLogConsole {
public void setConsoleFontSize(int fontSize) {
}
};
EditorColorsManager.getInstance().addEditorColorsListener(new EditorColorsListener() {
ApplicationManager.getApplication().getMessageBus().connect(myProjectModel).subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
globalScheme.setDelegate(EditorColorsManager.getInstance().getGlobalScheme());
editor.reinitSettings();
}
}, myProjectModel);
});
editor.setColorsScheme(ConsoleViewUtil.updateConsoleColorScheme(editor.createBoundColorSchemeDelegate(globalScheme)));
}
@@ -18,13 +18,11 @@ package com.intellij.openapi.editor.colors.impl;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.ide.WelcomeWizardUtil;
import com.intellij.ide.ui.LafManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.colors.EditorColorsListener;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
@@ -39,7 +37,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ComponentTreeEventDispatcher;
import com.intellij.util.EventDispatcher;
import com.intellij.util.JdomKt;
import com.intellij.util.io.URLUtil;
import com.intellij.util.ui.UIUtil;
@@ -66,7 +63,6 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Pers
@NonNls private static final String SCHEME_NODE_NAME = "scheme";
private static final String DEFAULT_NAME = "Default";
private final EventDispatcher<EditorColorsListener> myDispatcher = EventDispatcher.create(EditorColorsListener.class);
private final ComponentTreeEventDispatcher<EditorColorsListener> myTreeDispatcher = ComponentTreeEventDispatcher.create(EditorColorsListener.class);
private final DefaultColorSchemesManager myDefaultColorSchemeManager;
@@ -178,14 +174,13 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Pers
}
public void schemeChangedOrSwitched(@Nullable EditorColorsScheme newScheme) {
EditorFactory.getInstance().refreshAllEditors();
// refreshAllEditors is not enough - for example, change "Errors and warnings -> Typo" from green (default) to red
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
DaemonCodeAnalyzer.getInstance(project).restart();
}
// we need to push events to components that use editor font, e.g. HTML editor panes
myDispatcher.getMulticaster().globalSchemeChange(newScheme);
ApplicationManager.getApplication().getMessageBus().syncPublisher(TOPIC).globalSchemeChange(newScheme);
myTreeDispatcher.getMulticaster().globalSchemeChange(newScheme);
}
@@ -306,21 +301,6 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Pers
return mySchemeManager.findSchemeByName(schemeName);
}
@Override
public void addEditorColorsListener(@NotNull EditorColorsListener listener) {
myDispatcher.addListener(listener);
}
@Override
public void addEditorColorsListener(@NotNull EditorColorsListener listener, @NotNull Disposable disposable) {
myDispatcher.addListener(listener, disposable);
}
@Override
public void removeEditorColorsListener(@NotNull EditorColorsListener listener) {
myDispatcher.removeListener(listener);
}
@Override
public void setUseOnlyMonospacedFonts(boolean value) {
myState.USE_ONLY_MONOSPACED_FONTS = value;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -25,6 +25,9 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.colors.EditorColorsListener;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.event.EditorEventMulticaster;
import com.intellij.openapi.editor.event.EditorFactoryEvent;
import com.intellij.openapi.editor.event.EditorFactoryListener;
@@ -66,6 +69,13 @@ public class EditorFactoryImpl extends EditorFactory implements ApplicationCompo
});
}
});
ApplicationManager.getApplication().getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
refreshAllEditors();
}
});
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -96,16 +96,15 @@ public class FileStatusManagerImpl extends FileStatusManager implements ProjectC
}
}
public FileStatusManagerImpl(Project project, StartupManager startupManager, EditorColorsManager colorsManager,
@SuppressWarnings("UnusedParameters") DirectoryIndex makeSureIndexIsInitializedFirst) {
public FileStatusManagerImpl(Project project, StartupManager startupManager, @SuppressWarnings("UnusedParameters") DirectoryIndex makeSureIndexIsInitializedFirst) {
myProject = project;
colorsManager.addEditorColorsListener(new EditorColorsListener() {
project.getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
fileStatusesChanged();
}
}, myProject);
});
startupManager.registerPreStartupActivity(() -> {
DocumentAdapter documentListener = new DocumentAdapter() {
@@ -1208,7 +1208,9 @@ public class FileUtil extends FileUtilRt {
char c = name.charAt(i);
boolean appendReplacement = true;
if (c > 0 && c < 255) {
if (strict ? Character.isLetterOrDigit(c) || c == '_' : Character.isJavaIdentifierPart(c) || c == ' ' || c == '@' || c == '-') {
if (strict
? (Character.isLetterOrDigit(c) || (c == '_'))
: (Character.isJavaIdentifierPart(c) || (c == ' ') || (c == '@') || (c == '-'))) {
continue;
}
}
@@ -23,7 +23,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.colors.EditorColorsAdapter;
import com.intellij.openapi.editor.colors.EditorColorsListener;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.event.*;
@@ -74,7 +74,7 @@ public class XLineBreakpointManager {
private final XDependentBreakpointManager myDependentBreakpointManager;
private final StartupManagerEx myStartupManager;
public XLineBreakpointManager(Project project, final XDependentBreakpointManager dependentBreakpointManager, final StartupManager startupManager) {
public XLineBreakpointManager(@NotNull Project project, final XDependentBreakpointManager dependentBreakpointManager, final StartupManager startupManager) {
myProject = project;
myDependentBreakpointManager = dependentBreakpointManager;
myStartupManager = (StartupManagerEx)startupManager;
@@ -114,10 +114,7 @@ public class XLineBreakpointManager {
myBreakpointsUpdateQueue = new MergingUpdateQueue("XLine breakpoints", 300, true, null, project);
// Update breakpoints colors if global color schema was changed
final EditorColorsManager colorsManager = EditorColorsManager.getInstance();
if (colorsManager != null) { // in some debugger tests EditorColorsManager component isn't loaded
colorsManager.addEditorColorsListener(new MyEditorColorsListener(), project);
}
project.getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new MyEditorColorsListener());
}
public void updateBreakpointsUI() {
@@ -336,7 +333,7 @@ public class XLineBreakpointManager {
}
}
private class MyEditorColorsListener extends EditorColorsAdapter {
private class MyEditorColorsListener implements EditorColorsListener {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
updateBreakpointsUI();
@@ -60,14 +60,11 @@ public class ExecutionPointHighlighter {
private final AtomicBoolean updateRequested = new AtomicBoolean();
public ExecutionPointHighlighter(final Project project) {
public ExecutionPointHighlighter(@NotNull Project project) {
myProject = project;
// Update highlighter colors if global color schema was changed
final EditorColorsManager colorsManager = EditorColorsManager.getInstance();
if (colorsManager != null) { // in some debugger tests EditorColorsManager component isn't loaded
colorsManager.addEditorColorsListener(scheme -> update(false), project);
}
project.getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, scheme -> update(false));
}
public void show(final @NotNull XSourcePosition position, final boolean notTopFrame,
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2016 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.coverage;
import com.intellij.CommonBundle;
@@ -18,7 +33,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.colors.EditorColorsAdapter;
import com.intellij.openapi.editor.colors.EditorColorsListener;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.event.EditorFactoryEvent;
@@ -92,14 +107,14 @@ public class CoverageDataManagerImpl extends CoverageDataManager {
private final Object ANNOTATORS_LOCK = new Object();
private final Map<Editor, SrcFileAnnotator> myAnnotators = new HashMap<>();
public CoverageDataManagerImpl(final Project project) {
public CoverageDataManagerImpl(@NotNull Project project) {
myProject = project;
EditorColorsManager.getInstance().addEditorColorsListener(new EditorColorsAdapter() {
project.getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
chooseSuitesBundle(myCurrentSuitesBundle);
}
}, project);
});
addSuiteListener(new CoverageViewSuiteListener(this, myProject), myProject);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -22,6 +22,7 @@ import com.intellij.ide.ui.UISettingsListener;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.KeyboardShortcut;
import com.intellij.openapi.actionSystem.Shortcut;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.colors.*;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.editor.markup.TextAttributes;
@@ -67,13 +68,13 @@ public class JBTerminalSystemSettingsProvider extends DefaultTabbedSettingsProvi
}
}, this);
EditorColorsManager.getInstance().addEditorColorsListener(new EditorColorsAdapter() {
ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
myColorScheme.updateGlobalScheme(scheme);
fireFontChanged();
}
}, this);
});
}
private static int consoleFontSize(MyColorSchemeDelegate colorScheme) {