cherry pick and resolve conflicts: IDEA-CR-55519: do not open listen for selection if focus is in editor

GitOrigin-RevId: 4397877f3b48075e78bccbb44c15db3a1110d4a3
This commit is contained in:
kirill.skrygan
2019-11-20 15:23:13 +00:00
committed by intellij-monorepo-bot
parent 30105ba495
commit 1a588d17b1
3 changed files with 30 additions and 11 deletions
@@ -33,6 +33,7 @@ import com.intellij.openapi.vcs.changes.actions.ShowDiffPreviewAction;
import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager;
import com.intellij.openapi.vcs.changes.ui.*;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.problems.ProblemListener;
import com.intellij.ui.GuiUtils;
import com.intellij.ui.JBColor;
@@ -356,7 +357,7 @@ public class ChangesViewManager implements ChangesViewEx,
JComponent mainPanel;
if (Registry.is("show.diff.preview.as.editor.tab")) {
myDiffPreview = new EditorTabPreview(changeProcessor, myProject,
myDiffPreview = new EditorTabPreview(changeProcessor,
contentPanel, myView){
@Override
@@ -365,7 +366,10 @@ public class ChangesViewManager implements ChangesViewEx,
}
@Override
protected boolean shouldSkip() {
protected boolean skipPreviewUpdate() {
if (super.skipPreviewUpdate())
return true;
return myModelUpdateInProgress;
}
@@ -11,6 +11,9 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.openapi.vcs.changes.actions.diff.lst.LocalChangeListDiffTool;
import com.intellij.openapi.vcs.changes.ui.ChangesTree;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.Update;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -23,23 +26,23 @@ public abstract class EditorTabPreview implements ChangesViewPreview {
private final VcsConfiguration myVcsConfiguration;
private final DiffRequestProcessor myChangeProcessor;
public EditorTabPreview(@NotNull DiffRequestProcessor changeProcessor, @NotNull Project project,
public EditorTabPreview(@NotNull DiffRequestProcessor changeProcessor,
@NotNull JComponent contentPanel, @NotNull ChangesTree changesTree) {
myProject = project;
myProject = changesTree.getProject();
myChangeProcessor = changeProcessor;
MyDiffPreviewProvider previewProvider = new MyDiffPreviewProvider(changeProcessor, this::getCurrentName);
myPreviewDiffVirtualFile = new PreviewDiffVirtualFile(previewProvider);
myVcsConfiguration = VcsConfiguration.getInstance(project);
myVcsConfiguration = VcsConfiguration.getInstance(myProject);
//do not open file aggressively on start up, do it later
DumbService.getInstance(project).smartInvokeLater(() -> {
if (project.isDisposed()) return;
DumbService.getInstance(myProject).smartInvokeLater(() -> {
if (myProject.isDisposed()) return;
changesTree.addSelectionListener(() -> {
if (!myVcsConfiguration.LOCAL_CHANGES_DETAILS_PREVIEW_SHOWN) return;
if (shouldSkip()) return;
if (skipPreviewUpdate()) return;
setDiffPreviewVisible(true);
});
@@ -52,7 +55,7 @@ public abstract class EditorTabPreview implements ChangesViewPreview {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
FileEditorManager.getInstance(project).openFile(myPreviewDiffVirtualFile, true, true);
FileEditorManager.getInstance(myProject).openFile(myPreviewDiffVirtualFile, true, true);
}
}.registerCustomShortcutSet(contentPanel, null);
}
@@ -62,7 +65,11 @@ public abstract class EditorTabPreview implements ChangesViewPreview {
protected abstract void doRefresh();
protected boolean shouldSkip() {
protected boolean skipPreviewUpdate() {
return ToolWindowManager.getInstance(myProject).isEditorComponentActive();
}
protected boolean isContentEmpty() {
return false;
}
@@ -676,7 +676,15 @@ public class ShelvedChangesViewManager implements Disposable {
myRootPanel.add(toolbar.getComponent(), BorderLayout.WEST);
if (Registry.is("show.diff.preview.as.editor.tab")) {
myDiffPreview = new EditorTabPreview(changeProcessor, project, pane, myTree){
myDiffPreview = new EditorTabPreview(changeProcessor, pane, myTree){
@Override
protected boolean skipPreviewUpdate() {
if (super.skipPreviewUpdate())
return true;
return !myVcsConfiguration.SHELVE_DETAILS_PREVIEW_SHOWN;
}
@Override
protected String getCurrentName() {