diff: use VcsEditorTabFilesManager component to open diff in editor
authorDmitry Zhuravlev <dmitry.zhuravlev@jetbrains.com>
Tue, 25 May 2021 10:24:40 +0000 (13:24 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Fri, 11 Jun 2021 21:35:42 +0000 (21:35 +0000)
GitOrigin-RevId: 1fb9027ae0499792c0d4f2bbe9743587a12861c6

platform/diff-impl/src/com/intellij/diff/DiffManagerImpl.java
platform/diff-impl/src/com/intellij/diff/editor/DiffEditorTabFilesManager.kt [new file with mode: 0644]
platform/platform-resources/src/META-INF/PlatformExtensions.xml
platform/vcs-impl/resources/META-INF/VCS.xml
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/EditorTabDiffPreviewManager.kt
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ShowEditorDiffPreviewActionProvider.kt

index 4f0ab4ea9611007e0c81f41acacc1fb3371dc1a5..0cb02238bfe766d61bb3626d444c7ae84bfa208c 100644 (file)
@@ -1,23 +1,10 @@
-/*
- * Copyright 2000-2015 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.
- */
+// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 package com.intellij.diff;
 
 import com.intellij.diff.chains.DiffRequestChain;
 import com.intellij.diff.chains.SimpleDiffRequestChain;
 import com.intellij.diff.editor.ChainDiffVirtualFile;
+import com.intellij.diff.editor.DiffEditorTabFilesManager;
 import com.intellij.diff.impl.DiffRequestPanelImpl;
 import com.intellij.diff.impl.DiffWindow;
 import com.intellij.diff.merge.*;
@@ -32,7 +19,6 @@ import com.intellij.diff.tools.simple.SimpleDiffTool;
 import com.intellij.diff.util.DiffUtil;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.diff.DiffBundle;
-import com.intellij.openapi.fileEditor.FileEditorManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.WindowWrapper;
 import com.intellij.openapi.util.Disposer;
@@ -86,7 +72,7 @@ public class DiffManagerImpl extends DiffManagerEx {
         DiffUtil.getWindowMode(hints) == WindowWrapper.Mode.FRAME &&
         hints.getWindowConsumer() == null) {
       ChainDiffVirtualFile diffFile = new ChainDiffVirtualFile(requests, DiffBundle.message("label.default.diff.editor.tab.name"));
-      FileEditorManager.getInstance(project).openFile(diffFile, true);
+      DiffEditorTabFilesManager.getInstance(project).showDiffFile(diffFile, true);
       return;
     }
     new DiffWindow(project, requests, hints).show();
diff --git a/platform/diff-impl/src/com/intellij/diff/editor/DiffEditorTabFilesManager.kt b/platform/diff-impl/src/com/intellij/diff/editor/DiffEditorTabFilesManager.kt
new file mode 100644 (file)
index 0000000..8c97d99
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.diff.editor
+
+import com.intellij.openapi.components.service
+import com.intellij.openapi.fileEditor.FileEditor
+import com.intellij.openapi.fileEditor.FileEditorManager
+import com.intellij.openapi.project.Project
+import org.jetbrains.annotations.ApiStatus
+
+@ApiStatus.Internal
+interface DiffEditorTabFilesManager {
+  fun showDiffFile(diffFile: ChainDiffVirtualFile, focusEditor: Boolean): Array<out FileEditor>
+
+  companion object {
+    @JvmStatic
+    fun getInstance(project: Project): DiffEditorTabFilesManager = project.service()
+  }
+}
+
+class DefaultDiffTabFilesManager(private val project: Project) : DiffEditorTabFilesManager {
+
+  override fun showDiffFile(diffFile: ChainDiffVirtualFile, focusEditor: Boolean): Array<out FileEditor> {
+    return FileEditorManager.getInstance(project).openFile(diffFile, true)
+  }
+}
index f0c533999fb30b5fdb6102f94826774e3446c231..27a5c482625e01fcd4a486b5e8b96e962a80c73d 100644 (file)
                     serviceImplementation="com.intellij.openapi.diff.impl.dir.DirDiffManagerImpl"/>
     <diff.DiffExtension implementation="com.intellij.diff.actions.ShowBlankDiffWindowDiffExtension"/>
 
+    <projectService serviceInterface="com.intellij.diff.editor.DiffEditorTabFilesManager"
+                    serviceImplementation="com.intellij.diff.editor.DefaultDiffTabFilesManager"/>
 
     <daemon.highlightInfoFilter implementation="com.intellij.codeInsight.daemon.OutsidersPsiFileSupport$HighlightFilter"/>
     <daemon.intentionActionFilter implementation="com.intellij.codeInsight.daemon.OutsidersPsiFileSupport$IntentionFilter"/>
index dae332597430d847dbfcbc2d58bfa203ca1f7c10..ebe728fcc92c4b62e01dd1003ca16e0990c9d541 100644 (file)
@@ -44,6 +44,9 @@
         key="ignore.codeInspection.duplicateEntry"
         level="WARNING"/>
 
+    <projectService serviceInterface="com.intellij.diff.editor.DiffEditorTabFilesManager"
+                    serviceImplementation="com.intellij.openapi.vcs.changes.EditorTabDiffPreviewManager"
+                    overrides="true"/>
     <projectService serviceImplementation="com.intellij.vcs.commit.CommitModeManager"/>
     <vcsStartupActivity implementation="com.intellij.vcs.commit.CommitModeManager$MyStartupActivity"/>
   </extensions>
index a9befa5d59224229598920b5baed0540b8de0ba1..7ac76f1cc2a6279d920d16465f36346d9fa0e536 100644 (file)
@@ -1,10 +1,12 @@
 // Copyright 2000-2021 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.vcs.changes
 
+import com.intellij.diff.editor.ChainDiffVirtualFile
+import com.intellij.diff.editor.DiffEditorTabFilesManager
 import com.intellij.openapi.Disposable
 import com.intellij.openapi.actionSystem.DataKey
-import com.intellij.openapi.components.Service
 import com.intellij.openapi.components.service
+import com.intellij.openapi.fileEditor.FileEditor
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.util.registry.Registry
 import com.intellij.openapi.util.registry.RegistryValue
@@ -12,8 +14,7 @@ import com.intellij.openapi.util.registry.RegistryValueListener
 import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager
 import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManagerListener
 
-@Service(Service.Level.PROJECT)
-class EditorTabDiffPreviewManager(private val project: Project) {
+class EditorTabDiffPreviewManager(private val project: Project) : DiffEditorTabFilesManager {
 
   fun isEditorDiffPreviewAvailable() =
     ChangesViewContentManager.isCommitToolWindowShown(project) || Registry.`is`("show.diff.preview.as.editor.tab")
@@ -33,6 +34,10 @@ class EditorTabDiffPreviewManager(private val project: Project) {
                  })
   }
 
+  override fun showDiffFile(diffFile: ChainDiffVirtualFile, focusEditor: Boolean): Array<out FileEditor> {
+    return VcsEditorTabFilesManager.getInstance().openFile(project, diffFile, focusEditor)
+  }
+
   fun showDiffPreview(diffPreview: DiffPreview) {
     diffPreview.setPreviewVisible(true, true)
   }
@@ -44,6 +49,7 @@ class EditorTabDiffPreviewManager(private val project: Project) {
     val EDITOR_TAB_DIFF_PREVIEW = DataKey.create<DiffPreview>("EditorTabDiffPreview")
 
     @JvmStatic
-    fun getInstance(project: Project): EditorTabDiffPreviewManager = project.service()
+    fun getInstance(project: Project): EditorTabDiffPreviewManager =
+      project.service<DiffEditorTabFilesManager>() as EditorTabDiffPreviewManager
   }
 }
