mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
split PsiVcsSelectionProvider into java and xml parts
This commit is contained in:
+1
-9
@@ -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");
|
||||
}
|
||||
@@ -282,6 +282,8 @@
|
||||
<todoIndexer filetype="XHTML" implementationClass="com.intellij.psi.impl.cache.impl.idCache.XHtmlTodoIndexer"/>
|
||||
|
||||
<elementSignatureProvider implementation="com.intellij.codeInsight.folding.impl.XmlElementSignatureProvider"/>
|
||||
|
||||
<vcsSelectionProvider implementation="com.intellij.vcsUtil.XmlVcsSelectionProvider"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
<orderEntry type="module" module-name="icons" />
|
||||
<orderEntry type="library" name="XmlBeans" level="project" />
|
||||
<orderEntry type="module" module-name="platform-resources" />
|
||||
<orderEntry type="module" module-name="vcs-api" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
Reference in New Issue
Block a user