update copyright
[fedora-idea.git] / xml / impl / src / com / intellij / vcsUtil / XmlVcsSelectionProvider.java
blob50b92791f9622adfc424b330686ebad3c9ea1a69
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.vcsUtil;
18 import com.intellij.codeInsight.TargetElementUtilBase;
19 import com.intellij.openapi.editor.Document;
20 import com.intellij.openapi.editor.Editor;
21 import com.intellij.openapi.fileEditor.FileDocumentManager;
22 import com.intellij.openapi.util.TextRange;
23 import com.intellij.openapi.vcs.VcsBundle;
24 import com.intellij.openapi.vcs.actions.VcsContext;
25 import com.intellij.openapi.vfs.VirtualFile;
26 import com.intellij.psi.PsiElement;
27 import com.intellij.psi.xml.XmlTag;
28 import com.intellij.psi.xml.XmlText;
30 /**
31 * @author yole
33 public class XmlVcsSelectionProvider implements VcsSelectionProvider {
34 public VcsSelection getSelection(VcsContext context) {
35 final Editor editor = context.getEditor();
36 if (editor == null) return null;
37 PsiElement psiElement = TargetElementUtilBase.findTargetElement(editor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
38 if (psiElement == null || !psiElement.isValid()) {
39 return null;
42 final String actionName;
44 if (psiElement instanceof XmlTag) {
45 actionName = VcsBundle.message("action.name.show.history.for.tag");
47 else if (psiElement instanceof XmlText) {
48 actionName = VcsBundle.message("action.name.show.history.for.text");
50 else {
51 return null;
54 TextRange textRange = psiElement.getTextRange();
55 if (textRange == null) {
56 return null;
59 VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile();
60 if (virtualFile == null) {
61 return null;
63 if (!virtualFile.isValid()) {
64 return null;
67 Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
68 return new VcsSelection(document, textRange, actionName);