From 5aeec4d11309aae8772f952b043e73803d6e4c53 Mon Sep 17 00:00:00 2001 From: "Dmitry.Krasilschikov" Date: Sun, 3 Nov 2019 17:54:53 +0200 Subject: [PATCH] UX-600 IDEA-223834 copy paths popups: add path from repository root provider GitOrigin-RevId: f111d1536d5b57386502875b7e874f79b62437e0 --- .../git4idea/resources/META-INF/plugin.xml | 5 +++++ .../actions/CopyRepositoryRootPathProvider.kt | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 plugins/git4idea/src/git4idea/actions/CopyRepositoryRootPathProvider.kt diff --git a/plugins/git4idea/resources/META-INF/plugin.xml b/plugins/git4idea/resources/META-INF/plugin.xml index 6e2f13fb0e1f..88e4e3f0c7e3 100644 --- a/plugins/git4idea/resources/META-INF/plugin.xml +++ b/plugins/git4idea/resources/META-INF/plugin.xml @@ -185,6 +185,11 @@ + + + + diff --git a/plugins/git4idea/src/git4idea/actions/CopyRepositoryRootPathProvider.kt b/plugins/git4idea/src/git4idea/actions/CopyRepositoryRootPathProvider.kt new file mode 100644 index 000000000000..6b1ddc8c0fc0 --- /dev/null +++ b/plugins/git4idea/src/git4idea/actions/CopyRepositoryRootPathProvider.kt @@ -0,0 +1,20 @@ +// Copyright 2000-2019 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 git4idea.actions + +import com.intellij.ide.actions.CopyPathProvider +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VfsUtilCore +import com.intellij.openapi.vfs.VirtualFile +import git4idea.repo.GitRepositoryManager + +class CopyPathFromRepositoryRootProvider : CopyPathProvider() { + override fun getPathToElement(project: Project, virtualFile: VirtualFile?, editor: Editor?): String? { + if (virtualFile == null) return null + + val repository = GitRepositoryManager.getInstance(project).getRepositoryForFile(virtualFile) + if (repository == null) return null + + return VfsUtilCore.getRelativePath(virtualFile, repository.root) + } +} \ No newline at end of file