index b6919a81c80fbb2b1b174e061d84c870a13996c7..08d9384348fdf31ac44c8586423a2a9fea988157 100644 (file)
@@ -3,7 +3,6 @@ package com.intellij.openapi.vcs.changes
 
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.AnActionExtensionProvider
-import com.intellij.openapi.components.service
 import com.intellij.openapi.vcs.changes.EditorTabDiffPreviewManager.Companion.EDITOR_TAB_DIFF_PREVIEW
 
 open class ShowEditorDiffPreviewActionProvider : AnActionExtensionProvider {
@@ -12,7 +11,7 @@ open class ShowEditorDiffPreviewActionProvider : AnActionExtensionProvider {
 
     return project != null &&
            getDiffPreview(e) != null &&
-           project.service<EditorTabDiffPreviewManager>().isEditorDiffPreviewAvailable()
+           EditorTabDiffPreviewManager.getInstance(project).isEditorDiffPreviewAvailable()
   }
 
   override fun update(e: AnActionEvent) {}
@@ -20,7 +19,7 @@ open class ShowEditorDiffPreviewActionProvider : AnActionExtensionProvider {
   override fun actionPerformed(e: AnActionEvent) {
     val diffPreview = getDiffPreview(e)!!
 
-    val previewManager = e.project!!.service<EditorTabDiffPreviewManager>()
+    val previewManager = EditorTabDiffPreviewManager.getInstance(e.project!!)
     previewManager.showDiffPreview(diffPreview)
   }