diff --git a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/changes/CodeReviewChangeListComponentFactory.kt b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/changes/CodeReviewChangeListComponentFactory.kt index d80790f1a873..0367678282c4 100644 --- a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/changes/CodeReviewChangeListComponentFactory.kt +++ b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/changes/CodeReviewChangeListComponentFactory.kt @@ -17,7 +17,6 @@ import com.intellij.openapi.vcs.FilePath import com.intellij.openapi.vcs.changes.ChangesUtil import com.intellij.openapi.vcs.changes.ui.* import com.intellij.openapi.vcs.changes.ui.VcsTreeModelData.selected -import com.intellij.openapi.vcs.changes.ui.VcsTreeModelData.uiDataSnapshot import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.ClientProperty import com.intellij.ui.ExpandableItemsHandler @@ -102,7 +101,7 @@ object CodeReviewChangeListComponentFactory { override fun uiDataSnapshot(sink: DataSink) { super.uiDataSnapshot(sink) - uiDataSnapshot(sink, project, this) + VcsTreeModelData.uiDataSnapshot(sink, project, this) sink[CommonDataKeys.NAVIGATABLE] = getSelectedFiles().singleOrNull()?.let { OpenFileDescriptor(project, it) } sink[CommonDataKeys.NAVIGATABLE_ARRAY] = ChangesUtil.getNavigatableArray(project, getSelectedFiles()) sink[SELECTED_CHANGES] = getSelectedChanges() diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SpecificFilesViewDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SpecificFilesViewDialog.java index b1310940a1fe..58e73931c8b9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SpecificFilesViewDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SpecificFilesViewDialog.java @@ -178,15 +178,14 @@ abstract class SpecificFilesViewDialog extends DialogWrapper { @Override public void uiDataSnapshot(@NotNull DataSink sink) { super.uiDataSnapshot(sink); + VcsTreeModelData.uiDataSnapshot(sink, myProject, this); + VcsTreeModelData treeSelection = VcsTreeModelData.selected(this); VcsTreeModelData exactSelection = VcsTreeModelData.exactlySelected(this); - VcsTreeModelData.uiDataSnapshot(sink, myProject, this); sink.lazy(ChangesListView.EXACTLY_SELECTED_FILES_DATA_KEY, () -> VcsTreeModelData.mapToExactVirtualFile(exactSelection)); - sink.set(myShownDataKey, - treeSelection.iterateUserObjects(FilePath.class)); - sink.set(VcsDataKeys.FILE_PATHS, - treeSelection.iterateUserObjects(FilePath.class)); + sink.set(myShownDataKey, treeSelection.iterateUserObjects(FilePath.class)); + sink.set(VcsDataKeys.FILE_PATHS, treeSelection.iterateUserObjects(FilePath.class)); sink.set(PlatformDataKeys.DELETE_ELEMENT_PROVIDER, new VirtualFileDeleteProvider()); sink.set(PlatformCoreDataKeys.HELP_ID, ChangesListView.HELP_ID); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/savedPatches/SavedPatchesChangesBrowser.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/savedPatches/SavedPatchesChangesBrowser.kt index 4aa2e12d3f3b..9fd2d36772e3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/savedPatches/SavedPatchesChangesBrowser.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/savedPatches/SavedPatchesChangesBrowser.kt @@ -141,8 +141,7 @@ class SavedPatchesChangesBrowser(project: Project, internal val isShowDiffWithLo val changeObjects = selection.iterateUserObjects(SavedPatchesProvider.ChangeObject::class.java) sink[CommonDataKeys.VIRTUAL_FILE_ARRAY] = changeObjects - .map { it.filePath.virtualFile } - .filterNotNull() + .filterMap { it.filePath.virtualFile } .toList().toTypedArray() sink[VcsDataKeys.FILE_PATHS] = changeObjects.map { it.filePath } sink[CommonDataKeys.NAVIGATABLE_ARRAY] = changeObjects 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 b9ed4b370175..ad4f9fa8cc63 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 @@ -507,18 +507,15 @@ public class ShelvedChangesViewManager implements Disposable { public void uiDataSnapshot(@NotNull DataSink sink) { super.uiDataSnapshot(sink); sink.set(SHELVED_CHANGES_TREE, this); - sink.set(SHELVED_CHANGELIST_KEY, new ArrayList<>( - getSelectedLists(this, l -> !l.isRecycled() && !l.isDeleted()))); - sink.set(SHELVED_RECYCLED_CHANGELIST_KEY, new ArrayList<>( - getSelectedLists(this, l -> l.isRecycled() && !l.isDeleted()))); - sink.set(SHELVED_DELETED_CHANGELIST_KEY, new ArrayList<>( - getSelectedLists(this, l -> l.isDeleted()))); + sink.set(SHELVED_CHANGELIST_KEY, new ArrayList<>(getSelectedLists(this, l -> !l.isRecycled() && !l.isDeleted()))); + sink.set(SHELVED_RECYCLED_CHANGELIST_KEY, new ArrayList<>(getSelectedLists(this, l -> l.isRecycled() && !l.isDeleted()))); + sink.set(SHELVED_DELETED_CHANGELIST_KEY, new ArrayList<>(getSelectedLists(this, l -> l.isDeleted()))); sink.set(SHELVED_CHANGE_KEY, VcsTreeModelData.selected(this).iterateUserObjects(ShelvedWrapper.class) - .map(s -> s.getShelvedChange()) - .filterNotNull().toList()); + .filterMap(s -> s.getShelvedChange()) + .toList()); sink.set(SHELVED_BINARY_FILE_KEY, VcsTreeModelData.selected(this).iterateUserObjects(ShelvedWrapper.class) - .map(s -> s.getBinaryFile()) - .filterNotNull().toList()); + .filterMap(s -> s.getBinaryFile()) + .toList()); if (!isEditing()) { sink.set(PlatformDataKeys.DELETE_ELEMENT_PROVIDER, myDeleteProvider); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/VcsTreeModelData.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/VcsTreeModelData.java index cd668d29fc19..1cd9c41cc40c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/VcsTreeModelData.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/VcsTreeModelData.java @@ -6,7 +6,6 @@ import com.intellij.ide.SelectInContext; import com.intellij.openapi.ListSelection; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataSink; -import com.intellij.openapi.actionSystem.PlatformCoreDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsDataKeys; @@ -315,34 +314,26 @@ public abstract class VcsTreeModelData { sink.set(VcsDataKeys.CHANGE_LEAD_SELECTION, mapToChange(exactlySelected(tree)).toArray(Change.EMPTY_CHANGE_ARRAY)); sink.set(VcsDataKeys.FILE_PATHS, mapToFilePath(selected(tree))); + VcsTreeModelData treeSelection = selected(tree); VcsTreeModelData exactSelection = exactlySelected(tree); - sink.set(PlatformCoreDataKeys.BGT_DATA_PROVIDER, - slowId -> getSlowData(project, treeSelection, exactSelection, slowId)); - } - - @Nullable - private static Object getSlowData(@Nullable Project project, - @NotNull VcsTreeModelData treeSelection, - @NotNull VcsTreeModelData exactSelection, - @NotNull String slowId) { - if (SelectInContext.DATA_KEY.is(slowId)) { + sink.lazy(SelectInContext.DATA_KEY, () -> { if (project == null) return null; VirtualFile file = mapObjectToVirtualFile(exactSelection.iterateRawUserObjects()).first(); if (file == null) return null; return new FileSelectInContext(project, file, null); - } - else if (VcsDataKeys.VIRTUAL_FILES.is(slowId)) { + }); + sink.lazy(VcsDataKeys.VIRTUAL_FILES, () -> { return mapToVirtualFile(treeSelection); - } - else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(slowId)) { + }); + sink.lazy(CommonDataKeys.VIRTUAL_FILE_ARRAY, () -> { return mapToVirtualFile(treeSelection).toArray(VirtualFile.EMPTY_ARRAY); + }); + if (project != null) { + sink.lazy(CommonDataKeys.NAVIGATABLE_ARRAY, () -> { + return ChangesUtil.getNavigatableArray(project, mapToNavigatableFile(treeSelection)); + }); } - else if (CommonDataKeys.NAVIGATABLE_ARRAY.is(slowId)) { - if (project == null) return null; - return ChangesUtil.getNavigatableArray(project, mapToNavigatableFile(treeSelection)); - } - return null; } @NotNull diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogChangesBrowser.kt b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogChangesBrowser.kt index 8378c963ad76..086b0d2f7ff5 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogChangesBrowser.kt +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogChangesBrowser.kt @@ -10,7 +10,10 @@ import com.intellij.diff.util.DiffPlaces import com.intellij.diff.util.DiffUserDataKeysEx import com.intellij.ide.ui.customization.CustomActionsSchema.Companion.getInstance import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.* +import com.intellij.openapi.actionSystem.ActionManager +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.DataKey +import com.intellij.openapi.actionSystem.DataSink import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer @@ -276,20 +279,28 @@ class VcsLogChangesBrowser internal constructor(project: Project, val roots = HashSet(commitModel.roots) val selectedData = VcsTreeModelData.selected(myViewer) sink.lazy(VcsDataKeys.VCS) { - val rootsVcs = JBIterable.from(roots) - .map { root -> ProjectLevelVcsManager.getInstance(myProject).getVcsFor(root) } - .filterNotNull() - .unique() - .single() - rootsVcs?.keyInstanceMethod ?: selectedData.iterateUserObjects(Change::class.java) - .map { change -> ChangesUtil.getFilePath(change) } - .map { root -> ProjectLevelVcsManager.getInstance(myProject).getVcsFor(root) } - .filterNotNull() - .unique() - .single()?.keyInstanceMethod + getSelectedVcs(roots, selectedData)?.keyInstanceMethod } } + private fun getSelectedVcs( + roots: Set, + selectedData: VcsTreeModelData, + ): AbstractVcs? { + val rootsVcs = JBIterable.from(roots) + .filterMap { root -> ProjectLevelVcsManager.getInstance(myProject).getVcsFor(root) } + .unique() + .single() + if (rootsVcs != null) return rootsVcs + + val selectionVcs = selectedData.iterateUserObjects(Change::class.java) + .map { change -> ChangesUtil.getFilePath(change) } + .filterMap { root -> ProjectLevelVcsManager.getInstance(myProject).getVcsFor(root) } + .unique() + .single() + return selectionVcs + } + public override fun getDiffRequestProducer(userObject: Any): ChangeDiffRequestChain.Producer? { return getDiffRequestProducer(userObject, false) }