From b2bc5e12237d5e4bcd4d2f2bef6e577f989cb23c Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 9 Sep 2024 14:34:48 +0200 Subject: [PATCH] diff: remove dependency on VcsEditorTabFilesManager GitOrigin-RevId: 147d7554e49006d11866943ddaaa9f65350a0f27 --- .../resources/META-INF/diff-impl.xml | 2 ++ .../editor/DiffEditorTabFilesManagerImpl.kt | 27 +++++++++++++++++++ platform/vcs-impl/api-dump.txt | 9 ------- .../resources/intellij.platform.vcs.impl.xml | 4 --- .../vcs/changes/DiffEditorTabFilesListener.kt | 24 ----------------- .../ShowDiffInEditorTooltipInstaller.kt | 17 +++++++----- .../vcs/changes/VcsEditorTabFilesManager.kt | 26 ------------------ 7 files changed, 39 insertions(+), 70 deletions(-) delete mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/DiffEditorTabFilesListener.kt diff --git a/platform/diff-impl/resources/META-INF/diff-impl.xml b/platform/diff-impl/resources/META-INF/diff-impl.xml index bd5089cc818f..9e65bbd6ddaa 100644 --- a/platform/diff-impl/resources/META-INF/diff-impl.xml +++ b/platform/diff-impl/resources/META-INF/diff-impl.xml @@ -9,5 +9,7 @@ + \ No newline at end of file diff --git a/platform/diff-impl/src/com/intellij/diff/editor/DiffEditorTabFilesManagerImpl.kt b/platform/diff-impl/src/com/intellij/diff/editor/DiffEditorTabFilesManagerImpl.kt index 3adbd94a446b..ef3b8ec7362d 100644 --- a/platform/diff-impl/src/com/intellij/diff/editor/DiffEditorTabFilesManagerImpl.kt +++ b/platform/diff-impl/src/com/intellij/diff/editor/DiffEditorTabFilesManagerImpl.kt @@ -5,8 +5,12 @@ import com.intellij.codeWithMe.ClientId import com.intellij.diff.editor.DiffEditorTabFilesManager.Companion.isDiffInEditor import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.application.ModalityState +import com.intellij.openapi.application.invokeLater import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.fileEditor.FileOpenedSyncListener +import com.intellij.openapi.fileEditor.ex.FileEditorWithProvider import com.intellij.openapi.fileEditor.impl.EditorWindow import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl import com.intellij.openapi.fileEditor.impl.FileEditorOpenOptions @@ -114,6 +118,29 @@ internal class EditorTabDiffPreviewAdvancedSettingsListener : AdvancedSettingsCh } } +/** + * Toggle option on drag-n-drop + */ +internal class DiffInWindowDndListener : FileOpenedSyncListener { + override fun fileOpenedSync(editorManager: FileEditorManager, file: VirtualFile, editorsWithProviders: List) { + if (file !is DiffContentVirtualFile) return + if (editorManager !is FileEditorManagerImpl) return + + // flag is not properly set for async editor opening + //if (file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN) != true) return + + val openedFileEditors = editorsWithProviders.map { it.fileEditor } + val window = editorManager.windows.find { it.allComposites.any { it.allEditors.any { openedFileEditors.contains(it) } } } ?: return + + val isFileInEditor = !isSingletonEditorInWindow(window) + if (DiffEditorTabFilesManager.isDiffInEditor != isFileInEditor) { + invokeLater(ModalityState.nonModal()) { + DiffEditorTabFilesManager.isDiffInEditor = isFileInEditor + } + } + } +} + internal fun isSingletonEditorInWindow(window: EditorWindow): Boolean { return window.owner.isFloating && window.tabCount == 1 } diff --git a/platform/vcs-impl/api-dump.txt b/platform/vcs-impl/api-dump.txt index 8c18437de9b6..159e7f3bad4f 100644 --- a/platform/vcs-impl/api-dump.txt +++ b/platform/vcs-impl/api-dump.txt @@ -1419,11 +1419,6 @@ c:com.intellij.openapi.vcs.changes.DefaultChangeListOwner - addUnversionedFiles(com.intellij.openapi.vcs.changes.LocalChangeList,java.util.List):V - getProject():com.intellij.openapi.project.Project - moveChangesTo(com.intellij.openapi.vcs.changes.LocalChangeList,java.util.List):V -a:com.intellij.openapi.vcs.changes.DefaultDiffEditorTabFilesListener -- com.intellij.openapi.vcs.changes.VcsEditorTabFilesListener -- ():V -- a:shouldOpenInNewWindowChanged(com.intellij.diff.editor.DiffContentVirtualFile,Z):V -- f:shouldOpenInNewWindowChanged(com.intellij.openapi.vfs.VirtualFile,Z):V c:com.intellij.openapi.vcs.changes.DeletedFilesHolder - com.intellij.openapi.vcs.changes.FileHolder - ():V @@ -1436,10 +1431,6 @@ c:com.intellij.openapi.vcs.changes.DeletedFilesHolder - hashCode():I - isContainedInLocallyDeleted(com.intellij.openapi.vcs.FilePath):Z - takeFrom(com.intellij.openapi.vcs.changes.DeletedFilesHolder):V -f:com.intellij.openapi.vcs.changes.DiffEditorTabStateListener -- com.intellij.openapi.vcs.changes.DefaultDiffEditorTabFilesListener -- ():V -- shouldOpenInNewWindowChanged(com.intellij.diff.editor.DiffContentVirtualFile,Z):V com.intellij.openapi.vcs.changes.DiffPreview - sf:Companion:com.intellij.openapi.vcs.changes.DiffPreview$Companion - a:closePreview():V diff --git a/platform/vcs-impl/resources/intellij.platform.vcs.impl.xml b/platform/vcs-impl/resources/intellij.platform.vcs.impl.xml index 0755dd9db13a..036cff6eda4a 100644 --- a/platform/vcs-impl/resources/intellij.platform.vcs.impl.xml +++ b/platform/vcs-impl/resources/intellij.platform.vcs.impl.xml @@ -58,8 +58,4 @@ - - - diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/DiffEditorTabFilesListener.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/DiffEditorTabFilesListener.kt deleted file mode 100644 index 33281d56a0d9..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/DiffEditorTabFilesListener.kt +++ /dev/null @@ -1,24 +0,0 @@ -// 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.openapi.vcs.changes - -import com.intellij.diff.editor.DiffContentVirtualFile -import com.intellij.diff.editor.DiffEditorTabFilesManager -import com.intellij.openapi.vfs.VirtualFile - -abstract class DefaultDiffEditorTabFilesListener : VcsEditorTabFilesListener { - final override fun shouldOpenInNewWindowChanged(file: VirtualFile, shouldOpenInNewWindow: Boolean) { - if (file is DiffContentVirtualFile) { - shouldOpenInNewWindowChanged(file as DiffContentVirtualFile, shouldOpenInNewWindow) - } - } - - abstract fun shouldOpenInNewWindowChanged(diffFile: DiffContentVirtualFile, shouldOpenInNewWindow: Boolean) -} - - -class DiffEditorTabStateListener : DefaultDiffEditorTabFilesListener() { - - override fun shouldOpenInNewWindowChanged(diffFile: DiffContentVirtualFile, shouldOpenInNewWindow: Boolean) { - DiffEditorTabFilesManager.isDiffInEditor = !shouldOpenInNewWindow - } -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ShowDiffInEditorTooltipInstaller.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ShowDiffInEditorTooltipInstaller.kt index a614bd3b2dc7..5d457ceee4ef 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ShowDiffInEditorTooltipInstaller.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ShowDiffInEditorTooltipInstaller.kt @@ -4,7 +4,7 @@ package com.intellij.openapi.vcs.changes import com.intellij.diff.DiffContext import com.intellij.diff.actions.impl.SetEditorSettingsAction import com.intellij.diff.actions.impl.SetEditorSettingsActionGroup -import com.intellij.diff.editor.DiffContentVirtualFile +import com.intellij.diff.editor.DiffEditorTabFilesManager import com.intellij.diff.editor.DiffRequestProcessorEditorCustomizer import com.intellij.diff.util.DiffUserDataKeysEx import com.intellij.openapi.Disposable @@ -12,6 +12,7 @@ import com.intellij.openapi.actionSystem.ActionToolbar import com.intellij.openapi.actionSystem.impl.ActionButtonUtil import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.fileEditor.FileEditor +import com.intellij.openapi.options.advanced.AdvancedSettingsChangeListener import com.intellij.openapi.util.Disposer import com.intellij.openapi.vcs.VcsBundle import com.intellij.openapi.vcs.changes.ui.ActionToolbarGotItTooltip @@ -27,9 +28,11 @@ internal class ShowDiffInEditorTooltipInstaller : DiffRequestProcessorEditorCust } } -private class ShowDiffInEditorTabTooltipHolder(disposable: Disposable, - private val toolbarToShowTooltip: ActionToolbar) : - DefaultDiffEditorTabFilesListener(), Disposable { +private class ShowDiffInEditorTabTooltipHolder( + disposable: Disposable, + private val toolbarToShowTooltip: ActionToolbar, +) + : AdvancedSettingsChangeListener, Disposable { companion object { const val TOOLTIP_ID = "show.diff.in.editor" @@ -42,11 +45,11 @@ private class ShowDiffInEditorTabTooltipHolder(disposable: Disposable, init { Disposer.register(disposable, this) - ApplicationManager.getApplication().messageBus.connect(this).subscribe(VcsEditorTabFilesListener.TOPIC, this) + ApplicationManager.getApplication().messageBus.connect(this).subscribe(AdvancedSettingsChangeListener.TOPIC, this) } - override fun shouldOpenInNewWindowChanged(diffFile: DiffContentVirtualFile, shouldOpenInNewWindow: Boolean) { - if (shouldOpenInNewWindow) { + override fun advancedSettingChanged(id: String, oldValue: Any, newValue: Any) { + if (id == DiffEditorTabFilesManager.SHOW_DIFF_IN_EDITOR_SETTING && !DiffEditorTabFilesManager.isDiffInEditor) { showGotItTooltip() } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsEditorTabFilesManager.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsEditorTabFilesManager.kt index e549473d127d..374d0b9029a9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsEditorTabFilesManager.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsEditorTabFilesManager.kt @@ -2,15 +2,10 @@ package com.intellij.openapi.vcs.changes import com.intellij.codeWithMe.ClientId -import com.intellij.diff.editor.DiffContentVirtualFile import com.intellij.openapi.Disposable -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.* import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.fileEditor.FileEditorManager -import com.intellij.openapi.fileEditor.FileEditorManagerListener -import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx -import com.intellij.openapi.fileEditor.impl.EditorWindow import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl import com.intellij.openapi.fileEditor.impl.FileEditorOpenOptions import com.intellij.openapi.project.Project @@ -28,22 +23,6 @@ class VcsEditorTabFilesManager : var openInNewWindow by property(false) } - init { - val messageBus = ApplicationManager.getApplication().messageBus - messageBus.connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, object : FileEditorManagerListener { - override fun fileOpened(source: FileEditorManager, file: VirtualFile) { - //currently shouldOpenInNewWindow is bound only to diff files - if (file is DiffContentVirtualFile && source is FileEditorManagerEx) { - val isOpenInNewWindow = source.findFloatingWindowForFile(file)?.let { - it.tabCount == 1 - } ?: false - shouldOpenInNewWindow = isOpenInNewWindow - messageBus.syncPublisher(VcsEditorTabFilesListener.TOPIC).shouldOpenInNewWindowChanged(file, isOpenInNewWindow) - } - } - }) - } - var shouldOpenInNewWindow: Boolean get() = state.openInNewWindow private set(value) { @@ -89,11 +68,6 @@ class VcsEditorTabFilesManager : companion object { @JvmStatic fun getInstance(): VcsEditorTabFilesManager = service() - - @JvmStatic - fun FileEditorManagerEx.findFloatingWindowForFile(file: VirtualFile): EditorWindow? { - return windows.find { it.owner.isFloating && it.isFileOpen(file) } - } } }