From 1a588d17b1cba4189374b008f1f4d7c6ef992e7e Mon Sep 17 00:00:00 2001 From: "kirill.skrygan" Date: Wed, 20 Nov 2019 17:12:02 +0200 Subject: [PATCH] cherry pick and resolve conflicts: IDEA-CR-55519: do not open listen for selection if focus is in editor GitOrigin-RevId: 4397877f3b48075e78bccbb44c15db3a1110d4a3 --- .../vcs/changes/ChangesViewManager.java | 8 +++++-- .../openapi/vcs/changes/EditorTabPreview.java | 23 ++++++++++++------- .../shelf/ShelvedChangesViewManager.java | 10 +++++++- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java index a24d5cb65006..c3b30745d292 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java @@ -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; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/EditorTabPreview.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/EditorTabPreview.java index d19209c658b5..374f72c221c9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/EditorTabPreview.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/EditorTabPreview.java @@ -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; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java index 6cd553d21bbd..882d3ae82831 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java @@ -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() {