diff --git a/plugins/tasks/tasks-core/src/META-INF/plugin.xml b/plugins/tasks/tasks-core/src/META-INF/plugin.xml index 84353ade5efb..b6d217e110ce 100644 --- a/plugins/tasks/tasks-core/src/META-INF/plugin.xml +++ b/plugins/tasks/tasks-core/src/META-INF/plugin.xml @@ -95,6 +95,8 @@ + + diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/doc/TaskDocumentationProvider.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/doc/TaskDocumentationProvider.java new file mode 100644 index 000000000000..2a7fe87435e8 --- /dev/null +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/doc/TaskDocumentationProvider.java @@ -0,0 +1,87 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.tasks.doc; + +import com.intellij.lang.documentation.AbstractDocumentationProvider; +import com.intellij.lang.documentation.ExternalDocumentationProvider; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiManager; +import com.intellij.tasks.Task; + +import java.util.Collections; +import java.util.List; + +/** + * @author Dennis.Ushakov + */ +public class TaskDocumentationProvider extends AbstractDocumentationProvider implements ExternalDocumentationProvider { + + @Override + public List getUrlFor(PsiElement element, PsiElement originalElement) { + if (element instanceof TaskPsiElement) { + final String url = ((TaskPsiElement)element).getTask().getIssueUrl(); + if (url != null) { + return Collections.singletonList(url); + } + } + return Collections.emptyList(); + } + + @Override + public String generateDoc(PsiElement element, PsiElement originalElement) { + if (!(element instanceof TaskPsiElement)) return null; + final Task task = ((TaskPsiElement)element).getTask(); + final StringBuilder builder = new StringBuilder(""); + builder.append("Summary: ").append(task.getSummary()).append("
"); + builder.append("Id: ").append(task.getId()).append("
"); + if (task.getCreated() != null) { + builder.append("Created at: ").append(task.getCreated()).append("
"); + } + if (task.getUpdated() != null) { + builder.append("Updated at: ").append(task.getUpdated()).append("
"); + } + if (task.getDescription() != null) { + builder.append("Description:
").append(task.getDescription()); + } + builder.append(""); + return builder.toString(); + } + + @Override + public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object, PsiElement element) { + return object instanceof Task ? new TaskPsiElement(psiManager, (Task)object): null; + } + + + @Override + public String fetchExternalDocumentation(Project project, PsiElement element, List docUrls) { + return null; + } + + @Override + public boolean hasDocumentationFor(PsiElement element, PsiElement originalElement) { + return element instanceof TaskPsiElement; + } + + @Override + public boolean canPromptToConfigureDocumentation(PsiElement element) { + return false; + } + + @Override + public void promptToConfigureDocumentation(PsiElement element) {} +} diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/doc/TaskPsiElement.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/doc/TaskPsiElement.java new file mode 100644 index 000000000000..b8308107f605 --- /dev/null +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/doc/TaskPsiElement.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.tasks.doc; + +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiFileFactory; +import com.intellij.psi.PsiManager; +import com.intellij.psi.impl.FakePsiElement; +import com.intellij.tasks.Task; + +/** + * @author Dennis.Ushakov + */ +public class TaskPsiElement extends FakePsiElement { + private final PsiManager myPsiManager; + private final Task myTask; + + public TaskPsiElement(PsiManager psiManager, final Task task) { + myPsiManager = psiManager; + myTask = task; + } + + @Override + public PsiElement getParent() { + return null; + } + + public Task getTask() { + return myTask; + } + + @Override + public boolean isValid() { + return true; + } + + @Override + public PsiManager getManager() { + return myPsiManager; + } + + @Override + public PsiFile getContainingFile() { + return PsiFileFactory.getInstance(getProject()).createFileFromText("foo.txt", ""); + } +} diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskCompletionContributor.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskCompletionContributor.java index 5e0ef2d91178..9307b5633c7d 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskCompletionContributor.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskCompletionContributor.java @@ -89,7 +89,7 @@ public class TaskCompletionContributor extends CompletionContributor { : AutoCompletionPolicy.NEVER_AUTOCOMPLETE; for (final Task task : items) { - LookupElementBuilder builder = LookupElementBuilder.create(task.getId()) + LookupElementBuilder builder = LookupElementBuilder.create(task, task.getId()) .setIcon(task.getIcon()) .addLookupString(task.getSummary()) .setTailText(" " + task.getSummary(), true)