diff --git a/source/com/intellij/vcsUtil/PsiVcsSelectionProvider.java b/java/java-impl/src/com/intellij/vcsUtil/JavaVcsSelectionProvider.java similarity index 84% rename from source/com/intellij/vcsUtil/PsiVcsSelectionProvider.java rename to java/java-impl/src/com/intellij/vcsUtil/JavaVcsSelectionProvider.java index 0912e0af24c3..a48759a56a47 100644 --- a/source/com/intellij/vcsUtil/PsiVcsSelectionProvider.java +++ b/java/java-impl/src/com/intellij/vcsUtil/JavaVcsSelectionProvider.java @@ -9,14 +9,12 @@ import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.actions.VcsContext; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; -import com.intellij.psi.xml.XmlTag; -import com.intellij.psi.xml.XmlText; import org.jetbrains.annotations.Nullable; /** * @author yole */ -public class PsiVcsSelectionProvider implements VcsSelectionProvider { +public class JavaVcsSelectionProvider implements VcsSelectionProvider { @Nullable public VcsSelection getSelection(final VcsContext context) { final Editor editor = context.getEditor(); @@ -43,12 +41,6 @@ public class PsiVcsSelectionProvider implements VcsSelectionProvider { else if (psiElement instanceof PsiMethod) { actionName = VcsBundle.message("action.name.show.history.for.method"); } - else if (psiElement instanceof XmlTag) { - actionName = VcsBundle.message("action.name.show.history.for.tag"); - } - else if (psiElement instanceof XmlText) { - actionName = VcsBundle.message("action.name.show.history.for.text"); - } else if (psiElement instanceof PsiCodeBlock) { actionName = VcsBundle.message("action.name.show.history.for.code.block"); } diff --git a/platform/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index d414b084dfaa..b9eae595bae6 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -282,6 +282,8 @@ + + diff --git a/xml/impl/src/com/intellij/vcsUtil/XmlVcsSelectionProvider.java b/xml/impl/src/com/intellij/vcsUtil/XmlVcsSelectionProvider.java new file mode 100644 index 000000000000..a49bfbe8a64a --- /dev/null +++ b/xml/impl/src/com/intellij/vcsUtil/XmlVcsSelectionProvider.java @@ -0,0 +1,55 @@ +package com.intellij.vcsUtil; + +import com.intellij.codeInsight.TargetElementUtilBase; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.openapi.vcs.actions.VcsContext; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; +import com.intellij.psi.xml.XmlTag; +import com.intellij.psi.xml.XmlText; + +/** + * @author yole + */ +public class XmlVcsSelectionProvider implements VcsSelectionProvider { + public VcsSelection getSelection(VcsContext context) { + final Editor editor = context.getEditor(); + if (editor == null) return null; + PsiElement psiElement = TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED); + if (psiElement == null || !psiElement.isValid()) { + return null; + } + + final String actionName; + + if (psiElement instanceof XmlTag) { + actionName = VcsBundle.message("action.name.show.history.for.tag"); + } + else if (psiElement instanceof XmlText) { + actionName = VcsBundle.message("action.name.show.history.for.text"); + } + else { + return null; + } + + TextRange textRange = psiElement.getTextRange(); + if (textRange == null) { + return null; + } + + VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile(); + if (virtualFile == null) { + return null; + } + if (!virtualFile.isValid()) { + return null; + } + + Document document = FileDocumentManager.getInstance().getDocument(virtualFile); + return new VcsSelection(document, textRange, actionName); + } +} diff --git a/xml/impl/xml.iml b/xml/impl/xml.iml index 15cd624f6a7f..352130f96034 100644 --- a/xml/impl/xml.iml +++ b/xml/impl/xml.iml @@ -16,6 +16,7 @@ +