do not use EditorEventListener.TOPIC for now

This commit is contained in:
Vladimir Krivosheev
2018-08-14 10:16:22 +02:00
parent c461353f41
commit d72a1402ac
2 changed files with 31 additions and 27 deletions
@@ -1,28 +1,42 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.command.impl;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.undo.DocumentReference;
import com.intellij.openapi.command.undo.DocumentReferenceManager;
import com.intellij.openapi.command.undo.UndoConstants;
import com.intellij.openapi.command.undo.UndoManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.event.EditorEventListener;
import com.intellij.openapi.editor.event.DocumentListener;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.AbstractFileViewProvider;
import com.intellij.util.messages.MessageBusConnection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DocumentUndoProvider {
public class DocumentUndoProvider implements Disposable {
private static final Key<Boolean> UNDOING_EDITOR_CHANGE = Key.create("DocumentUndoProvider.UNDOING_EDITOR_CHANGE");
DocumentUndoProvider(@Nullable Project project, @NotNull MessageBusConnection busConnection) {
busConnection.subscribe(EditorEventListener.TOPIC, new MyEditorDocumentListener(project));
private final Project myProject;
DocumentUndoProvider(Project project) {
MyEditorDocumentListener documentListener = new MyEditorDocumentListener();
myProject = project;
EditorFactory.getInstance().getEventMulticaster().addDocumentListener(documentListener, this);
}
@Override
public void dispose() {
}
private UndoManagerImpl getUndoManager() {
return (UndoManagerImpl)(myProject == null ? UndoManager.getGlobalInstance() : UndoManager.getInstance(myProject));
}
public static void startDocumentUndo(@Nullable Document doc) {
@@ -33,18 +47,7 @@ public class DocumentUndoProvider {
if (doc != null) doc.putUserData(UNDOING_EDITOR_CHANGE, null);
}
private static class MyEditorDocumentListener implements EditorEventListener {
@Nullable
private final Project myProject;
public MyEditorDocumentListener(@Nullable Project project) {
myProject = project;
}
private UndoManagerImpl getUndoManager() {
return (UndoManagerImpl)(myProject == null ? UndoManager.getGlobalInstance() : UndoManager.getInstance(myProject));
}
private class MyEditorDocumentListener implements DocumentListener {
@Override
public void beforeDocumentChange(@NotNull DocumentEvent e) {
Document document = e.getDocument();
@@ -80,7 +83,7 @@ public class DocumentUndoProvider {
&& shouldRecordActions(document);
}
private static boolean shouldRecordActions(final Document document) {
private boolean shouldRecordActions(final Document document) {
if (document.getUserData(UndoConstants.DONT_RECORD_UNDO) == Boolean.TRUE) return false;
VirtualFile vFile = FileDocumentManager.getInstance().getFile(document);
@@ -33,7 +33,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ex.WindowManagerEx;
import com.intellij.psi.ExternalChangeAction;
import com.intellij.util.ObjectUtils;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.util.messages.MessageBus;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -86,15 +86,15 @@ public class UndoManagerImpl extends UndoManager implements Disposable {
return Registry.intValue("undo.documentUndoLimit");
}
public UndoManagerImpl() {
this(null);
public UndoManagerImpl(CommandProcessor commandProcessor) {
this(null, commandProcessor);
}
public UndoManagerImpl(@Nullable ProjectEx project) {
public UndoManagerImpl(@Nullable ProjectEx project, @NotNull CommandProcessor commandProcessor) {
myProject = project;
if (myProject == null || !myProject.isDefault()) {
runStartupActivity(myProject);
runStartupActivity(myProject, commandProcessor);
}
myMerger = new CommandMerger(this);
@@ -109,7 +109,7 @@ public class UndoManagerImpl extends UndoManager implements Disposable {
public void dispose() {
}
private void runStartupActivity(@Nullable Project project) {
private void runStartupActivity(@Nullable Project project, @NotNull CommandProcessor commandProcessor) {
myUndoProviders = project == null
? Extensions.getExtensions(UndoProvider.EP_NAME)
: Extensions.getExtensions(UndoProvider.PROJECT_EP_NAME, myProject);
@@ -121,8 +121,9 @@ public class UndoManagerImpl extends UndoManager implements Disposable {
myEditorProvider = new FocusBasedCurrentEditorProvider();
MessageBusConnection busConnection = (project == null ? ApplicationManager.getApplication().getMessageBus() : project.getMessageBus()).connect(this);
busConnection.subscribe(CommandListener.TOPIC, new CommandListener() {
MessageBus messageBus = project == null ? ApplicationManager.getApplication().getMessageBus() : project.getMessageBus();
messageBus.connect(this).subscribe(CommandListener.TOPIC, new CommandListener() {
private boolean myStarted;
@Override
@@ -156,7 +157,7 @@ public class UndoManagerImpl extends UndoManager implements Disposable {
}
});
new DocumentUndoProvider(myProject, busConnection);
Disposer.register(this, new DocumentUndoProvider(myProject));
}
public boolean isActive() {